diff --git a/components/deepseek/actions/create-chat-completion/create-chat-completion.mjs b/components/deepseek/actions/create-chat-completion/create-chat-completion.mjs new file mode 100644 index 0000000000000..8cdbd0f1b8981 --- /dev/null +++ b/components/deepseek/actions/create-chat-completion/create-chat-completion.mjs @@ -0,0 +1,136 @@ +import { RESPONSE_FORMAT_TYPE_OPTIONS } from "../../common/constants.mjs"; +import { parseObject } from "../../common/util.mjs"; +import deepseek from "../../deepseek.app.mjs"; + +export default { + key: "deepseek-create-chat-completion", + name: "Create Chat Completion", + description: "Creates a chat completion using the DeepSeek API. [See the documentation](https://api-docs.deepseek.com/api/create-chat-completion)", + version: "0.0.1", + type: "action", + props: { + deepseek, + messages: { + type: "string[]", + label: "Messages", + description: "The messages for the chat conversation as JSON strings. Each message should be a JSON string like '{\"role\": \"user\", \"content\": \"Hello!\"}'. [See the documentation](https://api-docs.deepseek.com/api/create-chat-completion) for further details.", + }, + frequencyPenalty: { + type: "string", + label: "Frequency Penalty", + description: "Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim.", + optional: true, + }, + maxTokens: { + type: "integer", + label: "Max Tokens", + description: "Integer between 1 and 8192. The maximum number of tokens that can be generated in the chat completion. The total length of input tokens and generated tokens is limited by the model's context length. If `max_tokens` is not specified, the default value 4096 is used.", + optional: true, + }, + presencePenalty: { + type: "string", + label: "Presence Penalty", + description: "Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the text so far, increasing the model's likelihood to talk about new topics.", + optional: true, + }, + responseFormatType: { + type: "string", + label: "Response Format Type", + description: "The format that the model must output. Setting to JSON Object enables JSON Output, which guarantees the message the model generates is valid JSON.", + options: RESPONSE_FORMAT_TYPE_OPTIONS, + optional: true, + }, + stop: { + type: "string[]", + label: "Stop Sequences", + description: "Up to 16 sequences where the API will stop generating further tokens.", + optional: true, + }, + stream: { + type: "boolean", + label: "Stream", + description: "If set, partial message deltas will be sent. Tokens will be sent as data-only server-sent events (SSE) as they become available, with the stream terminated by a `data: [DONE]` message.", + optional: true, + reloadProps: true, + }, + streamIncludeUsage: { + type: "string", + label: "Stream Include Usage", + description: "If set, an additional chunk will be streamed before the `data: [DONE]` message. The `usage` field on this chunk shows the token usage statistics for the entire request, and the `choices` field will always be an empty array. All other chunks will also include a `usage` field, but with a null value.", + optional: true, + hidden: true, + }, + temperature: { + type: "string", + label: "Temperature", + description: "What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. We generally recommend altering this or Top P but not both.", + optional: true, + }, + topP: { + type: "string", + label: "Top P", + description: "An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered. We generally recommend altering this or Temperature but not both.", + optional: true, + }, + tools: { + type: "string[]", + label: "Tools", + description: "A list of tools the model may call. Currently, only functions are supported as a tool. Use this to provide a list of functions the model may generate JSON inputs for. A max of 128 functions are supported.", + optional: true, + }, + toolChoice: { + type: "string", + label: "Tool Choice", + description: "Controls which (if any) tool is called by the model. [See the documentation](https://api-docs.deepseek.com/api/create-chat-completion) for further details.", + optional: true, + }, + logprobs: { + type: "boolean", + label: "Log Probs", + description: "Whether to return log probabilities of the output tokens or not. If true, returns the log probabilities of each output token returned in the `content` of `message`.", + optional: true, + }, + topLogprobs: { + type: "string", + label: "Top Log Probabilities", + description: "An integer between 0 and 20 specifying the number of most likely tokens to return at each token position, each with an associated log probability. logprobs must be set to true if this parameter is used.", + optional: true, + }, + }, + async additionalProps(props) { + props.streamIncludeUsage.hidden = !this.stream; + return {}; + }, + async run({ $ }) { + const response = await this.deepseek.createModelResponse({ + $, + data: { + messages: parseObject(this.messages), + model: "deepseek-chat", + frequency_penalty: this.frequencyPenalty && parseInt(this.frequencyPenalty), + max_tokens: this.maxTokens, + presence_penalty: this.presencePenalty && parseInt(this.presencePenalty), + response_format: this.responseFormatType + ? { + type: this.responseFormatType, + } + : null, + stop: parseObject(this.stop), + stream: this.stream, + stream_options: this.stream + ? { + include_usage: this.streamIncludeUsage, + } + : null, + temperature: this.temperature && parseInt(this.temperature), + top_p: this.topP && parseInt(this.topP), + tools: parseObject(this.tools), + tool_choice: parseObject(this.toolChoice), + logprobs: this.logprobs, + top_logprobs: this.topLogprobs && parseInt(this.topLogprobs), + }, + }); + $.export("$summary", "Chat completion created"); + return response; + }, +}; diff --git a/components/deepseek/actions/get-balance/get-balance.mjs b/components/deepseek/actions/get-balance/get-balance.mjs new file mode 100644 index 0000000000000..c621fc32bfed9 --- /dev/null +++ b/components/deepseek/actions/get-balance/get-balance.mjs @@ -0,0 +1,19 @@ +import deepseek from "../../deepseek.app.mjs"; + +export default { + key: "deepseek-get-balance", + name: "Get User Balance", + description: "Retrieves the user's current balance. [See the documentation](https://api-docs.deepseek.com/api/get-user-balance)", + version: "0.0.1", + type: "action", + props: { + deepseek, + }, + async run({ $ }) { + const response = await this.deepseek.getUserBalance({ + $, + }); + $.export("$summary", "Successfully retrieved user balance"); + return response; + }, +}; diff --git a/components/deepseek/actions/list-models/list-models.mjs b/components/deepseek/actions/list-models/list-models.mjs new file mode 100644 index 0000000000000..b867caba2e520 --- /dev/null +++ b/components/deepseek/actions/list-models/list-models.mjs @@ -0,0 +1,19 @@ +import deepseek from "../../deepseek.app.mjs"; + +export default { + key: "deepseek-list-models", + name: "List Models", + description: "Lists the currently available models, and provides basic information about each one such as the owner and availability. [See the documentation](https://api-docs.deepseek.com/api/list-models)", + version: "0.0.1", + type: "action", + props: { + deepseek, + }, + async run({ $ }) { + const models = await this.deepseek.listModels({ + $, + }); + $.export("$summary", "Successfully listed models"); + return models; + }, +}; diff --git a/components/deepseek/common/constants.mjs b/components/deepseek/common/constants.mjs new file mode 100644 index 0000000000000..f5de38062a1d9 --- /dev/null +++ b/components/deepseek/common/constants.mjs @@ -0,0 +1,10 @@ +export const RESPONSE_FORMAT_TYPE_OPTIONS = [ + { + label: "Text", + value: "text", + }, + { + label: "JSON Object", + value: "json_object", + }, +]; diff --git a/components/deepseek/common/util.mjs b/components/deepseek/common/util.mjs new file mode 100644 index 0000000000000..dcc9cc61f6f41 --- /dev/null +++ b/components/deepseek/common/util.mjs @@ -0,0 +1,24 @@ +export const parseObject = (obj) => { + if (!obj) return undefined; + + if (Array.isArray(obj)) { + return obj.map((item) => { + if (typeof item === "string") { + try { + return JSON.parse(item); + } catch (e) { + return item; + } + } + return item; + }); + } + if (typeof obj === "string") { + try { + return JSON.parse(obj); + } catch (e) { + return obj; + } + } + return obj; +}; diff --git a/components/deepseek/deepseek.app.mjs b/components/deepseek/deepseek.app.mjs index 1e3cfe2aae7a5..7ecf9ef719a83 100644 --- a/components/deepseek/deepseek.app.mjs +++ b/components/deepseek/deepseek.app.mjs @@ -1,11 +1,44 @@ +import { axios } from "@pipedream/platform"; + export default { type: "app", app: "deepseek", - propDefinitions: {}, methods: { - // this.$auth contains connected account data - authKeys() { - console.log(Object.keys(this.$auth)); + _baseUrl() { + return "https://api.deepseek.com"; + }, + _headers() { + return { + "Authorization": `Bearer ${this.$auth.api_key}`, + }; + }, + _makeRequest({ + $ = this, path, ...opts + }) { + return axios($, { + url: this._baseUrl() + path, + headers: this._headers(), + ...opts, + }); + }, + createModelResponse(opts = {}) { + return this._makeRequest({ + method: "POST", + path: "/chat/completions", + ...opts, + }); + }, + getUserBalance() { + return this._makeRequest({ + method: "GET", + path: "/user/balance", + }); + }, + listModels() { + return this._makeRequest({ + method: "GET", + path: "/models", + }); }, }, }; diff --git a/components/deepseek/package.json b/components/deepseek/package.json index 0763e10c2c8ea..f520a8520fe49 100644 --- a/components/deepseek/package.json +++ b/components/deepseek/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/deepseek", - "version": "0.0.1", + "version": "0.1.0", "description": "Pipedream DeepSeek Components", "main": "deepseek.app.mjs", "keywords": [ @@ -11,5 +11,8 @@ "author": "Pipedream (https://pipedream.com/)", "publishConfig": { "access": "public" + }, + "dependencies": { + "@pipedream/platform": "^3.0.3" } -} \ No newline at end of file +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index be12ad6b860ee..f46eafa0cf617 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -2615,7 +2615,11 @@ importers: components/deepl: {} - components/deepseek: {} + components/deepseek: + dependencies: + '@pipedream/platform': + specifier: ^3.0.3 + version: 3.0.3 components/defastra: dependencies: @@ -5694,8 +5698,7 @@ importers: specifier: ^3.0.3 version: 3.0.3 - components/klipy: - specifiers: {} + components/klipy: {} components/knack: dependencies: