diff --git a/package-lock.json b/package-lock.json index 2aabda99..84a3a562 100644 --- a/package-lock.json +++ b/package-lock.json @@ -661,10 +661,6 @@ "dev": true, "license": "MIT" }, - "node_modules/@mariozechner/ai": { - "resolved": "packages/ai", - "link": true - }, "node_modules/@mariozechner/pi": { "resolved": "packages/pods", "link": true @@ -673,6 +669,10 @@ "resolved": "packages/agent", "link": true }, + "node_modules/@mariozechner/pi-ai": { + "resolved": "packages/ai", + "link": true + }, "node_modules/@mariozechner/pi-tui": { "resolved": "packages/tui", "link": true @@ -2716,10 +2716,10 @@ }, "packages/agent": { "name": "@mariozechner/pi-agent", - "version": "0.5.9", + "version": "0.5.10", "license": "MIT", "dependencies": { - "@mariozechner/pi-tui": "^0.5.8", + "@mariozechner/pi-tui": "^0.5.9", "@types/glob": "^8.1.0", "chalk": "^5.5.0", "glob": "^11.0.3", @@ -3097,8 +3097,8 @@ } }, "packages/ai": { - "name": "@mariozechner/ai", - "version": "0.5.9", + "name": "@mariozechner/pi-ai", + "version": "0.5.10", "license": "MIT", "dependencies": { "@anthropic-ai/sdk": "^0.60.0", @@ -3134,10 +3134,10 @@ }, "packages/pods": { "name": "@mariozechner/pi", - "version": "0.5.9", + "version": "0.5.10", "license": "MIT", "dependencies": { - "@mariozechner/pi-agent": "^0.5.8", + "@mariozechner/pi-agent": "^0.5.9", "chalk": "^5.5.0" }, "bin": { @@ -3150,7 +3150,7 @@ }, "packages/tui": { "name": "@mariozechner/pi-tui", - "version": "0.5.9", + "version": "0.5.10", "license": "MIT", "dependencies": { "@types/mime-types": "^2.1.4", diff --git a/packages/agent/package-lock.json b/packages/agent/package-lock.json index f15b04c3..b7339ea1 100644 --- a/packages/agent/package-lock.json +++ b/packages/agent/package-lock.json @@ -1,12 +1,12 @@ { "name": "@mariozechner/pi-agent", - "version": "0.5.9", + "version": "0.5.10", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@mariozechner/pi-agent", - "version": "0.5.9", + "version": "0.5.10", "license": "MIT", "dependencies": { "@mariozechner/tui": "^0.1.1", diff --git a/packages/agent/package.json b/packages/agent/package.json index b0207317..040a26f6 100644 --- a/packages/agent/package.json +++ b/packages/agent/package.json @@ -1,6 +1,6 @@ { "name": "@mariozechner/pi-agent", - "version": "0.5.9", + "version": "0.5.10", "description": "General-purpose agent with tool calling and session persistence", "type": "module", "bin": { @@ -18,7 +18,7 @@ "prepublishOnly": "npm run clean && npm run build" }, "dependencies": { - "@mariozechner/pi-tui": "^0.5.9", + "@mariozechner/pi-tui": "^0.5.10", "@types/glob": "^8.1.0", "chalk": "^5.5.0", "glob": "^11.0.3", diff --git a/packages/ai/README.md b/packages/ai/README.md index e9f93c26..5db712bb 100644 --- a/packages/ai/README.md +++ b/packages/ai/README.md @@ -2,6 +2,8 @@ Unified LLM API with automatic model discovery, provider configuration, token and cost tracking, and simple context persistence and hand-off to other models mid-session. +**Note**: This library only includes models that support tool calling (function calling), as this is essential for agentic workflows. + ## Supported Providers - **OpenAI** @@ -203,6 +205,63 @@ const model = { const llm = new OpenAICompletionsLLM(model, 'your-api-key'); ``` +## Model Discovery + +All models in this library support tool calling. Models are automatically fetched from OpenRouter and models.dev APIs at build time. + +### List Available Models +```typescript +import { PROVIDERS } from '@mariozechner/pi-ai'; + +// List all OpenAI models (all support tool calling) +for (const [modelId, model] of Object.entries(PROVIDERS.openai.models)) { + console.log(`${modelId}: ${model.name}`); + console.log(` Context: ${model.contextWindow} tokens`); + console.log(` Reasoning: ${model.reasoning}`); + console.log(` Vision: ${model.input.includes('image')}`); + console.log(` Cost: $${model.cost.input}/$${model.cost.output} per million tokens`); +} + +// Find all models with reasoning support +const reasoningModels = []; +for (const provider of Object.values(PROVIDERS)) { + for (const model of Object.values(provider.models)) { + if (model.reasoning) { + reasoningModels.push(model); + } + } +} + +// Find all vision-capable models +const visionModels = []; +for (const provider of Object.values(PROVIDERS)) { + for (const model of Object.values(provider.models)) { + if (model.input.includes('image')) { + visionModels.push(model); + } + } +} +``` + +### Check Model Capabilities +```typescript +import { getModel } from '@mariozechner/pi-ai'; + +const model = getModel('openai', 'gpt-4o-mini'); +if (model) { + console.log(`Model: ${model.name}`); + console.log(`Provider: ${model.provider}`); + console.log(`Context window: ${model.contextWindow} tokens`); + console.log(`Max output: ${model.maxTokens} tokens`); + console.log(`Supports reasoning: ${model.reasoning}`); + console.log(`Supports images: ${model.input.includes('image')}`); + console.log(`Input cost: $${model.cost.input} per million tokens`); + console.log(`Output cost: $${model.cost.output} per million tokens`); + console.log(`Cache read cost: $${model.cost.cacheRead} per million tokens`); + console.log(`Cache write cost: $${model.cost.cacheWrite} per million tokens`); +} +``` + ## Environment Variables Set these environment variables to use `createLLM` without passing API keys: diff --git a/packages/ai/package.json b/packages/ai/package.json index 0cf42c5a..f978ea7b 100644 --- a/packages/ai/package.json +++ b/packages/ai/package.json @@ -1,6 +1,6 @@ { "name": "@mariozechner/pi-ai", - "version": "0.5.9", + "version": "0.5.10", "description": "Unified LLM API with automatic model discovery and provider configuration", "type": "module", "main": "./dist/index.js", diff --git a/packages/ai/src/models.generated.ts b/packages/ai/src/models.generated.ts index 0027fbe3..a92a077c 100644 --- a/packages/ai/src/models.generated.ts +++ b/packages/ai/src/models.generated.ts @@ -1598,22 +1598,6 @@ export const PROVIDERS = { contextWindow: 131072, maxTokens: 16384, } satisfies Model, - "meta-llama/llama-3.1-405b-instruct": { - id: "meta-llama/llama-3.1-405b-instruct", - name: "Meta: Llama 3.1 405B Instruct", - provider: "openrouter", - baseUrl: "https://openrouter.ai/api/v1", - reasoning: false, - input: ["text"], - cost: { - input: 0.7999999999999999, - output: 0.7999999999999999, - cacheRead: 0, - cacheWrite: 0, - }, - contextWindow: 32768, - maxTokens: 16384, - } satisfies Model, "meta-llama/llama-3.1-70b-instruct": { id: "meta-llama/llama-3.1-70b-instruct", name: "Meta: Llama 3.1 70B Instruct", @@ -1630,6 +1614,22 @@ export const PROVIDERS = { contextWindow: 131072, maxTokens: 16384, } satisfies Model, + "meta-llama/llama-3.1-405b-instruct": { + id: "meta-llama/llama-3.1-405b-instruct", + name: "Meta: Llama 3.1 405B Instruct", + provider: "openrouter", + baseUrl: "https://openrouter.ai/api/v1", + reasoning: false, + input: ["text"], + cost: { + input: 0.7999999999999999, + output: 0.7999999999999999, + cacheRead: 0, + cacheWrite: 0, + }, + contextWindow: 32768, + maxTokens: 16384, + } satisfies Model, "mistralai/mistral-nemo": { id: "mistralai/mistral-nemo", name: "Mistral: Mistral Nemo", @@ -1646,6 +1646,22 @@ export const PROVIDERS = { contextWindow: 32000, maxTokens: 4096, } satisfies Model, + "mistralai/mistral-7b-instruct-v0.3": { + id: "mistralai/mistral-7b-instruct-v0.3", + name: "Mistral: Mistral 7B Instruct v0.3", + provider: "openrouter", + baseUrl: "https://openrouter.ai/api/v1", + reasoning: false, + input: ["text"], + cost: { + input: 0.028, + output: 0.054, + cacheRead: 0, + cacheWrite: 0, + }, + contextWindow: 32768, + maxTokens: 16384, + } satisfies Model, "mistralai/mistral-7b-instruct:free": { id: "mistralai/mistral-7b-instruct:free", name: "Mistral: Mistral 7B Instruct (free)", @@ -1678,22 +1694,6 @@ export const PROVIDERS = { contextWindow: 32768, maxTokens: 16384, } satisfies Model, - "mistralai/mistral-7b-instruct-v0.3": { - id: "mistralai/mistral-7b-instruct-v0.3", - name: "Mistral: Mistral 7B Instruct v0.3", - provider: "openrouter", - baseUrl: "https://openrouter.ai/api/v1", - reasoning: false, - input: ["text"], - cost: { - input: 0.028, - output: 0.054, - cacheRead: 0, - cacheWrite: 0, - }, - contextWindow: 32768, - maxTokens: 16384, - } satisfies Model, "microsoft/phi-3-mini-128k-instruct": { id: "microsoft/phi-3-mini-128k-instruct", name: "Microsoft: Phi-3 Mini 128K Instruct", @@ -1726,22 +1726,6 @@ export const PROVIDERS = { contextWindow: 128000, maxTokens: 4096, } satisfies Model, - "meta-llama/llama-3-8b-instruct": { - id: "meta-llama/llama-3-8b-instruct", - name: "Meta: Llama 3 8B Instruct", - provider: "openrouter", - baseUrl: "https://openrouter.ai/api/v1", - reasoning: false, - input: ["text"], - cost: { - input: 0.03, - output: 0.06, - cacheRead: 0, - cacheWrite: 0, - }, - contextWindow: 8192, - maxTokens: 16384, - } satisfies Model, "meta-llama/llama-3-70b-instruct": { id: "meta-llama/llama-3-70b-instruct", name: "Meta: Llama 3 70B Instruct", @@ -1758,6 +1742,22 @@ export const PROVIDERS = { contextWindow: 8192, maxTokens: 16384, } satisfies Model, + "meta-llama/llama-3-8b-instruct": { + id: "meta-llama/llama-3-8b-instruct", + name: "Meta: Llama 3 8B Instruct", + provider: "openrouter", + baseUrl: "https://openrouter.ai/api/v1", + reasoning: false, + input: ["text"], + cost: { + input: 0.03, + output: 0.06, + cacheRead: 0, + cacheWrite: 0, + }, + contextWindow: 8192, + maxTokens: 16384, + } satisfies Model, "mistralai/mixtral-8x22b-instruct": { id: "mistralai/mixtral-8x22b-instruct", name: "Mistral: Mixtral 8x22B Instruct", @@ -1854,22 +1854,6 @@ export const PROVIDERS = { contextWindow: 128000, maxTokens: 4096, } satisfies Model, - "mistralai/mistral-small": { - id: "mistralai/mistral-small", - name: "Mistral Small", - provider: "openrouter", - baseUrl: "https://openrouter.ai/api/v1", - reasoning: false, - input: ["text"], - cost: { - input: 0.19999999999999998, - output: 0.6, - cacheRead: 0, - cacheWrite: 0, - }, - contextWindow: 32768, - maxTokens: 4096, - } satisfies Model, "mistralai/mistral-tiny": { id: "mistralai/mistral-tiny", name: "Mistral Tiny", @@ -1886,6 +1870,22 @@ export const PROVIDERS = { contextWindow: 32768, maxTokens: 4096, } satisfies Model, + "mistralai/mistral-small": { + id: "mistralai/mistral-small", + name: "Mistral Small", + provider: "openrouter", + baseUrl: "https://openrouter.ai/api/v1", + reasoning: false, + input: ["text"], + cost: { + input: 0.19999999999999998, + output: 0.6, + cacheRead: 0, + cacheWrite: 0, + }, + contextWindow: 32768, + maxTokens: 4096, + } satisfies Model, "mistralai/mixtral-8x7b-instruct": { id: "mistralai/mixtral-8x7b-instruct", name: "Mistral: Mixtral 8x7B Instruct", @@ -2473,21 +2473,6 @@ export const PROVIDERS = { contextWindow: 16385, maxTokens: 4096, } satisfies Model, - "gpt-3.5-turbo": { - id: "gpt-3.5-turbo", - name: "OpenAI: GPT-3.5 Turbo", - provider: "openai", - reasoning: false, - input: ["text"], - cost: { - input: 0.5, - output: 1.5, - cacheRead: 0, - cacheWrite: 0, - }, - contextWindow: 16385, - maxTokens: 4096, - } satisfies Model, "gpt-4": { id: "gpt-4", name: "OpenAI: GPT-4", @@ -2518,6 +2503,21 @@ export const PROVIDERS = { contextWindow: 8191, maxTokens: 4096, } satisfies Model, + "gpt-3.5-turbo": { + id: "gpt-3.5-turbo", + name: "OpenAI: GPT-3.5 Turbo", + provider: "openai", + reasoning: false, + input: ["text"], + cost: { + input: 0.5, + output: 1.5, + cacheRead: 0, + cacheWrite: 0, + }, + contextWindow: 16385, + maxTokens: 4096, + } satisfies Model, }, }, anthropic: { @@ -2597,9 +2597,9 @@ export const PROVIDERS = { contextWindow: 200000, maxTokens: 64000, } satisfies Model, - "claude-3-5-haiku-latest": { - id: "claude-3-5-haiku-latest", - name: "Anthropic: Claude 3.5 Haiku", + "claude-3-5-haiku-20241022": { + id: "claude-3-5-haiku-20241022", + name: "Anthropic: Claude 3.5 Haiku (2024-10-22)", provider: "anthropic", reasoning: false, input: ["text", "image"], @@ -2612,9 +2612,9 @@ export const PROVIDERS = { contextWindow: 200000, maxTokens: 8192, } satisfies Model, - "claude-3-5-haiku-20241022": { - id: "claude-3-5-haiku-20241022", - name: "Anthropic: Claude 3.5 Haiku (2024-10-22)", + "claude-3-5-haiku-latest": { + id: "claude-3-5-haiku-latest", + name: "Anthropic: Claude 3.5 Haiku", provider: "anthropic", reasoning: false, input: ["text", "image"], diff --git a/packages/pods/package-lock.json b/packages/pods/package-lock.json index beaaf453..b700b51d 100644 --- a/packages/pods/package-lock.json +++ b/packages/pods/package-lock.json @@ -1,12 +1,12 @@ { "name": "@mariozechner/pi", - "version": "0.5.9", + "version": "0.5.10", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@mariozechner/pi", - "version": "0.5.9", + "version": "0.5.10", "license": "MIT", "dependencies": { "@ai-sdk/openai": "^2.0.5", diff --git a/packages/pods/package.json b/packages/pods/package.json index 693a5827..5d016c9c 100644 --- a/packages/pods/package.json +++ b/packages/pods/package.json @@ -1,6 +1,6 @@ { "name": "@mariozechner/pi", - "version": "0.5.9", + "version": "0.5.10", "description": "CLI tool for managing vLLM deployments on GPU pods", "type": "module", "bin": { @@ -34,7 +34,7 @@ "node": ">=20.0.0" }, "dependencies": { - "@mariozechner/pi-agent": "^0.5.9", + "@mariozechner/pi-agent": "^0.5.10", "chalk": "^5.5.0" }, "devDependencies": {} diff --git a/packages/tui/package-lock.json b/packages/tui/package-lock.json index 76955b5e..807b645f 100644 --- a/packages/tui/package-lock.json +++ b/packages/tui/package-lock.json @@ -1,12 +1,12 @@ { "name": "@mariozechner/tui", - "version": "0.5.9", + "version": "0.5.10", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@mariozechner/tui", - "version": "0.5.9", + "version": "0.5.10", "license": "MIT", "dependencies": { "@types/mime-types": "^2.1.4", diff --git a/packages/tui/package.json b/packages/tui/package.json index c1124332..94528750 100644 --- a/packages/tui/package.json +++ b/packages/tui/package.json @@ -1,6 +1,6 @@ { "name": "@mariozechner/pi-tui", - "version": "0.5.9", + "version": "0.5.10", "description": "Terminal User Interface library with differential rendering for efficient text-based applications", "type": "module", "main": "dist/index.js",