From eae63375e1954deaeff236571a3601a1d484dca5 Mon Sep 17 00:00:00 2001 From: Dimitri Kennedy Date: Sat, 20 Apr 2024 22:40:13 -0400 Subject: [PATCH 1/4] update standard completions to include the _meta --- examples/extract_user/index.ts | 1 + src/instructor.ts | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/extract_user/index.ts b/examples/extract_user/index.ts index baaa72dd..3ac8fad3 100644 --- a/examples/extract_user/index.ts +++ b/examples/extract_user/index.ts @@ -29,6 +29,7 @@ const user = await client.chat.completions.create({ }) console.log(user) + // { // age: 30, // name: "Jason Liu", diff --git a/src/instructor.ts b/src/instructor.ts index 9376dae7..bce5bca8 100644 --- a/src/instructor.ts +++ b/src/instructor.ts @@ -221,7 +221,7 @@ class Instructor { } } - return validation.data + return { ...validation.data, _meta: data._meta } } catch (error) { if (!(error instanceof ZodError)) { throw error From 8fdb7976f51057ca81abdff77da00e01c1cf8bdd Mon Sep 17 00:00:00 2001 From: Dimitri Kennedy Date: Sat, 20 Apr 2024 22:40:44 -0400 Subject: [PATCH 2/4] changeset --- .changeset/happy-suits-dress.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/happy-suits-dress.md diff --git a/.changeset/happy-suits-dress.md b/.changeset/happy-suits-dress.md new file mode 100644 index 00000000..5387309f --- /dev/null +++ b/.changeset/happy-suits-dress.md @@ -0,0 +1,5 @@ +--- +"@instructor-ai/instructor": patch +--- + +make sure we pass through \_meta on non stream completions From 65f273c1dcf39b58f9dafedeac00b72310fd68bc Mon Sep 17 00:00:00 2001 From: Dimitri Kennedy Date: Sat, 20 Apr 2024 22:42:17 -0400 Subject: [PATCH 3/4] add some defense --- src/instructor.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/instructor.ts b/src/instructor.ts index bce5bca8..22acd873 100644 --- a/src/instructor.ts +++ b/src/instructor.ts @@ -221,7 +221,7 @@ class Instructor { } } - return { ...validation.data, _meta: data._meta } + return { ...validation.data, _meta: data?._meta ?? {} } } catch (error) { if (!(error instanceof ZodError)) { throw error From 674173df5e0c96a4e7aa7bd694f3d5a55e0572aa Mon Sep 17 00:00:00 2001 From: Dimitri Kennedy Date: Sat, 20 Apr 2024 23:01:45 -0400 Subject: [PATCH 4/4] fix anthropic tests --- tests/anthropic.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/anthropic.test.ts b/tests/anthropic.test.ts index 86e8ea09..832eafe8 100644 --- a/tests/anthropic.test.ts +++ b/tests/anthropic.test.ts @@ -142,7 +142,7 @@ describe("LLMClient Anthropic Provider - mode: MD_JSON", () => { } }) - expect(completion).toEqual({ name: "Dimitri Kennedy" }) + expect(omit(["_meta"], completion)).toEqual({ name: "Dimitri Kennedy" }) }) test("complex schema - streaming", async () => {