@logicleai/llmosaic
v0.2.6
Published
JavaScript toolkit for calling LLM APIs in OpenAI format
Downloads
19
Readme
Installation
npm install @logicleai/llmosaic
Usage
import { Provider, ProviderType } from '@logicleai/llmosaic';
const openai = new Provider({
apiKey: process.env['OPENAI_API_KEY'],
providerType: ProviderType.Anthropic,
});
async function main() {
const chatCompletion = await openai.completion({
messages: [{ role: 'user', content: 'Say this is a test' }],
model: 'claude-3-opus-20240229',
});
}
main();
Streaming responses
import { Provider, ProviderType } from '@logicleai/llmosaic';
const openai = new Provider({
providerType: ProviderType.TogetherAI,
});
async function main() {
const stream = await openai.completion({
messages: [{ role: 'user', content: 'Say this is a test' }],
model: 'mistralai/Mixtral-8x7B-Instruct-v0.1',
stream: true,
});
for await (const chunk of stream) {
process.stdout.write(chunk.choices[0]?.delta?.content || '');
}
}
main();
Supported Providers
| Provider | Completion | Streaming | Models | |:------------:|:--------------:|:-------------:|:----------:| | openai | ✅ | ✅ | ✅ | | anthropic | ✅ | ✅ | ✅ | | togetherai | ✅ | ✅ | ✅ | | groq | ✅ | ✅ | ✅ | | localai | ✅ | ✅ | ✅ |
Contributing
Clone the repo
git clone https://github.com/logicleai/llmosaic.git
Install dependencies
npm install
Build the project
npm run build