Skip to content

Commit

Permalink
fix(validation): increase max_retries from 1 to 2 (#433)
Browse files Browse the repository at this point in the history
  • Loading branch information
jxnl authored Feb 12, 2024
1 parent 56e69d4 commit 2a215cd
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
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.

0 comments on commit 2a215cd

Please sign in to comment.