Skip to content

Commit

Permalink
Include meta on standard completion (#166)
Browse files Browse the repository at this point in the history
  • Loading branch information
roodboi authored Apr 21, 2024
1 parent 972d9ae commit ddfe257
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/happy-suits-dress.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@instructor-ai/instructor": patch
---

make sure we pass through \_meta on non stream completions
1 change: 1 addition & 0 deletions examples/extract_user/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const user = await client.chat.completions.create({
})

console.log(user)

// {
// age: 30,
// name: "Jason Liu",
Expand Down
2 changes: 1 addition & 1 deletion src/instructor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ class Instructor<C extends GenericClient | OpenAI> {
}
}

return validation.data
return { ...validation.data, _meta: data?._meta ?? {} }
} catch (error) {
if (!(error instanceof ZodError)) {
throw error
Expand Down
2 changes: 1 addition & 1 deletion tests/anthropic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down

0 comments on commit ddfe257

Please sign in to comment.