@astack-tech/integrations 0.1.1-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,215 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/model-provider/index.ts
31
+ var model_provider_exports = {};
32
+ __export(model_provider_exports, {
33
+ Deepseek: () => deepseek_default
34
+ });
35
+ module.exports = __toCommonJS(model_provider_exports);
36
+
37
+ // src/model-provider/deepseek/index.ts
38
+ var import_core = require("@astack-tech/core");
39
+ var import_openai = __toESM(require("openai"), 1);
40
+ var Deepseek = class extends import_core.Component {
41
+ constructor(config) {
42
+ super({});
43
+ this.client = new import_openai.default({
44
+ apiKey: config.apiKey,
45
+ baseURL: config.baseURL || "https://api.deepseek.com/v1"
46
+ });
47
+ this.model = config.model || "deepseek-chat";
48
+ this.temperature = config.temperature ?? 0.7;
49
+ this.maxTokens = config.maxTokens;
50
+ this.topP = config.topP;
51
+ this.systemPrompt = config.systemPrompt;
52
+ if (config.rawTools && config.rawTools.length > 0) {
53
+ this.tools = config.rawTools.map((tool) => ({
54
+ type: "function",
55
+ function: {
56
+ name: tool.name,
57
+ description: tool.description,
58
+ parameters: tool.parameters || {}
59
+ }
60
+ }));
61
+ } else {
62
+ this.tools = config.tools;
63
+ }
64
+ import_core.Component.Port.I("prompt").attach(this);
65
+ import_core.Component.Port.I("messages").attach(this);
66
+ import_core.Component.Port.O("completion").attach(this);
67
+ import_core.Component.Port.O("message").attach(this);
68
+ }
69
+ /**
70
+ * 生成文本完成
71
+ * @param prompt 提示文本
72
+ * @returns 生成的文本
73
+ */
74
+ async generateCompletion(prompt) {
75
+ const messages = [];
76
+ if (this.systemPrompt) {
77
+ messages.push({
78
+ role: "system",
79
+ content: this.systemPrompt
80
+ });
81
+ }
82
+ messages.push({
83
+ role: "user",
84
+ content: prompt
85
+ });
86
+ const requestParams = {
87
+ model: this.model,
88
+ messages,
89
+ temperature: this.temperature,
90
+ max_tokens: this.maxTokens,
91
+ top_p: this.topP
92
+ };
93
+ if (this.tools && this.tools.length > 0) {
94
+ requestParams.tools = this.tools;
95
+ }
96
+ const response = await this.client.chat.completions.create(requestParams);
97
+ if (response.choices[0].message.tool_calls && response.choices[0].message.tool_calls.length > 0) {
98
+ return JSON.stringify(response.choices[0].message);
99
+ }
100
+ return response.choices[0].message.content || "";
101
+ }
102
+ /**
103
+ * 处理对话消息
104
+ * @param messages 对话消息数组
105
+ * @param options 可选的调用选项,包含临时工具列表
106
+ * @returns 生成的响应消息
107
+ */
108
+ async chatCompletion(messages, options) {
109
+ const formattedMessages = [];
110
+ if (this.systemPrompt) {
111
+ formattedMessages.push({
112
+ role: "system",
113
+ content: this.systemPrompt
114
+ });
115
+ }
116
+ formattedMessages.push(
117
+ ...messages.map((msg) => {
118
+ const formattedMsg = {
119
+ role: msg.role,
120
+ content: msg.content
121
+ };
122
+ if (msg.role === "tool" && msg.tool_call_id) {
123
+ formattedMsg.tool_call_id = msg.tool_call_id;
124
+ }
125
+ return formattedMsg;
126
+ })
127
+ );
128
+ const requestParams = {
129
+ model: this.model,
130
+ messages: formattedMessages,
131
+ temperature: this.temperature,
132
+ max_tokens: this.maxTokens,
133
+ top_p: this.topP
134
+ };
135
+ const toolsToUse = options?.temporaryTools || this.tools;
136
+ if (toolsToUse && toolsToUse.length > 0) {
137
+ const formattedTools = toolsToUse.map((tool) => {
138
+ const typedTool = tool;
139
+ if (typedTool.type === "function") {
140
+ return tool;
141
+ }
142
+ return {
143
+ type: "function",
144
+ function: {
145
+ name: typedTool.name,
146
+ description: typedTool.description,
147
+ parameters: typedTool.parameters || {}
148
+ }
149
+ };
150
+ });
151
+ requestParams.tools = formattedTools;
152
+ }
153
+ const response = await this.client.chat.completions.create(requestParams);
154
+ const responseMessage = response.choices[0].message;
155
+ const result = {
156
+ role: "assistant",
157
+ content: responseMessage.content || ""
158
+ };
159
+ if (responseMessage.tool_calls && responseMessage.tool_calls.length > 0) {
160
+ result.tool_calls = responseMessage.tool_calls.map((toolCall) => ({
161
+ id: toolCall.id,
162
+ tool_name: toolCall.function.name,
163
+ arguments: JSON.parse(toolCall.function.arguments || "{}")
164
+ }));
165
+ }
166
+ return result;
167
+ }
168
+ /**
169
+ * 在独立模式下运行组件
170
+ * @param input 输入参数,可以是提示文本或对话消息数组
171
+ * @returns 生成的文本或响应消息
172
+ */
173
+ async run(input) {
174
+ if (typeof input === "string") {
175
+ return this.generateCompletion(input);
176
+ } else {
177
+ return this.chatCompletion(input);
178
+ }
179
+ }
180
+ /**
181
+ * 在流水线中运行组件
182
+ * @param $i 输入端口
183
+ * @param $o 输出端口
184
+ */
185
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
186
+ _transform($i, $o) {
187
+ $i("prompt").receive(async (prompt) => {
188
+ try {
189
+ const completion = await this.generateCompletion(prompt);
190
+ $o("completion").send(completion);
191
+ } catch (error) {
192
+ console.error("Deepseek API \u8C03\u7528\u9519\u8BEF:", error);
193
+ $o("completion").send("API \u8C03\u7528\u9519\u8BEF");
194
+ }
195
+ });
196
+ $i("messages").receive(async (messages) => {
197
+ try {
198
+ const responseMessage = await this.chatCompletion(messages);
199
+ $o("message").send(responseMessage);
200
+ } catch (error) {
201
+ console.error("Deepseek API \u8C03\u7528\u9519\u8BEF:", error);
202
+ $o("message").send({
203
+ role: "assistant",
204
+ content: "API \u8C03\u7528\u9519\u8BEF"
205
+ });
206
+ }
207
+ });
208
+ }
209
+ };
210
+ var deepseek_default = Deepseek;
211
+ // Annotate the CommonJS export names for ESM import in node:
212
+ 0 && (module.exports = {
213
+ Deepseek
214
+ });
215
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/model-provider/index.ts","../../src/model-provider/deepseek/index.ts"],"sourcesContent":["export {\n default as Deepseek,\n type Message as DeepseekMessage,\n type ToolCall as DeepseekToolCall,\n type DeepseekConfig,\n type MessageRole as DeepseekMessageRole,\n} from './deepseek';\n","import { Component } from '@astack-tech/core';\nimport OpenAI from 'openai';\n\n/**\n * Deepseek 模型提供者配置\n */\nexport interface DeepseekConfig {\n /**\n * API 密钥\n */\n apiKey: string;\n\n /**\n * 使用的模型名称\n * 默认为 'deepseek-chat'\n */\n model?: string;\n\n /**\n * 自定义 API 基础 URL\n * 默认为 Deepseek 官方 API 地址\n */\n baseURL?: string;\n\n /**\n * 温度参数,控制输出的随机性\n */\n temperature?: number;\n\n /**\n * 最大生成的 token 数\n */\n maxTokens?: number;\n\n /**\n * 采样概率\n */\n topP?: number;\n\n /**\n * 系统提示消息\n */\n systemPrompt?: string;\n\n /**\n * 工具实例数组,直接传递工具实例\n * 每个工具应具有 name、description 和 parameters 属性\n */\n rawTools?: Array<{\n name: string;\n description: string;\n parameters?: Record<string, unknown>;\n }>;\n\n /**\n * API 格式的工具定义数组,与 rawTools 二选一\n * 使用 OpenAI 兼容的工具定义格式\n */\n tools?: unknown[];\n}\n\n/**\n * 消息角色类型\n */\nexport type MessageRole = 'system' | 'user' | 'assistant' | 'tool';\n\n/**\n * 工具调用\n */\nexport interface ToolCall {\n /**\n * 工具调用 ID\n */\n id?: string;\n\n /**\n * 工具名称\n */\n tool_name: string;\n\n /**\n * 工具调用参数\n */\n arguments: Record<string, unknown>;\n}\n\n/**\n * 对话消息类型\n */\nexport interface Message {\n /**\n * 消息角色\n */\n role: MessageRole;\n\n /**\n * 消息内容\n */\n content?: string;\n\n /**\n * 工具调用\n */\n tool_calls?: ToolCall[];\n\n /**\n * 工具调用 ID,用于工具响应消息\n */\n tool_call_id?: string;\n}\n\n/**\n * Deepseek 组件\n *\n * 使用 OpenAI 兼容接口调用 Deepseek 模型\n *\n * 输入:\n * - prompt: 文本提示\n * - messages: 对话消息数组\n *\n * 输出:\n * - completion: 生成的文本完成\n * - message: 生成的响应消息\n */\nclass Deepseek extends Component {\n // OpenAI 客户端实例\n private client: OpenAI;\n\n // 配置选项\n private model: string;\n private temperature: number;\n private maxTokens?: number;\n private topP?: number;\n private systemPrompt?: string;\n private tools?: unknown[];\n\n constructor(config: DeepseekConfig) {\n super({});\n\n // 配置客户端\n this.client = new OpenAI({\n apiKey: config.apiKey,\n baseURL: config.baseURL || 'https://api.deepseek.com/v1',\n });\n\n // 保存基本配置\n this.model = config.model || 'deepseek-chat';\n this.temperature = config.temperature ?? 0.7;\n this.maxTokens = config.maxTokens;\n this.topP = config.topP;\n this.systemPrompt = config.systemPrompt;\n\n // 处理工具配置,优先使用 rawTools\n if (config.rawTools && config.rawTools.length > 0) {\n // 将工具实例转换为 API 格式\n this.tools = config.rawTools.map(tool => ({\n type: 'function',\n function: {\n name: tool.name,\n description: tool.description,\n parameters: tool.parameters || {},\n },\n }));\n } else {\n // 使用直接提供的 API 格式工具\n this.tools = config.tools;\n }\n\n // 重命名端口\n Component.Port.I('prompt').attach(this);\n Component.Port.I('messages').attach(this);\n Component.Port.O('completion').attach(this);\n Component.Port.O('message').attach(this);\n }\n\n /**\n * 生成文本完成\n * @param prompt 提示文本\n * @returns 生成的文本\n */\n async generateCompletion(prompt: string): Promise<string> {\n const messages: Array<OpenAI.Chat.ChatCompletionMessageParam> = [];\n\n // 添加系统提示\n if (this.systemPrompt) {\n messages.push({\n role: 'system',\n content: this.systemPrompt,\n });\n }\n\n // 添加用户提示\n messages.push({\n role: 'user',\n content: prompt,\n });\n\n // 创建请求参数\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const requestParams: any = {\n model: this.model,\n messages,\n temperature: this.temperature,\n max_tokens: this.maxTokens,\n top_p: this.topP,\n };\n\n // 如果有工具定义,添加到请求中\n if (this.tools && this.tools.length > 0) {\n requestParams.tools = this.tools;\n }\n\n // 调用 API\n const response = await this.client.chat.completions.create(requestParams);\n\n // 处理工具调用结果\n if (\n response.choices[0].message.tool_calls &&\n response.choices[0].message.tool_calls.length > 0\n ) {\n return JSON.stringify(response.choices[0].message);\n }\n\n return response.choices[0].message.content || '';\n }\n\n /**\n * 处理对话消息\n * @param messages 对话消息数组\n * @param options 可选的调用选项,包含临时工具列表\n * @returns 生成的响应消息\n */\n async chatCompletion(\n messages: Message[],\n options?: { temporaryTools?: unknown[] }\n ): Promise<Message> {\n // 转换消息格式\n const formattedMessages: Array<OpenAI.Chat.ChatCompletionMessageParam> = [];\n\n // 添加系统提示\n if (this.systemPrompt) {\n formattedMessages.push({\n role: 'system',\n content: this.systemPrompt,\n });\n }\n\n // 添加用户提供的消息\n formattedMessages.push(\n ...messages.map(msg => {\n // 基本消息结构\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const formattedMsg: any = {\n role: msg.role,\n content: msg.content,\n };\n\n // 如果有工具调用 ID,添加到消息中\n if (msg.role === 'tool' && msg.tool_call_id) {\n formattedMsg.tool_call_id = msg.tool_call_id;\n }\n\n return formattedMsg;\n })\n );\n\n // 创建请求参数\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const requestParams: any = {\n model: this.model,\n messages: formattedMessages,\n temperature: this.temperature,\n max_tokens: this.maxTokens,\n top_p: this.topP,\n };\n\n // 决定使用哪些工具\n // 如果提供了临时工具,优先使用临时工具\n const toolsToUse = options?.temporaryTools || this.tools;\n\n // 如果有工具定义,添加到请求中\n if (toolsToUse && toolsToUse.length > 0) {\n // 检查工具格式并转换,确保符合 Deepseek API 要求\n const formattedTools = toolsToUse.map(tool => {\n // 使用类型断言来处理 unknown 类型\n type ToolType = {\n type?: string;\n name?: string;\n description?: string;\n parameters?: Record<string, unknown>;\n };\n\n const typedTool = tool as ToolType;\n\n // 如果工具已经是 API 格式,直接返回\n if (typedTool.type === 'function') {\n return tool;\n }\n\n // 如果是简单工具实例,转换为 API 格式\n return {\n type: 'function',\n function: {\n name: typedTool.name,\n description: typedTool.description,\n parameters: typedTool.parameters || {},\n },\n };\n });\n\n requestParams.tools = formattedTools;\n }\n\n // 调用 API\n const response = await this.client.chat.completions.create(requestParams);\n\n // 解析响应\n const responseMessage = response.choices[0].message;\n\n // 转换为内部消息格式\n const result: Message = {\n role: 'assistant',\n content: responseMessage.content || '',\n };\n\n // 如果有工具调用,添加到结果中\n if (responseMessage.tool_calls && responseMessage.tool_calls.length > 0) {\n result.tool_calls = responseMessage.tool_calls.map(toolCall => ({\n id: toolCall.id,\n tool_name: toolCall.function.name,\n arguments: JSON.parse(toolCall.function.arguments || '{}'),\n }));\n }\n\n return result;\n }\n\n /**\n * 在独立模式下运行组件\n * @param input 输入参数,可以是提示文本或对话消息数组\n * @returns 生成的文本或响应消息\n */\n async run(input: string | Message[]): Promise<string | Message> {\n if (typeof input === 'string') {\n return this.generateCompletion(input);\n } else {\n return this.chatCompletion(input);\n }\n }\n\n /**\n * 在流水线中运行组件\n * @param $i 输入端口\n * @param $o 输出端口\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n _transform($i: any, $o: any) {\n // 处理文本提示输入\n $i('prompt').receive(async (prompt: string) => {\n try {\n const completion = await this.generateCompletion(prompt);\n $o('completion').send(completion);\n } catch (error) {\n console.error('Deepseek API 调用错误:', error);\n $o('completion').send('API 调用错误');\n }\n });\n\n // 处理对话消息输入\n $i('messages').receive(async (messages: Message[]) => {\n try {\n const responseMessage = await this.chatCompletion(messages);\n $o('message').send(responseMessage);\n } catch (error) {\n console.error('Deepseek API 调用错误:', error);\n $o('message').send({\n role: 'assistant',\n content: 'API 调用错误',\n });\n }\n });\n }\n}\n\n// 默认导出组件\nexport default Deepseek;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,kBAA0B;AAC1B,oBAAmB;AA2HnB,IAAM,WAAN,cAAuB,sBAAU;AAAA,EAY/B,YAAY,QAAwB;AAClC,UAAM,CAAC,CAAC;AAGR,SAAK,SAAS,IAAI,cAAAA,QAAO;AAAA,MACvB,QAAQ,OAAO;AAAA,MACf,SAAS,OAAO,WAAW;AAAA,IAC7B,CAAC;AAGD,SAAK,QAAQ,OAAO,SAAS;AAC7B,SAAK,cAAc,OAAO,eAAe;AACzC,SAAK,YAAY,OAAO;AACxB,SAAK,OAAO,OAAO;AACnB,SAAK,eAAe,OAAO;AAG3B,QAAI,OAAO,YAAY,OAAO,SAAS,SAAS,GAAG;AAEjD,WAAK,QAAQ,OAAO,SAAS,IAAI,WAAS;AAAA,QACxC,MAAM;AAAA,QACN,UAAU;AAAA,UACR,MAAM,KAAK;AAAA,UACX,aAAa,KAAK;AAAA,UAClB,YAAY,KAAK,cAAc,CAAC;AAAA,QAClC;AAAA,MACF,EAAE;AAAA,IACJ,OAAO;AAEL,WAAK,QAAQ,OAAO;AAAA,IACtB;AAGA,0BAAU,KAAK,EAAE,QAAQ,EAAE,OAAO,IAAI;AACtC,0BAAU,KAAK,EAAE,UAAU,EAAE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O,KAAK,mBAAmB,KAAK;AAAA,IACtC,OAAO;AACL,aAAO,KAAK,eAAe,KAAK;AAAA,IAClC;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,WAAW,IAAS,IAAS;AAE3B,OAAG,QAAQ,EAAE,QAAQ,OAAO,WAAmB;AAC7C,UAAI;AACF,cAAM,aAAa,MAAM,KAAK,mBAAmB,MAAM;AACvD,WAAG,YAAY,EAAE,KAAK,UAAU;AAAA,MAClC,SAAS,OAAO;AACd,gBAAQ,MAAM,0CAAsB,KAAK;AACzC,WAAG,YAAY,EAAE,KAAK,8BAAU;AAAA,MAClC;AAAA,IACF,CAAC;AAGD,OAAG,UAAU,EAAE,QAAQ,OAAO,aAAwB;AACpD,UAAI;AACF,cAAM,kBAAkB,MAAM,KAAK,eAAe,QAAQ;AAC1D,WAAG,SAAS,EAAE,KAAK,eAAe;AAAA,MACpC,SAAS,OAAO;AACd,gBAAQ,MAAM,0CAAsB,KAAK;AACzC,WAAG,SAAS,EAAE,KAAK;AAAA,UACjB,MAAM;AAAA,UACN,SAAS;AAAA,QACX,CAAC;AAAA,MACH;AAAA,IACF,CAAC;AAAA,EACH;AACF;AAGA,IAAO,mBAAQ;","names":["OpenAI"]}
@@ -0,0 +1,152 @@
1
+ import { Component } from '@astack-tech/core';
2
+
3
+ /**
4
+ * Deepseek 模型提供者配置
5
+ */
6
+ interface DeepseekConfig {
7
+ /**
8
+ * API 密钥
9
+ */
10
+ apiKey: string;
11
+ /**
12
+ * 使用的模型名称
13
+ * 默认为 'deepseek-chat'
14
+ */
15
+ model?: string;
16
+ /**
17
+ * 自定义 API 基础 URL
18
+ * 默认为 Deepseek 官方 API 地址
19
+ */
20
+ baseURL?: string;
21
+ /**
22
+ * 温度参数,控制输出的随机性
23
+ */
24
+ temperature?: number;
25
+ /**
26
+ * 最大生成的 token 数
27
+ */
28
+ maxTokens?: number;
29
+ /**
30
+ * 采样概率
31
+ */
32
+ topP?: number;
33
+ /**
34
+ * 系统提示消息
35
+ */
36
+ systemPrompt?: string;
37
+ /**
38
+ * 工具实例数组,直接传递工具实例
39
+ * 每个工具应具有 name、description 和 parameters 属性
40
+ */
41
+ rawTools?: Array<{
42
+ name: string;
43
+ description: string;
44
+ parameters?: Record<string, unknown>;
45
+ }>;
46
+ /**
47
+ * API 格式的工具定义数组,与 rawTools 二选一
48
+ * 使用 OpenAI 兼容的工具定义格式
49
+ */
50
+ tools?: unknown[];
51
+ }
52
+ /**
53
+ * 消息角色类型
54
+ */
55
+ type MessageRole = 'system' | 'user' | 'assistant' | 'tool';
56
+ /**
57
+ * 工具调用
58
+ */
59
+ interface ToolCall {
60
+ /**
61
+ * 工具调用 ID
62
+ */
63
+ id?: string;
64
+ /**
65
+ * 工具名称
66
+ */
67
+ tool_name: string;
68
+ /**
69
+ * 工具调用参数
70
+ */
71
+ arguments: Record<string, unknown>;
72
+ }
73
+ /**
74
+ * 对话消息类型
75
+ */
76
+ interface Message {
77
+ /**
78
+ * 消息角色
79
+ */
80
+ role: MessageRole;
81
+ /**
82
+ * 消息内容
83
+ */
84
+ content?: string;
85
+ /**
86
+ * 工具调用
87
+ */
88
+ tool_calls?: ToolCall[];
89
+ /**
90
+ * 工具调用 ID,用于工具响应消息
91
+ */
92
+ tool_call_id?: string;
93
+ }
94
+ /**
95
+ * Deepseek 组件
96
+ *
97
+ * 使用 OpenAI 兼容接口调用 Deepseek 模型
98
+ *
99
+ * 输入:
100
+ * - prompt: 文本提示
101
+ * - messages: 对话消息数组
102
+ *
103
+ * 输出:
104
+ * - completion: 生成的文本完成
105
+ * - message: 生成的响应消息
106
+ */
107
+ declare class Deepseek extends Component {
108
+ private client;
109
+ private model;
110
+ private temperature;
111
+ private maxTokens?;
112
+ private topP?;
113
+ private systemPrompt?;
114
+ private tools?;
115
+ constructor(config: DeepseekConfig);
116
+ /**
117
+ * 生成文本完成
118
+ * @param prompt 提示文本
119
+ * @returns 生成的文本
120
+ */
121
+ generateCompletion(prompt: string): Promise<string>;
122
+ /**
123
+ * 处理对话消息
124
+ * @param messages 对话消息数组
125
+ * @param options 可选的调用选项,包含临时工具列表
126
+ * @returns 生成的响应消息
127
+ */
128
+ chatCompletion(messages: Message[], options?: {
129
+ temporaryTools?: unknown[];
130
+ }): Promise<Message>;
131
+ /**
132
+ * 在独立模式下运行组件
133
+ * @param input 输入参数,可以是提示文本或对话消息数组
134
+ * @returns 生成的文本或响应消息
135
+ */
136
+ run(input: string | Message[]): Promise<string | Message>;
137
+ /**
138
+ * 在流水线中运行组件
139
+ * @param $i 输入端口
140
+ * @param $o 输出端口
141
+ */
142
+ _transform($i: any, $o: any): void;
143
+ }
144
+
145
+ type index_Deepseek = Deepseek;
146
+ declare const index_Deepseek: typeof Deepseek;
147
+ type index_DeepseekConfig = DeepseekConfig;
148
+ declare namespace index {
149
+ export { index_Deepseek as Deepseek, type index_DeepseekConfig as DeepseekConfig, type Message as DeepseekMessage, type MessageRole as DeepseekMessageRole, type ToolCall as DeepseekToolCall };
150
+ }
151
+
152
+ export { Deepseek, type DeepseekConfig, type Message as DeepseekMessage, type MessageRole as DeepseekMessageRole, type ToolCall as DeepseekToolCall, index as i };
@@ -0,0 +1,152 @@
1
+ import { Component } from '@astack-tech/core';
2
+
3
+ /**
4
+ * Deepseek 模型提供者配置
5
+ */
6
+ interface DeepseekConfig {
7
+ /**
8
+ * API 密钥
9
+ */
10
+ apiKey: string;
11
+ /**
12
+ * 使用的模型名称
13
+ * 默认为 'deepseek-chat'
14
+ */
15
+ model?: string;
16
+ /**
17
+ * 自定义 API 基础 URL
18
+ * 默认为 Deepseek 官方 API 地址
19
+ */
20
+ baseURL?: string;
21
+ /**
22
+ * 温度参数,控制输出的随机性
23
+ */
24
+ temperature?: number;
25
+ /**
26
+ * 最大生成的 token 数
27
+ */
28
+ maxTokens?: number;
29
+ /**
30
+ * 采样概率
31
+ */
32
+ topP?: number;
33
+ /**
34
+ * 系统提示消息
35
+ */
36
+ systemPrompt?: string;
37
+ /**
38
+ * 工具实例数组,直接传递工具实例
39
+ * 每个工具应具有 name、description 和 parameters 属性
40
+ */
41
+ rawTools?: Array<{
42
+ name: string;
43
+ description: string;
44
+ parameters?: Record<string, unknown>;
45
+ }>;
46
+ /**
47
+ * API 格式的工具定义数组,与 rawTools 二选一
48
+ * 使用 OpenAI 兼容的工具定义格式
49
+ */
50
+ tools?: unknown[];
51
+ }
52
+ /**
53
+ * 消息角色类型
54
+ */
55
+ type MessageRole = 'system' | 'user' | 'assistant' | 'tool';
56
+ /**
57
+ * 工具调用
58
+ */
59
+ interface ToolCall {
60
+ /**
61
+ * 工具调用 ID
62
+ */
63
+ id?: string;
64
+ /**
65
+ * 工具名称
66
+ */
67
+ tool_name: string;
68
+ /**
69
+ * 工具调用参数
70
+ */
71
+ arguments: Record<string, unknown>;
72
+ }
73
+ /**
74
+ * 对话消息类型
75
+ */
76
+ interface Message {
77
+ /**
78
+ * 消息角色
79
+ */
80
+ role: MessageRole;
81
+ /**
82
+ * 消息内容
83
+ */
84
+ content?: string;
85
+ /**
86
+ * 工具调用
87
+ */
88
+ tool_calls?: ToolCall[];
89
+ /**
90
+ * 工具调用 ID,用于工具响应消息
91
+ */
92
+ tool_call_id?: string;
93
+ }
94
+ /**
95
+ * Deepseek 组件
96
+ *
97
+ * 使用 OpenAI 兼容接口调用 Deepseek 模型
98
+ *
99
+ * 输入:
100
+ * - prompt: 文本提示
101
+ * - messages: 对话消息数组
102
+ *
103
+ * 输出:
104
+ * - completion: 生成的文本完成
105
+ * - message: 生成的响应消息
106
+ */
107
+ declare class Deepseek extends Component {
108
+ private client;
109
+ private model;
110
+ private temperature;
111
+ private maxTokens?;
112
+ private topP?;
113
+ private systemPrompt?;
114
+ private tools?;
115
+ constructor(config: DeepseekConfig);
116
+ /**
117
+ * 生成文本完成
118
+ * @param prompt 提示文本
119
+ * @returns 生成的文本
120
+ */
121
+ generateCompletion(prompt: string): Promise<string>;
122
+ /**
123
+ * 处理对话消息
124
+ * @param messages 对话消息数组
125
+ * @param options 可选的调用选项,包含临时工具列表
126
+ * @returns 生成的响应消息
127
+ */
128
+ chatCompletion(messages: Message[], options?: {
129
+ temporaryTools?: unknown[];
130
+ }): Promise<Message>;
131
+ /**
132
+ * 在独立模式下运行组件
133
+ * @param input 输入参数,可以是提示文本或对话消息数组
134
+ * @returns 生成的文本或响应消息
135
+ */
136
+ run(input: string | Message[]): Promise<string | Message>;
137
+ /**
138
+ * 在流水线中运行组件
139
+ * @param $i 输入端口
140
+ * @param $o 输出端口
141
+ */
142
+ _transform($i: any, $o: any): void;
143
+ }
144
+
145
+ type index_Deepseek = Deepseek;
146
+ declare const index_Deepseek: typeof Deepseek;
147
+ type index_DeepseekConfig = DeepseekConfig;
148
+ declare namespace index {
149
+ export { index_Deepseek as Deepseek, type index_DeepseekConfig as DeepseekConfig, type Message as DeepseekMessage, type MessageRole as DeepseekMessageRole, type ToolCall as DeepseekToolCall };
150
+ }
151
+
152
+ export { Deepseek, type DeepseekConfig, type Message as DeepseekMessage, type MessageRole as DeepseekMessageRole, type ToolCall as DeepseekToolCall, index as i };