UNPKG

aiwrapper

Version:

A Universal AI Wrapper for JavaScript & TypeScript

47 lines 2.06 kB
import { OpenAILikeLang } from "../openai-like/openai-like-lang.js"; import { models } from 'aimodels'; export class DeepSeekLang extends OpenAILikeLang { constructor(options) { const modelName = options.model || "deepseek-chat"; super({ apiKey: options.apiKey, model: modelName, systemPrompt: options.systemPrompt || "", maxTokens: options.maxTokens, baseURL: "https://api.deepseek.com/v1", }); } // Check if the model supports reasoning supportsReasoning() { // Check if the model has reasoning capability in aimodels const modelInfo = models.id(this._config.model); // First check if the model has the "reason" capability if (modelInfo === null || modelInfo === void 0 ? void 0 : modelInfo.can("reason")) { return true; } // As a fallback, check if the model name contains "reasoner" // This is a heuristic in case the model info is not up-to-date const isReasonerModel = this._config.model.toLowerCase().includes("reasoner"); return isReasonerModel; } /** * Override the handleStreamData method to capture reasoning content */ handleStreamData(data, result, messages, onResult) { if (data.finished) { result.finished = true; onResult === null || onResult === void 0 ? void 0 : onResult(result); return; } // Handle reasoning content if available (DeepSeek specific) if (data.choices && data.choices[0].delta.reasoning_content) { const reasoningContent = data.choices[0].delta.reasoning_content; result.thinking = (result.thinking || "") + reasoningContent; onResult === null || onResult === void 0 ? void 0 : onResult(result); return; } // Fall back to standard content handling from the parent class super.handleStreamData(data, result, messages, onResult); } } //# sourceMappingURL=deepseek-lang.js.map