Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include meta on standard completion #166

Merged
merged 4 commits into from
Apr 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading