Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/examples/self_critique.md
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion examples/validators/competitors.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Response(BaseModel):
resp = client.chat.completions.create(
model="gpt-3.5-turbo",
response_model=Response,
max_retries=1,
max_retries=2,
messages=[
{
"role": "user",
Expand Down
6 changes: 3 additions & 3 deletions examples/validators/llm_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class QuestionAnswerNoEvil(BaseModel):
qa: QuestionAnswerNoEvil = client.chat.completions.create(
model="gpt-3.5-turbo",
response_model=QuestionAnswerNoEvil,
max_retries=1,
max_retries=2,
messages=[
{
"role": "system",
Expand All @@ -107,10 +107,10 @@ class QuestionAnswerNoEvil(BaseModel):
],
) # 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."
Expand Down
8 changes: 4 additions & 4 deletions examples/validators/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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
{
Expand All @@ -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.
Loading