From 414477fe7760f02d317219c941bd6654202c1364 Mon Sep 17 00:00:00 2001 From: sxjeru Date: Mon, 20 Jan 2025 21:48:57 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=92=84=20style:=20Add=20deepseek=20r1=20m?= =?UTF-8?q?odel=20(#5520)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Update deepseek.ts * Update deepseek.ts * Update deepseek.ts * Update index.ts * Update index.ts * Update index.ts --- src/config/aiModels/deepseek.ts | 16 ++++++++++++++++ src/config/modelProviders/deepseek.ts | 23 +++++++++++++++++++---- src/libs/agent-runtime/deepseek/index.ts | 24 +++++++++++++++++++++++- 3 files changed, 58 insertions(+), 5 deletions(-) diff --git a/src/config/aiModels/deepseek.ts b/src/config/aiModels/deepseek.ts index 6d8b56822d18..0d2b00ceb8ea 100644 --- a/src/config/aiModels/deepseek.ts +++ b/src/config/aiModels/deepseek.ts @@ -20,6 +20,22 @@ const deepseekChatModels: AIChatModelCard[] = [ releasedAt: '2024-12-26', type: 'chat', }, + { + contextWindowTokens: 65_536, + description: + 'DeepSeek 推出的推理模型。在输出最终回答之前,模型会先输出一段思维链内容,以提升最终答案的准确性。', + displayName: 'DeepSeek R1', + enabled: true, + id: 'deepseek-reasoner', + pricing: { + cachedInput: 1, + currency: 'CNY', + input: 4, + output: 16, + }, + releasedAt: '2025-01-20', + type: 'chat', + }, ]; export const allModels = [...deepseekChatModels]; diff --git a/src/config/modelProviders/deepseek.ts b/src/config/modelProviders/deepseek.ts index 1b61564280f2..7135c2fa9c3d 100644 --- a/src/config/modelProviders/deepseek.ts +++ b/src/config/modelProviders/deepseek.ts @@ -11,14 +11,29 @@ const DeepSeek: ModelProviderCard = { enabled: true, functionCall: true, id: 'deepseek-chat', - pricing: { - cachedInput: 0.5, + pricing: { // 2025.2.9 之后涨价 + cachedInput: 0.1, currency: 'CNY', - input: 2, - output: 8, + input: 1, + output: 2, }, releasedAt: '2024-12-26', }, + { + contextWindowTokens: 65_536, + description: + 'DeepSeek 推出的推理模型。在输出最终回答之前,模型会先输出一段思维链内容,以提升最终答案的准确性。', + displayName: 'DeepSeek R1', + enabled: true, + id: 'deepseek-reasoner', + pricing: { + cachedInput: 1, + currency: 'CNY', + input: 4, + output: 16, + }, + releasedAt: '2025-01-20', + }, ], checkModel: 'deepseek-chat', description: diff --git a/src/libs/agent-runtime/deepseek/index.ts b/src/libs/agent-runtime/deepseek/index.ts index 9f312cbd28fd..fa1527e89c72 100644 --- a/src/libs/agent-runtime/deepseek/index.ts +++ b/src/libs/agent-runtime/deepseek/index.ts @@ -1,8 +1,30 @@ -import { ModelProvider } from '../types'; +import OpenAI from 'openai'; + +import { ChatStreamPayload, ModelProvider } from '../types'; import { LobeOpenAICompatibleFactory } from '../utils/openaiCompatibleFactory'; export const LobeDeepSeekAI = LobeOpenAICompatibleFactory({ baseURL: 'https://api.deepseek.com/v1', + chatCompletion: { + handlePayload: ({ frequency_penalty, model, presence_penalty, temperature, top_p, ...payload }: ChatStreamPayload) => + ({ + ...payload, + model, + ...(model === 'deepseek-reasoner' + ? { + frequency_penalty: undefined, + presence_penalty: undefined, + temperature: undefined, + top_p: undefined, + } + : { + frequency_penalty, + presence_penalty, + temperature, + top_p, + }), + }) as OpenAI.ChatCompletionCreateParamsStreaming, + }, debug: { chatCompletion: () => process.env.DEBUG_DEEPSEEK_CHAT_COMPLETION === '1', },