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

add example code block #106

Merged
merged 2 commits into from
Feb 8, 2024
Merged
Changes from 1 commit
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
23 changes: 21 additions & 2 deletions docs/examples/self_correction.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,29 @@ Now, we throw validation error that its objectionable and provide a helpful erro

## Retrying with Corrections

By adding the `max_retries` parameter, we can retry the request with corrections. and use the error message to correct the output.
By adding the `max_retries` parameter, we can retry the request with corrections and use the error message to correct the output.

```ts
mlluciano marked this conversation as resolved.
Show resolved Hide resolved

try {
await instructor.chat.completions.create({
model: "gpt-4",
max_retries: 2,
response_model: { schema: QuestionAnswer, name: "Question and Answer" },
messages: [
{
role: "system",
content:
"You are a system that answers questions based on the context. answer exactly what the question asks using the context."
},
{
role: "user",
content: `using the context: ${context}\n\nAnswer the following question: ${question}`
}
]
})
} catch (e as ZodError[]) {
console.error(e[0].message)
}
```

### Final Output
Expand Down
Loading