Skip to content

Commit df1baf8

Browse files
committed
deepseek init
1 parent ea6d76b commit df1baf8

File tree

5 files changed

+320
-3
lines changed

5 files changed

+320
-3
lines changed
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
import deepseek from "../../deepseek.app.mjs";
2+
import { axios } from "@pipedream/platform";
3+
4+
export default {
5+
key: "deepseek-create-chat-completion",
6+
name: "Create Chat Completion",
7+
description: "Creates a chat completion using the DeepSeek API. [See the documentation]()",
8+
version: "0.0.{{ts}}",
9+
type: "action",
10+
props: {
11+
deepseek,
12+
messages: {
13+
propDefinition: [
14+
"deepseek",
15+
"messages",
16+
],
17+
},
18+
model: {
19+
propDefinition: [
20+
"deepseek",
21+
"model",
22+
],
23+
},
24+
frequencyPenalty: {
25+
propDefinition: [
26+
"deepseek",
27+
"frequencyPenalty",
28+
],
29+
optional: true,
30+
},
31+
maxTokens: {
32+
propDefinition: [
33+
"deepseek",
34+
"maxTokens",
35+
],
36+
optional: true,
37+
},
38+
presencePenalty: {
39+
propDefinition: [
40+
"deepseek",
41+
"presencePenalty",
42+
],
43+
optional: true,
44+
},
45+
responseFormat: {
46+
propDefinition: [
47+
"deepseek",
48+
"responseFormat",
49+
],
50+
optional: true,
51+
},
52+
stop: {
53+
propDefinition: [
54+
"deepseek",
55+
"stop",
56+
],
57+
optional: true,
58+
},
59+
stream: {
60+
propDefinition: [
61+
"deepseek",
62+
"stream",
63+
],
64+
optional: true,
65+
},
66+
streamOptions: {
67+
propDefinition: [
68+
"deepseek",
69+
"streamOptions",
70+
],
71+
optional: true,
72+
},
73+
temperature: {
74+
propDefinition: [
75+
"deepseek",
76+
"temperature",
77+
],
78+
optional: true,
79+
},
80+
topP: {
81+
propDefinition: [
82+
"deepseek",
83+
"topP",
84+
],
85+
optional: true,
86+
},
87+
tools: {
88+
propDefinition: [
89+
"deepseek",
90+
"tools",
91+
],
92+
optional: true,
93+
},
94+
toolChoice: {
95+
propDefinition: [
96+
"deepseek",
97+
"toolChoice",
98+
],
99+
optional: true,
100+
},
101+
logprobs: {
102+
propDefinition: [
103+
"deepseek",
104+
"logprobs",
105+
],
106+
optional: true,
107+
},
108+
topLogprobs: {
109+
propDefinition: [
110+
"deepseek",
111+
"topLogprobs",
112+
],
113+
optional: true,
114+
},
115+
},
116+
async run({ $ }) {
117+
const response = await this.deepseek.createModelResponse();
118+
$.export("$summary", `Chat completion created: ${response.choices[0].message.content}`);
119+
return response;
120+
},
121+
};
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import deepseek from "../../deepseek.app.mjs";
2+
import { axios } from "@pipedream/platform";
3+
4+
export default {
5+
key: "deepseek-get-balance",
6+
name: "Get User Balance",
7+
description: "Retrieves the user's current balance. [See the documentation](https://api-docs.deepseek.com/api/get-user-balance)",
8+
version: "0.0.{{ts}}",
9+
type: "action",
10+
props: {
11+
deepseek: {
12+
type: "app",
13+
app: "deepseek",
14+
},
15+
},
16+
async run({ $ }) {
17+
const response = await this.deepseek.getUserBalance();
18+
$.export("$summary", "Successfully retrieved user balance");
19+
return response;
20+
},
21+
};
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import deepseek from "../../deepseek.app.mjs";
2+
import { axios } from "@pipedream/platform";
3+
4+
export default {
5+
key: "deepseek-list-models",
6+
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}}",
9+
type: "action",
10+
props: {
11+
deepseek: {
12+
type: "app",
13+
app: "deepseek",
14+
},
15+
},
16+
async run({ $ }) {
17+
const models = await this.deepseek.listModels();
18+
$.export("$summary", "Successfully listed models");
19+
return models;
20+
},
21+
};
Lines changed: 156 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,165 @@
1+
import { axios } from "@pipedream/platform";
2+
13
export default {
24
type: "app",
35
app: "deepseek",
4-
propDefinitions: {},
6+
version: "0.0.{{ts}}",
7+
propDefinitions: {
8+
messages: {
9+
type: "string[]",
10+
label: "Messages",
11+
description: "The messages for the chat conversation as JSON strings. Each message should be a JSON string like '{\"role\": \"user\", \"content\": \"Hello!\"}'.",
12+
},
13+
model: {
14+
type: "string",
15+
label: "Model",
16+
description: "The model to use for generating the chat completion.",
17+
async options() {
18+
const models = await this.listModels();
19+
return models.map((model) => ({
20+
label: `${model.id} (Owned by ${model.owner})`,
21+
value: model.id,
22+
}));
23+
},
24+
},
25+
frequencyPenalty: {
26+
type: "number",
27+
label: "Frequency Penalty",
28+
description: "Amount to penalize new tokens based on their frequency in the text so far.",
29+
optional: true,
30+
},
31+
maxTokens: {
32+
type: "integer",
33+
label: "Max Tokens",
34+
description: "The maximum number of tokens to generate in the completion.",
35+
optional: true,
36+
},
37+
presencePenalty: {
38+
type: "number",
39+
label: "Presence Penalty",
40+
description: "Amount to penalize new tokens based on their presence in the text so far.",
41+
optional: true,
42+
},
43+
responseFormat: {
44+
type: "string",
45+
label: "Response Format",
46+
description: "The format of the response.",
47+
optional: true,
48+
},
49+
stop: {
50+
type: "string[]",
51+
label: "Stop Sequences",
52+
description: "Sequences where the API will stop generating further tokens.",
53+
optional: true,
54+
},
55+
stream: {
56+
type: "boolean",
57+
label: "Stream",
58+
description: "Whether to stream the response.",
59+
optional: true,
60+
},
61+
streamOptions: {
62+
type: "string",
63+
label: "Stream Options",
64+
description: "Options for streaming the response.",
65+
optional: true,
66+
},
67+
temperature: {
68+
type: "number",
69+
label: "Temperature",
70+
description: "Sampling temperature, between 0 and 2.",
71+
optional: true,
72+
},
73+
topP: {
74+
type: "number",
75+
label: "Top P",
76+
description: "Nucleus sampling probability, between 0 and 1.",
77+
optional: true,
78+
},
79+
tools: {
80+
type: "string[]",
81+
label: "Tools",
82+
description: "Tools to be used in the generation.",
83+
optional: true,
84+
},
85+
toolChoice: {
86+
type: "string",
87+
label: "Tool Choice",
88+
description: "Choice of tool.",
89+
optional: true,
90+
},
91+
logprobs: {
92+
type: "integer",
93+
label: "Log Probs",
94+
description: "Number of top log probabilities to return.",
95+
optional: true,
96+
},
97+
topLogprobs: {
98+
type: "integer",
99+
label: "Top Log Probabilities",
100+
description: "Return the top log probabilities.",
101+
optional: true,
102+
},
103+
},
5104
methods: {
6-
// this.$auth contains connected account data
7105
authKeys() {
8106
console.log(Object.keys(this.$auth));
9107
},
108+
_baseUrl() {
109+
return "https://api.deepseek.com";
110+
},
111+
async _makeRequest(opts = {}) {
112+
const {
113+
$, method = "GET", path = "/", headers, ...otherOpts
114+
} = opts;
115+
return axios($, {
116+
method,
117+
url: this._baseUrl() + path,
118+
headers: {
119+
...headers,
120+
"Authorization": `Bearer ${this.$auth.api_key}`,
121+
"Accept": "application/json",
122+
"Content-Type": "application/json",
123+
},
124+
...otherOpts,
125+
});
126+
},
127+
async createModelResponse() {
128+
const data = {
129+
messages: this.messages.map((message) => JSON.parse(message)),
130+
model: this.model,
131+
};
132+
if (this.frequencyPenalty !== undefined) data.frequency_penalty = this.frequencyPenalty;
133+
if (this.maxTokens !== undefined) data.max_tokens = this.maxTokens;
134+
if (this.presencePenalty !== undefined) data.presence_penalty = this.presencePenalty;
135+
if (this.responseFormat !== undefined) data.response_format = this.responseFormat;
136+
if (this.stop !== undefined) data.stop = this.stop;
137+
if (this.stream !== undefined) data.stream = this.stream;
138+
if (this.streamOptions !== undefined) data.stream_options = this.streamOptions;
139+
if (this.temperature !== undefined) data.temperature = this.temperature;
140+
if (this.topP !== undefined) data.top_p = this.topP;
141+
if (this.tools !== undefined) data.tools = this.tools;
142+
if (this.toolChoice !== undefined) data.tool_choice = this.toolChoice;
143+
if (this.logprobs !== undefined) data.logprobs = this.logprobs;
144+
if (this.topLogprobs !== undefined) data.top_logprobs = this.topLogprobs;
145+
146+
return this._makeRequest({
147+
method: "POST",
148+
path: "/chat/completions",
149+
data,
150+
});
151+
},
152+
async getUserBalance() {
153+
return this._makeRequest({
154+
method: "GET",
155+
path: "/user/balance",
156+
});
157+
},
158+
async listModels() {
159+
return this._makeRequest({
160+
method: "GET",
161+
path: "/models",
162+
});
163+
},
10164
},
11165
};

components/deepseek/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@
1212
"publishConfig": {
1313
"access": "public"
1414
}
15-
}
15+
}

0 commit comments

Comments
 (0)