Skip to content

Commit cedfe17

Browse files
committed
[Components] deepseek #15444
Actions - Create Chat Completion - Get Balance - List Models
1 parent df1baf8 commit cedfe17

File tree

7 files changed

+147
-220
lines changed

7 files changed

+147
-220
lines changed
Lines changed: 84 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,121 +1,136 @@
1+
import { RESPONSE_FORMAT_TYPE_OPTIONS } from "../../common/constants.mjs";
2+
import { parseObject } from "../../common/util.mjs";
13
import deepseek from "../../deepseek.app.mjs";
2-
import { axios } from "@pipedream/platform";
34

45
export default {
56
key: "deepseek-create-chat-completion",
67
name: "Create Chat Completion",
7-
description: "Creates a chat completion using the DeepSeek API. [See the documentation]()",
8-
version: "0.0.{{ts}}",
8+
description: "Creates a chat completion using the DeepSeek API. [See the documentation](https://api-docs.deepseek.com/api/create-chat-completion)",
9+
version: "0.0.1",
910
type: "action",
1011
props: {
1112
deepseek,
1213
messages: {
13-
propDefinition: [
14-
"deepseek",
15-
"messages",
16-
],
17-
},
18-
model: {
19-
propDefinition: [
20-
"deepseek",
21-
"model",
22-
],
14+
type: "string[]",
15+
label: "Messages",
16+
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.",
2317
},
2418
frequencyPenalty: {
25-
propDefinition: [
26-
"deepseek",
27-
"frequencyPenalty",
28-
],
19+
type: "string",
20+
label: "Frequency Penalty",
21+
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.",
2922
optional: true,
3023
},
3124
maxTokens: {
32-
propDefinition: [
33-
"deepseek",
34-
"maxTokens",
35-
],
25+
type: "integer",
26+
label: "Max Tokens",
27+
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.",
3628
optional: true,
3729
},
3830
presencePenalty: {
39-
propDefinition: [
40-
"deepseek",
41-
"presencePenalty",
42-
],
31+
type: "string",
32+
label: "Presence Penalty",
33+
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.",
4334
optional: true,
4435
},
45-
responseFormat: {
46-
propDefinition: [
47-
"deepseek",
48-
"responseFormat",
49-
],
36+
responseFormatType: {
37+
type: "string",
38+
label: "Response Format Type",
39+
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.",
40+
options: RESPONSE_FORMAT_TYPE_OPTIONS,
5041
optional: true,
5142
},
5243
stop: {
53-
propDefinition: [
54-
"deepseek",
55-
"stop",
56-
],
44+
type: "string[]",
45+
label: "Stop Sequences",
46+
description: "Up to 16 sequences where the API will stop generating further tokens.",
5747
optional: true,
5848
},
5949
stream: {
60-
propDefinition: [
61-
"deepseek",
62-
"stream",
63-
],
50+
type: "boolean",
51+
label: "Stream",
52+
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.",
6453
optional: true,
54+
reloadProps: true,
6555
},
66-
streamOptions: {
67-
propDefinition: [
68-
"deepseek",
69-
"streamOptions",
70-
],
56+
streamIncludeUsage: {
57+
type: "string",
58+
label: "Stream Include Usage",
59+
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.",
7160
optional: true,
61+
hidden: true,
7262
},
7363
temperature: {
74-
propDefinition: [
75-
"deepseek",
76-
"temperature",
77-
],
64+
type: "string",
65+
label: "Temperature",
66+
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.",
7867
optional: true,
7968
},
8069
topP: {
81-
propDefinition: [
82-
"deepseek",
83-
"topP",
84-
],
70+
type: "string",
71+
label: "Top P",
72+
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.",
8573
optional: true,
8674
},
8775
tools: {
88-
propDefinition: [
89-
"deepseek",
90-
"tools",
91-
],
76+
type: "string[]",
77+
label: "Tools",
78+
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.",
9279
optional: true,
9380
},
9481
toolChoice: {
95-
propDefinition: [
96-
"deepseek",
97-
"toolChoice",
98-
],
82+
type: "string",
83+
label: "Tool Choice",
84+
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.",
9985
optional: true,
10086
},
10187
logprobs: {
102-
propDefinition: [
103-
"deepseek",
104-
"logprobs",
105-
],
88+
type: "boolean",
89+
label: "Log Probs",
90+
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`.",
10691
optional: true,
10792
},
10893
topLogprobs: {
109-
propDefinition: [
110-
"deepseek",
111-
"topLogprobs",
112-
],
94+
type: "string",
95+
label: "Top Log Probabilities",
96+
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.",
11397
optional: true,
11498
},
11599
},
100+
async additionalProps(props) {
101+
props.streamIncludeUsage.hidden = !this.stream;
102+
return {};
103+
},
116104
async run({ $ }) {
117-
const response = await this.deepseek.createModelResponse();
118-
$.export("$summary", `Chat completion created: ${response.choices[0].message.content}`);
105+
const response = await this.deepseek.createModelResponse({
106+
$,
107+
data: {
108+
messages: parseObject(this.messages),
109+
model: "deepseek-chat",
110+
frequency_penalty: this.frequencyPenalty && parseInt(this.frequencyPenalty),
111+
max_tokens: this.maxTokens,
112+
presence_penalty: this.presencePenalty && parseInt(this.presencePenalty),
113+
response_format: this.responseFormatType
114+
? {
115+
type: this.responseFormatType,
116+
}
117+
: null,
118+
stop: parseObject(this.stop),
119+
stream: this.stream,
120+
stream_options: this.stram
121+
? {
122+
include_usage: this.streamIncludeUsage,
123+
}
124+
: null,
125+
temperature: this.temperature && parseInt(this.temperature),
126+
top_p: this.topP && parseInt(this.topP),
127+
tools: parseObject(this.tools),
128+
tool_choice: parseObject(this.toolChoice),
129+
logprobs: this.logprobs,
130+
top_logprobs: this.topLogprobs && parseInt(this.topLogprobs),
131+
},
132+
});
133+
$.export("$summary", "Chat completion created");
119134
return response;
120135
},
121136
};

components/deepseek/actions/get-balance/get-balance.mjs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
11
import deepseek from "../../deepseek.app.mjs";
2-
import { axios } from "@pipedream/platform";
32

43
export default {
54
key: "deepseek-get-balance",
65
name: "Get User Balance",
76
description: "Retrieves the user's current balance. [See the documentation](https://api-docs.deepseek.com/api/get-user-balance)",
8-
version: "0.0.{{ts}}",
7+
version: "0.0.1",
98
type: "action",
109
props: {
11-
deepseek: {
12-
type: "app",
13-
app: "deepseek",
14-
},
10+
deepseek,
1511
},
1612
async run({ $ }) {
17-
const response = await this.deepseek.getUserBalance();
13+
const response = await this.deepseek.getUserBalance({
14+
$,
15+
});
1816
$.export("$summary", "Successfully retrieved user balance");
1917
return response;
2018
},

components/deepseek/actions/list-models/list-models.mjs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
11
import deepseek from "../../deepseek.app.mjs";
2-
import { axios } from "@pipedream/platform";
32

43
export default {
54
key: "deepseek-list-models",
65
name: "List Models",
7-
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/)",
8-
version: "0.0.{{ts}}",
6+
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)",
7+
version: "0.0.1",
98
type: "action",
109
props: {
11-
deepseek: {
12-
type: "app",
13-
app: "deepseek",
14-
},
10+
deepseek,
1511
},
1612
async run({ $ }) {
17-
const models = await this.deepseek.listModels();
13+
const models = await this.deepseek.listModels({
14+
$,
15+
});
1816
$.export("$summary", "Successfully listed models");
1917
return models;
2018
},
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export const RESPONSE_FORMAT_TYPE_OPTIONS = [
2+
{
3+
label: "Text",
4+
value: "text",
5+
},
6+
{
7+
label: "JSON Object",
8+
value: "json_object",
9+
},
10+
];
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
export const parseObject = (obj) => {
2+
if (!obj) return undefined;
3+
4+
if (Array.isArray(obj)) {
5+
return obj.map((item) => {
6+
if (typeof item === "string") {
7+
try {
8+
return JSON.parse(item);
9+
} catch (e) {
10+
return item;
11+
}
12+
}
13+
return item;
14+
});
15+
}
16+
if (typeof obj === "string") {
17+
try {
18+
return JSON.parse(obj);
19+
} catch (e) {
20+
return obj;
21+
}
22+
}
23+
return obj;
24+
};

0 commit comments

Comments
 (0)