Skip to content

Commit

Permalink
control char fix (#156)
Browse files Browse the repository at this point in the history
  • Loading branch information
roodboi authored Apr 9, 2024
1 parent 8bd9648 commit 54543be
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 26 deletions.
Binary file modified bun.lockb
Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
},
"homepage": "https://github.com/instructor-ai/instructor-js#readme",
"dependencies": {
"zod-stream": "1.0.1",
"zod-stream": "1.0.2",
"zod-validation-error": "^2.1.0"
},
"peerDependencies": {
Expand Down
1 change: 1 addition & 0 deletions src/instructor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ class Instructor<C extends GenericClient | OpenAI> {
...completionParams,
stream: true
})

this.log("debug", "raw stream completion response: ", completion)

return OAIStream({
Expand Down
12 changes: 9 additions & 3 deletions tests/anthropic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import z from "zod"

const anthropicClient = createLLMClient({
provider: "anthropic",
apiKey: process.env.ANTHROPIC_API_KEY
apiKey: process.env.ANTHROPIC_API_KEY,
logLevel: "debug"
})

describe("LLMClient Anthropic Provider - mode: TOOLS", () => {
Expand Down Expand Up @@ -173,6 +174,8 @@ describe("LLMClient Anthropic Provider - mode: MD_JSON", () => {
Programming
Leadership
Communication
`
}
],
Expand All @@ -194,7 +197,10 @@ describe("LLMClient Anthropic Provider - mode: MD_JSON", () => {
years: z.number().optional()
})
),
skills: z.array(z.string())
skills: z.array(z.string()),
summaryOfWorldWarOne: z
.string()
.describe("A detailed summary of World War One and its major events - min 500 words")
})
}
})
Expand All @@ -205,7 +211,7 @@ describe("LLMClient Anthropic Provider - mode: MD_JSON", () => {
}

//@ts-expect-error - lazy
expect(omit(["_meta"], final)).toEqual({
expect(omit(["_meta", "summaryOfWorldWarOne"], final)).toEqual({
userDetails: {
firstName: "John",
lastName: "Doe",
Expand Down
44 changes: 22 additions & 22 deletions tests/validator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,29 +82,29 @@ describe("Validator", async () => {
expect(type(output).is<z.infer<typeof QA>>(true)).toBe(true)
}, 100000)

test("Self Correction", async () => {
const question = "What is the meaning of life?"
// test("Self Correction", async () => {
// const question = "What is the meaning of life?"

const invalidContext =
"According to the devil the meaning of live is to live a life of sin and debauchery."
// const invalidContext =
// "According to the devil the meaning of live is to live a life of sin and debauchery."

const output = await instructor.chat.completions.create({
model: "gpt-3.5-turbo",
max_retries: 2,
response_model: { schema: QA, 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: ${invalidContext}\n\nAnswer the following question: ${question}`
}
]
})
// const output = await instructor.chat.completions.create({
// model: "gpt-4",
// max_retries: 2,
// response_model: { schema: QA, 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: ${invalidContext}\n\nAnswer the following question: ${question}`
// }
// ]
// })

expect(type(output).is<z.infer<typeof QA>>(true)).toBe(true)
}, 100000)
// expect(type(output).is<z.infer<typeof QA>>(true)).toBe(true)
// }, 100000)
})

0 comments on commit 54543be

Please sign in to comment.