UNPKG

contaigents

Version:

Modular AI Content Ecosystem with Audio Generation

81 lines (80 loc) 2.78 kB
import { BaseLLM } from "./BaseLLM.js"; export class DeepSeekProvider extends BaseLLM { constructor() { super(DeepSeekProvider.providerConfig); } async executePrompt(prompt, options = {}) { if (!this.isConfigured()) { throw new Error("DeepSeek provider is not configured"); } const response = await fetch("https://api.deepseek.com/v1/chat/completions", { method: "POST", headers: { "Content-Type": "application/json", Authorization: `Bearer ${this.config.apiKey}`, }, body: JSON.stringify({ model: this.config.model, messages: [{ role: "user", content: prompt }], temperature: options.temperature ?? 0.7, max_tokens: options.maxTokens, }), }); if (!response.ok) { const error = await response.json(); throw new Error(`DeepSeek API error: ${error.error?.message || "Unknown error"}`); } const data = await response.json(); return { content: data.choices[0].message.content, raw: data, }; } async executeConversation(messages, options = {}) { if (!(await this.isConfigured())) { throw new Error("DeepSeek provider is not configured"); } // Convert ConversationMessage to DeepSeek format (OpenAI-compatible) const deepSeekMessages = messages.map(msg => ({ role: msg.role, content: msg.content })); const response = await fetch("https://api.deepseek.com/v1/chat/completions", { method: "POST", headers: { "Content-Type": "application/json", Authorization: `Bearer ${this.config.apiKey}`, }, body: JSON.stringify({ model: this.config.model, messages: deepSeekMessages, temperature: options.temperature ?? 0.7, max_tokens: options.maxTokens, }), }); if (!response.ok) { const error = await response.json(); throw new Error(`DeepSeek API error: ${error.error?.message || "Unknown error"}`); } const data = await response.json(); return { content: data.choices[0].message.content, raw: data, }; } } DeepSeekProvider.providerConfig = { name: "DeepSeek", configFields: [ { name: "apiKey", required: true, }, { name: "model", required: true, options: ["deepseek-chat", "deepseek-coder"], default: "deepseek-chat", }, ], };