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 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..22acd873 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 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 () => {