Skip to content

Commit

Permalink
doc: added concept doc for logging (#146)
Browse files Browse the repository at this point in the history
  • Loading branch information
BenDLH authored Mar 28, 2024
1 parent 7e56385 commit 19c259a
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
41 changes: 41 additions & 0 deletions docs/concepts/logging.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
In order to see the requests made to OpenAI and the responses, you can set debug to true when initializing Instructor. This will show the requests and responses made to OpenAI. This can be useful for debugging and understanding the requests and responses made to OpenAI.

```typescript
const oai = new OpenAI({
apiKey: process.env.OPENAI_API_KEY ?? undefined,
organization: process.env.OPENAI_ORG_ID ?? undefined
})

const client = Instructor({
client: oai,
mode: "TOOLS",
debug: true // <== HERE
})

const UserSchema = z.object({
// Description will be used in the prompt
age: z.number().describe("The age of the user"),
name: z.string()
})

// User will be of type z.infer<typeof UserSchema>
const user = await client.chat.completions.create({
messages: [{ role: "user", content: "Jason Liu is 30 years old" }],
model: "gpt-3.5-turbo",
response_model: {
schema: UserSchema,
name: "User"
}
})
// [Instructor:DEBUG] 2024-03-28T13:42:00.178Z: User making completion call with params: {
// messages: [ { role: 'user', content: 'Jason Liu is 30 years old' } ],
// model: 'gpt-3.5-turbo',
// stream: false,
// tool_choice: { type: 'function', function: { name: 'User' } },
// tools: [ { type: 'function', function: [Object] } ]
// }
// [Instructor:DEBUG] 2024-03-28T13:42:00.846Z: User Completion validation: { success: true, data: { age: 30, name: 'Jason Liu' } }

console.log(user)
// { age: 30, name: "Jason Liu" }
```
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ nav:
- Schema: 'concepts/schema.md'
- Patching: 'concepts/patching.md'
- Streaming: 'concepts/streaming.md'
- Logging: 'concepts/logging.md'
- Prompting Tips: 'tips/prompting.md'
- Philosophy: 'concepts/philosophy.md'
- Help with Instructor: 'help.md'
Expand Down

0 comments on commit 19c259a

Please sign in to comment.