Skip to content

Commit 7d4a370

Browse files
authored
Merging pull request #15492
* Added actions * Done requests changes * Added actions * Done requests changes
1 parent 2cd3173 commit 7d4a370

File tree

6 files changed

+121
-20
lines changed

6 files changed

+121
-20
lines changed

components/writer/.gitignore

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import app from "../../writer.app.mjs";
2+
3+
export default {
4+
key: "writer-send-prompt",
5+
name: "Send Prompt",
6+
description: "Generate a chat completion based on the provided messages. [See the documentation](https://dev.writer.com/api-guides/api-reference/completion-api/chat-completion)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
messages: {
12+
propDefinition: [
13+
app,
14+
"messages",
15+
],
16+
},
17+
logprobs: {
18+
propDefinition: [
19+
app,
20+
"logprobs",
21+
],
22+
},
23+
maxTokens: {
24+
propDefinition: [
25+
app,
26+
"maxTokens",
27+
],
28+
},
29+
number: {
30+
propDefinition: [
31+
app,
32+
"number",
33+
],
34+
},
35+
},
36+
async run({ $ }) {
37+
const response = await this.app.sendPrompt({
38+
$,
39+
data: {
40+
model: "palmyra-x-004",
41+
messages: JSON.parse(this.messages),
42+
logprobs: this.logprobs,
43+
max_tokens: this.maxTokens,
44+
n: this.number,
45+
},
46+
});
47+
$.export("$summary", "Successfully generated chat completion");
48+
return response;
49+
},
50+
};

components/writer/app/writer.app.ts

Lines changed: 0 additions & 13 deletions
This file was deleted.

components/writer/package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
{
22
"name": "@pipedream/writer",
3-
"version": "0.0.2",
3+
"version": "0.1.0",
44
"description": "Pipedream Writer Components",
5-
"main": "dist/app/writer.app.mjs",
5+
"main": "writer.app.mjs",
66
"keywords": [
77
"pipedream",
88
"writer"
99
],
10-
"files": ["dist"],
1110
"homepage": "https://pipedream.com/apps/writer",
1211
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
1312
"publishConfig": {
1413
"access": "public"
14+
},
15+
"dependencies": {
16+
"@pipedream/platform": "^3.0.3"
1517
}
1618
}

components/writer/writer.app.mjs

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import { axios } from "@pipedream/platform";
2+
3+
export default {
4+
type: "app",
5+
app: "writer",
6+
propDefinitions: {
7+
messages: {
8+
type: "string",
9+
label: "Messages",
10+
description: "Array of messages to be used for generating completion. Use the format: `[{ \"role\": \"user\", \"content\": \"Hello\" }]`. The possible roles are `user`, `asssistant`, 'system' and 'tool'",
11+
},
12+
logprobs: {
13+
type: "boolean",
14+
label: "Log Probabilities",
15+
description: "Specifies whether to return log probabilities of the output tokens",
16+
optional: true,
17+
},
18+
maxTokens: {
19+
type: "integer",
20+
label: "Max Tokens",
21+
description: "Defines the maximum number of tokens that the model can generate in the response",
22+
optional: true,
23+
},
24+
number: {
25+
type: "integer",
26+
label: "Number",
27+
description: "Specifies the number of completions to generate",
28+
optional: true,
29+
},
30+
},
31+
methods: {
32+
_baseUrl() {
33+
return "https://api.writer.com/v1";
34+
},
35+
async _makeRequest(opts = {}) {
36+
const {
37+
$ = this,
38+
path,
39+
headers,
40+
...otherOpts
41+
} = opts;
42+
return axios($, {
43+
...otherOpts,
44+
url: this._baseUrl() + path,
45+
headers: {
46+
"Authorization": `Bearer ${this.$auth.api_key}`,
47+
"Content-Type": "application/json",
48+
...headers,
49+
},
50+
});
51+
},
52+
53+
async sendPrompt(args = {}) {
54+
return this._makeRequest({
55+
path: "/chat",
56+
method: "post",
57+
...args,
58+
});
59+
},
60+
},
61+
};

pnpm-lock.yaml

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)