UNPKG

@langchain/core

Version:
1 lines 3.48 kB
{"version":3,"file":"deepseek.cjs","names":["message: AIMessage","blocks: Array<ContentBlock.Standard>","_isString","ChatDeepSeekTranslator: StandardContentBlockTranslator"],"sources":["../../../src/messages/block_translators/deepseek.ts"],"sourcesContent":["import { AIMessage } from \"../ai.js\";\nimport { ContentBlock } from \"../content/index.js\";\nimport type { StandardContentBlockTranslator } from \"./index.js\";\nimport { _isString } from \"./utils.js\";\n\n/**\n * Converts a DeepSeek AI message to an array of v1 standard content blocks.\n *\n * This function processes an AI message from DeepSeek's API format\n * and converts it to the standardized v1 content block format. It handles\n * both string content and the reasoning_content in additional_kwargs.\n *\n * @param message - The AI message containing DeepSeek-formatted content\n * @returns Array of content blocks in v1 standard format\n *\n * @example\n * ```typescript\n * const message = new AIMessage({\n * content: \"The answer is 42\",\n * additional_kwargs: { reasoning_content: \"Let me think about this...\" }\n * });\n * const standardBlocks = convertToV1FromDeepSeekMessage(message);\n * // Returns:\n * // [\n * // { type: \"reasoning\", reasoning: \"Let me think about this...\" },\n * // { type: \"text\", text: \"The answer is 42\" }\n * // ]\n * ```\n */\nexport function convertToV1FromDeepSeekMessage(\n message: AIMessage\n): Array<ContentBlock.Standard> {\n const blocks: Array<ContentBlock.Standard> = [];\n\n // Extract reasoning from additional_kwargs.reasoning_content\n const reasoningContent = message.additional_kwargs?.reasoning_content;\n if (_isString(reasoningContent) && reasoningContent.length > 0) {\n blocks.push({\n type: \"reasoning\",\n reasoning: reasoningContent,\n });\n }\n\n // Handle text content\n if (typeof message.content === \"string\") {\n if (message.content.length > 0) {\n blocks.push({\n type: \"text\",\n text: message.content,\n });\n }\n } else {\n for (const block of message.content) {\n if (\n typeof block === \"object\" &&\n \"type\" in block &&\n block.type === \"text\" &&\n \"text\" in block &&\n _isString(block.text)\n ) {\n blocks.push({\n type: \"text\",\n text: block.text,\n });\n }\n }\n }\n\n // Add tool calls if present\n for (const toolCall of message.tool_calls ?? []) {\n blocks.push({\n type: \"tool_call\",\n id: toolCall.id,\n name: toolCall.name,\n args: toolCall.args,\n });\n }\n\n return blocks;\n}\n\nexport const ChatDeepSeekTranslator: StandardContentBlockTranslator = {\n translateContent: convertToV1FromDeepSeekMessage,\n translateContentChunk: convertToV1FromDeepSeekMessage,\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BA,SAAgB,+BACdA,SAC8B;CAC9B,MAAMC,SAAuC,CAAE;CAG/C,MAAM,mBAAmB,QAAQ,mBAAmB;AACpD,KAAIC,wBAAU,iBAAiB,IAAI,iBAAiB,SAAS,GAC3D,OAAO,KAAK;EACV,MAAM;EACN,WAAW;CACZ,EAAC;AAIJ,KAAI,OAAO,QAAQ,YAAY,UAC7B;MAAI,QAAQ,QAAQ,SAAS,GAC3B,OAAO,KAAK;GACV,MAAM;GACN,MAAM,QAAQ;EACf,EAAC;CACH,MAED,MAAK,MAAM,SAAS,QAAQ,QAC1B,KACE,OAAO,UAAU,YACjB,UAAU,SACV,MAAM,SAAS,UACf,UAAU,SACVA,wBAAU,MAAM,KAAK,EAErB,OAAO,KAAK;EACV,MAAM;EACN,MAAM,MAAM;CACb,EAAC;AAMR,MAAK,MAAM,YAAY,QAAQ,cAAc,CAAE,GAC7C,OAAO,KAAK;EACV,MAAM;EACN,IAAI,SAAS;EACb,MAAM,SAAS;EACf,MAAM,SAAS;CAChB,EAAC;AAGJ,QAAO;AACR;AAED,MAAaC,yBAAyD;CACpE,kBAAkB;CAClB,uBAAuB;AACxB"}