mirror of
https://github.com/kennethreitz/instructor.git
synced 2026-06-05 22:50:18 +00:00
fix(validation): increase max_retries from 1 to 2 (#433)
This commit is contained in:
@@ -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",
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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."
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user