From 54543bef7af8405c67c0452367ab4599f2064d3f Mon Sep 17 00:00:00 2001 From: Dimitri Kennedy Date: Tue, 9 Apr 2024 13:09:10 -0400 Subject: [PATCH] control char fix (#156) --- bun.lockb | Bin 286553 -> 286553 bytes package.json | 2 +- src/instructor.ts | 1 + tests/anthropic.test.ts | 12 ++++++++--- tests/validator.test.ts | 44 ++++++++++++++++++++-------------------- 5 files changed, 33 insertions(+), 26 deletions(-) diff --git a/bun.lockb b/bun.lockb index 182f1963d1bb9fd016a910f33d7f910aa9ccbd9d..5d503531daa2654afacf9b6c43c8f2910be34324 100755 GIT binary patch delta 145 zcmV;C0B--;z7g5J5s)q*WM+itO+(jg1*AOPhwmhks0YB=mjnXAkrzQJN~dHAu}%sv zlh`savxqMh=0NiU%chdile2XIaILrHhXqOm8b~a%jF16ieC}>p_1W%t8S{ZQ9#vwJ zME*CnYcPi&(0|NKx45h&931kIU4Mt&6#=*16#~!i0W!C(1p{Dz0W!A^g#%04olx)4kdu}%sv zlbA3tvxqMh=0LJEv#<9ue*)fE32hGz?pZDz0(;@LrvvRbj8j5rOZ;Zk(n@%Q3)7mI z*=7`ew4wF;Pk)U?*X*pnJvO%0kiduC6#=*16#~!i0Wr6&1p{Dz0Wr4@g#%04F}On{ diff --git a/package.json b/package.json index 3af56456..68b7caa8 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/src/instructor.ts b/src/instructor.ts index f91deb41..fc4b9a7e 100644 --- a/src/instructor.ts +++ b/src/instructor.ts @@ -273,6 +273,7 @@ class Instructor { ...completionParams, stream: true }) + this.log("debug", "raw stream completion response: ", completion) return OAIStream({ diff --git a/tests/anthropic.test.ts b/tests/anthropic.test.ts index e1dc2a96..3afaafbd 100644 --- a/tests/anthropic.test.ts +++ b/tests/anthropic.test.ts @@ -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", () => { @@ -173,6 +174,8 @@ describe("LLMClient Anthropic Provider - mode: MD_JSON", () => { Programming Leadership Communication + + ` } ], @@ -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") }) } }) @@ -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", diff --git a/tests/validator.test.ts b/tests/validator.test.ts index 4ca04ba2..05d7692e 100644 --- a/tests/validator.test.ts +++ b/tests/validator.test.ts @@ -82,29 +82,29 @@ describe("Validator", async () => { expect(type(output).is>(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>(true)).toBe(true) - }, 100000) + // expect(type(output).is>(true)).toBe(true) + // }, 100000) })