Skip to Content
Models

language-models

language-models provides a unified interface for working with various language models across different providers. It simplifies model selection and usage, providing a consistent API regardless of the underlying model provider.

The package abstracts away the differences between model providers, allowing you to switch between models without changing your application code. It supports a wide range of models from providers like OpenAI, Anthropic, Google, and more.

Usage Example

import { createModel } from 'language-models' // Create a model interface const model = createModel({ provider: 'openai', modelName: 'gpt-4o', apiKey: process.env.OPENAI_API_KEY, }) // Generate text const response = await model.complete({ prompt: 'Explain quantum computing in simple terms', maxTokens: 250, temperature: 0.7, }) // Use a different model const claudeModel = createModel({ provider: 'anthropic', modelName: 'claude-3-opus', apiKey: process.env.ANTHROPIC_API_KEY, }) // Use streaming for real-time responses const stream = await claudeModel.streamComplete({ prompt: 'Write a step-by-step guide for making bread', maxTokens: 1000, }) for await (const chunk of stream) { console.log(chunk) }
Last updated on