regolo-client
v1.0.2
Published
TypeScript/JavaScript SDK for the Regolo AI API — chat, completions, embeddings, reranking, image generation and audio transcription
Maintainers
Readme
@regolo/sdk
TypeScript/JavaScript SDK for the Regolo AI API.
Installation
npm install @regolo/sdk
# or
pnpm add @regolo/sdkQuickstart
import { RegoloClient } from "@regolo/sdk";
const client = new RegoloClient({
apiKey: "your-api-key",
chatModel: "your-model",
});
// Single-turn chat
const [role, content] = await client.runChat("Hello, who are you?") as [string, string];
console.log(content);
// Streaming chat
const stream = await client.runChat("Tell me a story", { stream: true });
for await (const [, chunk] of stream as AsyncGenerator<[string, string]>) {
process.stdout.write(chunk);
}Configuration
You can configure global defaults via environment variables before calling tryLoadingFromEnv():
| Variable | Description |
|---|---|
| API_KEY | Default API key |
| LLM | Default chat model |
| IMAGE_GENERATION_MODEL | Default image generation model |
| EMBEDDER_MODEL | Default embeddings model |
| AUDIO_TRANSCRIPTION_MODEL | Default audio transcription model |
| RERANKER_MODEL | Default reranker model |
import { tryLoadingFromEnv } from "@regolo/sdk";
tryLoadingFromEnv();API Reference
new RegoloClient(options?)
Creates a new client instance.
| Option | Type | Description |
|---|---|---|
| apiKey | string \| null | API key |
| chatModel | string \| null | Chat/completions model |
| embedderModel | string \| null | Embeddings model |
| imageGenerationModel | string \| null | Image generation model |
| audioTranscriptionModel | string \| null | Audio transcription model |
| rerankerModel | string \| null | Reranker model |
| alternativeUrl | string \| null | Override the base API URL |
| preExistentConversation | Conversation | Restore a previous conversation |
client.runChat(prompt?, options?)
Send a chat message and receive a response. Maintains conversation history automatically.
const result = await client.runChat("What is 2+2?");
// result: ["assistant", "4"]
// With options
const stream = await client.runChat("Explain gravity", {
stream: true,
maxTokens: 1024,
temperature: 0.7,
});client.completions(prompt, options?)
Text completions (non-chat).
const text = await client.completions("The capital of France is", { maxTokens: 10 });RegoloClient.chatCompletions(messages, options?)
Static method for one-off chat completions without a client instance.
const result = await RegoloClient.chatCompletions(
[{ role: "user", content: "Hello" }],
{ model: "your-model", apiKey: "your-key" },
);client.embeddings(inputText, options?)
Generate text embeddings.
const embeddings = await client.embeddings("Hello world");
// or multiple inputs:
const embeddings = await client.embeddings(["text 1", "text 2"]);client.rerank(query, documents, options?)
Rerank documents by relevance to a query.
const results = await client.rerank(
"What is machine learning?",
["ML is...", "Cooking recipes...", "Deep learning is a subset of ML..."],
);client.audioTranscription(file, options?)
Transcribe audio files.
const text = await client.audioTranscription("/path/to/audio.mp3");client.createImage(prompt, options?)
Generate images from a text prompt.
const [imageBuffer] = await client.createImage("A sunset over the ocean") as Buffer[];RegoloClient.getAvailableModels(apiKey, options?)
List available models.
const models = await RegoloClient.getAvailableModels("your-key");License
MIT
