Skip to content

Commit

Permalink
updating deps and tests (#191)
Browse files Browse the repository at this point in the history
  • Loading branch information
roodboi authored Oct 19, 2024
1 parent c810a5c commit bf240b2
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 69 deletions.
7 changes: 7 additions & 0 deletions .changeset/silly-bikes-float.md
Original file line number Diff line number Diff line change
@@ -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.
Binary file modified bun.lockb
Binary file not shown.
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
25 changes: 7 additions & 18 deletions src/constants/providers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]: ["*"]
}
}
17 changes: 0 additions & 17 deletions src/instructor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -89,20 +88,6 @@ class Instructor<C> {
}
}

private validateModelModeSupport<T extends z.AnyZodObject>(
params: ChatCompletionCreateParamsWithModel<T>
) {
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<T extends unknown[]>(level: LogLevel, ...args: T) {
if (this.logger) {
this.logger(level, ...args)
Expand Down Expand Up @@ -419,8 +404,6 @@ class Instructor<C> {
params: P,
requestOptions?: ClientTypeChatCompletionRequestOptions<C>
): Promise<ReturnTypeBasedOnParams<typeof this.client, P>> => {
this.validateModelModeSupport(params)

if (this.isChatCompletionCreateParamsWithModel(params)) {
if (params.stream) {
return this.chatCompletionStream(params, requestOptions) as ReturnTypeBasedOnParams<
Expand Down
28 changes: 2 additions & 26 deletions tests/mode.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,17 @@ 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 = {
[PROVIDERS.OAI]: {
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
Expand Down Expand Up @@ -55,25 +50,6 @@ const createTestCases = (): {

Object.entries(PROVIDER_SUPPORTED_MODES_BY_MODEL).forEach(
([provider, modesByModel]: [Provider, Record<Mode, string[]>]) => {
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("*")) {
Expand Down
2 changes: 1 addition & 1 deletion tests/zod-type.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
})
Expand Down

0 comments on commit bf240b2

Please sign in to comment.