diff --git a/.changeset/silly-bikes-float.md b/.changeset/silly-bikes-float.md new file mode 100644 index 00000000..8c47a655 --- /dev/null +++ b/.changeset/silly-bikes-float.md @@ -0,0 +1,7 @@ +--- +"@instructor-ai/instructor": minor +--- + +Updating core openai/zod stream/zod/anthropic dependencies to latest - updating tests and support validation to better handle changes without warning unnecessarily. + +Peer dependencies will likely need to be updated to match the latest. diff --git a/bun.lockb b/bun.lockb index 981b7ec2..1caaa38f 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/package.json b/package.json index d291daff..94c1ddd3 100644 --- a/package.json +++ b/package.json @@ -51,15 +51,15 @@ }, "homepage": "https://github.com/instructor-ai/instructor-js#readme", "dependencies": { - "zod-stream": "1.0.3", - "zod-validation-error": "^2.1.0" + "zod-stream": "2.0.0", + "zod-validation-error": "^3.4.0" }, "peerDependencies": { - "openai": ">=4.28.0", - "zod": ">=3.22.4" + "openai": ">=4.58.0", + "zod": ">=3.23.8" }, "devDependencies": { - "@anthropic-ai/sdk": "0.22.0", + "@anthropic-ai/sdk": "0.29.2", "@changesets/changelog-github": "^0.5.0", "@changesets/cli": "^2.27.1", "@ianvs/prettier-plugin-sort-imports": "4.1.0", @@ -75,8 +75,8 @@ "eslint-plugin-only-warn": "^1.1.0", "eslint-plugin-prettier": "^5.1.2", "husky": "^8.0.3", - "llm-polyglot": "2.0.0", - "openai": "4.50.0", + "llm-polyglot": "2.2.0", + "openai": "4.68.1", "prettier": "latest", "ts-inference-check": "^0.3.0", "tsup": "^8.0.1", diff --git a/src/constants/providers.ts b/src/constants/providers.ts index 02c835ae..123b0cc2 100644 --- a/src/constants/providers.ts +++ b/src/constants/providers.ts @@ -107,32 +107,21 @@ export const PROVIDER_SUPPORTED_MODES_BY_MODEL = { [MODE.MD_JSON]: ["*"] }, [PROVIDERS.TOGETHER]: { - [MODE.MD_JSON]: ["*"], - [MODE.JSON_SCHEMA]: [ - "mistralai/Mixtral-8x7B-Instruct-v0.1", - "mistralai/Mistral-7B-Instruct-v0.1", - "togethercomputer/CodeLlama-34b-Instruct" - ], - [MODE.TOOLS]: [ - "mistralai/Mixtral-8x7B-Instruct-v0.1", - "mistralai/Mistral-7B-Instruct-v0.1", - "togethercomputer/CodeLlama-34b-Instruct" - ] + [MODE.MD_JSON]: ["*"] + // [MODE.JSON_SCHEMA]: ["*"] + // [MODE.TOOLS]: ["*"] }, [PROVIDERS.ANYSCALE]: { - [MODE.MD_JSON]: ["*"], - [MODE.JSON_SCHEMA]: [ - "mistralai/Mistral-7B-Instruct-v0.1", - "mistralai/Mixtral-8x7B-Instruct-v0.1" - ], - [MODE.TOOLS]: ["mistralai/Mistral-7B-Instruct-v0.1", "mistralai/Mixtral-8x7B-Instruct-v0.1"] + [MODE.MD_JSON]: ["*"] + // [MODE.JSON_SCHEMA]: ["*"] + // [MODE.TOOLS]: ["*"] }, [PROVIDERS.ANTHROPIC]: { [MODE.MD_JSON]: ["*"], [MODE.TOOLS]: ["*"] }, [PROVIDERS.GROQ]: { - [MODE.TOOLS]: ["mixtral-8x7b-32768", "gemma-7b-it"], + [MODE.TOOLS]: ["*"], [MODE.MD_JSON]: ["*"] } } diff --git a/src/instructor.ts b/src/instructor.ts index c5568c0a..435065dd 100644 --- a/src/instructor.ts +++ b/src/instructor.ts @@ -19,7 +19,6 @@ import { Provider, PROVIDER_PARAMS_TRANSFORMERS, PROVIDER_SUPPORTED_MODES, - PROVIDER_SUPPORTED_MODES_BY_MODEL, PROVIDERS } from "./constants/providers" import { iterableTee } from "./lib" @@ -89,20 +88,6 @@ class Instructor { } } - private validateModelModeSupport( - params: ChatCompletionCreateParamsWithModel - ) { - if (this.provider !== PROVIDERS.OAI) { - const modelSupport = PROVIDER_SUPPORTED_MODES_BY_MODEL[this.provider][this.mode] - - if (!modelSupport.includes("*") && !modelSupport.includes(params.model)) { - throw new Error( - `Model ${params.model} is not supported by provider ${this.provider} in mode ${this.mode}` - ) - } - } - } - private log(level: LogLevel, ...args: T) { if (this.logger) { this.logger(level, ...args) @@ -419,8 +404,6 @@ class Instructor { params: P, requestOptions?: ClientTypeChatCompletionRequestOptions ): Promise> => { - this.validateModelModeSupport(params) - if (this.isChatCompletionCreateParamsWithModel(params)) { if (params.stream) { return this.chatCompletionStream(params, requestOptions) as ReturnTypeBasedOnParams< diff --git a/tests/mode.test.ts b/tests/mode.test.ts index 6629123c..30f94824 100644 --- a/tests/mode.test.ts +++ b/tests/mode.test.ts @@ -4,11 +4,10 @@ import OpenAI from "openai" import { z } from "zod" import { type Mode } from "zod-stream" -import { MODE, Provider, PROVIDER_SUPPORTED_MODES_BY_MODEL, PROVIDERS } from "@/constants/providers" +import { Provider, PROVIDER_SUPPORTED_MODES_BY_MODEL, PROVIDERS } from "@/constants/providers" const default_oai_model = "gpt-4o" -const default_anyscale_model = "mistralai/Mixtral-8x7B-Instruct-v0.1" -const default_together_model = "mistralai/Mixtral-8x7B-Instruct-v0.1" +const default_together_model = "meta-llama/Llama-3.2-90B-Vision-Instruct-Turbo" const default_groq_model = "llama3-70b-8192" const provider_config = { @@ -16,10 +15,6 @@ const provider_config = { baseURL: "https://api.openai.com/v1", apiKey: process.env.OPENAI_API_KEY }, - [PROVIDERS.ANYSCALE]: { - baseURL: "https://api.endpoints.anyscale.com/v1", - apiKey: process.env.ANYSCALE_API_KEY - }, [PROVIDERS.TOGETHER]: { baseURL: "https://api.together.xyz", apiKey: process.env.TOGETHER_API_KEY @@ -55,25 +50,6 @@ const createTestCases = (): { Object.entries(PROVIDER_SUPPORTED_MODES_BY_MODEL).forEach( ([provider, modesByModel]: [Provider, Record]) => { - if (provider === PROVIDERS.ANYSCALE) { - Object.entries(modesByModel).forEach(([mode, models]: [Mode, string[]]) => { - if (mode === MODE.MD_JSON) { - // Skip MD_JSON for Anyscale - its somewhat supported but super flakey - return - } - - if (models.includes("*")) { - testCases.push({ - model: default_anyscale_model, - mode, - provider - }) - } else { - models.forEach(model => testCases.push({ model, mode, provider })) - } - }) - } - if (provider === PROVIDERS.TOGETHER) { Object.entries(modesByModel).forEach(([mode, models]: [Mode, string[]]) => { if (models.includes("*")) { diff --git a/tests/zod-type.test.ts b/tests/zod-type.test.ts index b2d0815f..22b0b54a 100644 --- a/tests/zod-type.test.ts +++ b/tests/zod-type.test.ts @@ -15,7 +15,7 @@ async function extractUser({ schema }) { }) const user = await client.chat.completions.create({ - messages: [{ role: "user", content: "do nothing" }], + messages: [{ role: "user", content: "do nothing - return nothing." }], model: "gpt-4o", response_model: { schema: schema, name: "User" } })