fix(validation): increase max_retries from 1 to 2 (#433)

This commit is contained in:
Jason Liu
2024-02-12 09:51:42 -05:00
committed by GitHub
parent 56e69d4378
commit 2a215cd6d8
4 changed files with 9 additions and 9 deletions
+1 -1
View File
@@ -104,7 +104,7 @@ By adding the `max_retries` parameter, we can retry the request with corrections
qa: QuestionAnswerNoEvil = client.chat.completions.create(
model="gpt-3.5-turbo",
response_model=QuestionAnswerNoEvil,
max_retries=1,
max_retries=2,
messages=[
{
"role": "system",
+1 -1
View File
@@ -27,7 +27,7 @@ try:
resp = client.chat.completions.create(
model="gpt-3.5-turbo",
response_model=Response,
max_retries=1,
max_retries=2,
messages=[
{
"role": "user",
+3 -3
View File
@@ -94,7 +94,7 @@ except Exception as e:
qa: QuestionAnswerNoEvil = client.chat.completions.create(
model="gpt-3.5-turbo",
response_model=QuestionAnswerNoEvil,
max_retries=1,
max_retries=2,
messages=[
{
"role": "system",
@@ -107,10 +107,10 @@ qa: QuestionAnswerNoEvil = client.chat.completions.create(
],
) # type: ignore
print("After validation with `llm_validator` with `max_retries=1`")
print("After validation with `llm_validator` with `max_retries=2`")
print(qa.model_dump_json(indent=2), end="\n\n")
"""
After validation with `llm_validator` with `max_retries=1`
After validation with `llm_validator` with `max_retries=2`
{
"question": "What is the meaning of life?",
"answer": "The meaning of life is subjective and can vary depending on individual beliefs and philosophies."
+4 -4
View File
@@ -116,13 +116,13 @@ except Exception as e:
### Retrying Validation
Allow for retries by setting `max_retries=1`.
Allow for retries by setting `max_retries=2`.
```python
qa: QuestionAnswerNoEvil = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
response_model=QuestionAnswerNoEvil,
max_retries=1,
max_retries=2,
messages=[
{
"role": "system",
@@ -138,7 +138,7 @@ qa: QuestionAnswerNoEvil = openai.ChatCompletion.create(
#### Output
After validation with `llm_validator` and `max_retries=1`:
After validation with `llm_validator` and `max_retries=2`:
```json
{
@@ -149,4 +149,4 @@ After validation with `llm_validator` and `max_retries=1`:
## Summary
This document described how to use `llm_validator` with OpenAI's GPT-3.5 Turbo and Pydantic, including example outputs. This approach allows for controlled and filtered responses.
This document described how to use `llm_validator` with OpenAI's GPT-3.5 Turbo and Pydantic, including example outputs. This approach allows for controlled and filtered responses.