co-mono/packages/ai
Mario Zechner 4bb3a5ad02 feat(ai): Add OpenAI-compatible provider examples for multiple services
- Add examples for Cerebras, Groq, Ollama, and OpenRouter
- Update OpenAI Completions provider to handle base URL properly
- Simplify README formatting
- All examples use the same OpenAICompletionsLLM provider with different base URLs
2025-08-25 17:41:47 +02:00
..
docs refactor(ai): Add completion signal to onText/onThinking callbacks 2025-08-24 20:33:26 +02:00
src feat(ai): Add OpenAI-compatible provider examples for multiple services 2025-08-25 17:41:47 +02:00
test feat(ai): Add OpenAI-compatible provider examples for multiple services 2025-08-25 17:41:47 +02:00
package.json test(ai): Add comprehensive E2E tests for all AI providers 2025-08-25 15:54:26 +02:00
README.md feat(ai): Add OpenAI-compatible provider examples for multiple services 2025-08-25 17:41:47 +02:00
tsconfig.build.json feat(ai): Create unified AI package with OpenAI, Anthropic, and Gemini support 2025-08-17 20:18:45 +02:00

@mariozechner/ai

Unified API for OpenAI, Anthropic, and Google Gemini LLM providers with streaming, tool calling, and thinking support.

Installation

npm install @mariozechner/ai

Quick Start

import { AnthropicLLM } from '@mariozechner/ai/providers/anthropic';
import { OpenAICompletionsLLM } from '@mariozechner/ai/providers/openai-completions';
import { GeminiLLM } from '@mariozechner/ai/providers/gemini';

// Pick your provider - same API for all
const llm = new AnthropicLLM('claude-3-5-sonnet-20241022');
// const llm = new OpenAICompletionsLLM('gpt-4o');
// const llm = new GeminiLLM('gemini-2.0-flash-exp');

// Basic completion
const response = await llm.complete({
  messages: [{ role: 'user', content: 'Hello!' }]
});
console.log(response.content);

// Streaming with thinking
const streamResponse = await llm.complete({
  messages: [{ role: 'user', content: 'Explain quantum computing' }]
}, {
  onText: (chunk) => process.stdout.write(chunk),
  onThinking: (chunk) => process.stderr.write(chunk),
  // Provider specific config
  thinking: { enabled: true }
});

// Tool calling
const tools = [{
  name: 'calculator',
  description: 'Perform calculations',
  parameters: {
    type: 'object',
    properties: {
      expression: { type: 'string' }
    },
    required: ['expression']
  }
}];

const toolResponse = await llm.complete({
  messages: [{ role: 'user', content: 'What is 15 * 27?' }],
  tools
});

if (toolResponse.toolCalls) {
  for (const call of toolResponse.toolCalls) {
    console.log(`Tool: ${call.name}, Args:`, call.arguments);
  }
}

Development

This package is part of the pi monorepo. See the main README for development instructions.

License

MIT