|
| 1 | +import { axios } from "@pipedream/platform"; |
| 2 | + |
1 | 3 | export default { |
2 | 4 | type: "app", |
3 | 5 | 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 | + }, |
5 | 104 | methods: { |
6 | | - // this.$auth contains connected account data |
7 | 105 | authKeys() { |
8 | 106 | console.log(Object.keys(this.$auth)); |
9 | 107 | }, |
| 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 | + }, |
10 | 164 | }, |
11 | 165 | }; |
0 commit comments