From 5a12fbdab7e850d87717c55afc428d4b491ee5e4 Mon Sep 17 00:00:00 2001 From: Dimitri Kennedy Date: Wed, 12 Jun 2024 17:52:10 -0400 Subject: [PATCH] update anthropic tests and llm polyglot latest --- bun.lockb | Bin 288360 -> 287771 bytes package.json | 2 +- tests/anthropic.test.ts | 33 ++++++++++++++++++++------------- 3 files changed, 21 insertions(+), 14 deletions(-) diff --git a/bun.lockb b/bun.lockb index 5692ff0199c694285f196570aa1536e50311adb1..981b7ec2ae5ff199edc453a2bb0cdc39f7ebd61f 100755 GIT binary patch delta 3310 zcmb7`c~DhV9LLYQj|aSmqz@F)G#|Kcgt!2y3580zq~?;P7J}u5TZ>@XlK^oo?Ws3$ z87pVhNpp(wIqFzuQ&u`wQ!~b*;DV?%npkR)_Wk1bzy9jX{l4=(pYuESoO{mi-g$M$ zy_=4C*Ccd3u=PNjjfbZU|8dLA@##N=Z96&o+L{|1Ty0u^_uJCKb=UW<%nmUuXV*?> zXO;i*QC@XStGV;0&B>Z!jIY9&CdMqu&FR}1Q(Bha@@7m~UP5MXhZRUqPY&G5Y7!{A z(5EbAYDQt;(1ii69vG4qSe(+|JsU0ogRMY8O0w&Hv>polQ{3NO1(yVF0!KEdgjX8V zudz|kFWE7;EcIe^%bspbb{?y;P}ib%qP}!*mH(~F3htbX`F}%#8(TOA3>mR(ME+>c zu%VX%O9f+;7J&K0CK8HD>?9a+j~$FFW$857#uY zSNoFccdS1gmYj=KIn14=cO1r?F!uFk*7#uFBuDWl_BgLK%+B;$k@g-qN0oisYfZ3k z5loH(IAiaM0@xV^5E%_n6Py@r%}NbiO9%;84!6Et?eUfK;f?v}yj@dnrP&=Stle3d z$Z&6B*@H42F=QU7Qu{MQECQ@XY^E5F(v)*EQD%un!qk*J?1xY07C@dR$x5ZoQMY*5Ni)_>#){|bpZ2=tq0>S zc7)y#dq;7dz%s=)iggAX7UIV*N~vHM_~8oN1cu9Wg%ZWKD6SjWZOq2w->SIo@C`c0 zZHnswc313Ov7TUM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7x4U(1XluN!m|t&TP066OzfBN zJd&po?-hF%{ybO_BJ+gvt%mpys2DK?j640D#A8S$Lax7vb5CPjkQ6ui$x9+>Oy$RdbMuV)gKBSPNx| zZ4_hsY_UYXI#F)+Ip^A~k=r_~l4O4DbwHg^7t{^$WA6fVF|@YBTJLi6`}|VK(`7wn zd-#oh1^QR0>Vg#&=HoYfGxQ4PsD$`Awh_nB03|@-&YPDl$K?r)xnk|IqWpZpq4W;0 zotAdX7kL)aVg<7Cg{^C)# z*M;`FZLj6d3}gf{onztlP?rgHhT8`dZGw{#c4FvIs{L89Q|YnGoRk{7%(cj=tFe1r zO-@y { }) }) -describe("LLMClient Anthropic Provider - mode: MD_JSON", () => { +describe("LLMClient Anthropic Provider - mode: TOOLS - stream", () => { const instructor = Instructor({ client: anthropicClient, - mode: "MD_JSON" + mode: "TOOLS" }) test("basic completion", async () => { const completion = await instructor.chat.completions.create({ model: "claude-3-sonnet-20240229", + stream: true, max_tokens: 1000, messages: [ { @@ -135,17 +136,24 @@ describe("LLMClient Anthropic Provider - mode: MD_JSON", () => { } ], response_model: { - name: "get_name", + name: "extract_name", schema: z.object({ name: z.string() }) } }) - expect(omit(["_meta"], completion)).toEqual({ name: "Dimitri Kennedy" }) + let final = {} + + for await (const result of completion) { + final = result + } + + //@ts-expect-error ignore for testing + expect(omit(["_meta"], final)).toEqual({ name: "Dimitri Kennedy" }) }) - test("complex schema - streaming", async () => { + test("complex schema", async () => { const completion = await instructor.chat.completions.create({ model: "claude-3-sonnet-20240229", max_tokens: 1000, @@ -173,14 +181,15 @@ describe("LLMClient Anthropic Provider - mode: MD_JSON", () => { Programming Leadership Communication - - ` } ], response_model: { name: "process_user_data", schema: z.object({ + story: z + .string() + .describe("A long and mostly made up story about the user - minimum 500 words"), userDetails: z.object({ firstName: z.string(), lastName: z.string(), @@ -196,21 +205,19 @@ describe("LLMClient Anthropic Provider - mode: MD_JSON", () => { years: z.number().optional() }) ), - skills: z.array(z.string()), - summaryOfWorldWarOne: z - .string() - .describe("A detailed summary of World War One and its major events - min 500 words") + skills: z.array(z.string()) }) } }) let final = {} + for await (const result of completion) { final = result } - //@ts-expect-error - lazy - expect(omit(["_meta", "summaryOfWorldWarOne"], final)).toEqual({ + //@ts-expect-error ignore for testing + expect(omit(["_meta", "story"], final)).toEqual({ userDetails: { firstName: "John", lastName: "Doe",