From 442e17153fca0ce9a115a1a5150a282f5fb25421 Mon Sep 17 00:00:00 2001 From: Luan Cazarine Date: Mon, 4 Nov 2024 11:15:20 -0300 Subject: [PATCH 1/3] tldr init --- .../actions/summarize-text/summarize-text.mjs | 41 ++++++++++++++ components/tldr/package.json | 2 +- components/tldr/tldr.app.mjs | 55 ++++++++++++++++++- 3 files changed, 94 insertions(+), 4 deletions(-) create mode 100644 components/tldr/actions/summarize-text/summarize-text.mjs diff --git a/components/tldr/actions/summarize-text/summarize-text.mjs b/components/tldr/actions/summarize-text/summarize-text.mjs new file mode 100644 index 0000000000000..759fb63776ca6 --- /dev/null +++ b/components/tldr/actions/summarize-text/summarize-text.mjs @@ -0,0 +1,41 @@ +import tldr from "../../tldr.app.mjs"; + +export default { + key: "tldr-summarize-text", + name: "Summarize Text", + description: "Reads in a piece of text and distills the main points. [See the documentation](https://runtldr.com/documentation)", + version: "0.0.{{ts}}", + type: "action", + props: { + tldr, + inputText: { + propDefinition: [ + tldr, + "inputText", + ], + }, + responseStyle: { + propDefinition: [ + tldr, + "responseStyle", + ], + }, + responseLength: { + propDefinition: [ + tldr, + "responseLength", + ], + }, + }, + async run({ $ }) { + const response = await this.tldr.summarize({ + inputText: this.inputText, + responseLength: this.responseLength || undefined, + responseStyle: this.responseStyle || undefined, + }); + + const summary = response.output.summary; + $.export("$summary", `Successfully summarized the text with the following summary: "${summary}"`); + return response.output; + }, +}; diff --git a/components/tldr/package.json b/components/tldr/package.json index 33f19a0b0e983..04c4015ce4b3c 100644 --- a/components/tldr/package.json +++ b/components/tldr/package.json @@ -12,4 +12,4 @@ "publishConfig": { "access": "public" } -} \ No newline at end of file +} diff --git a/components/tldr/tldr.app.mjs b/components/tldr/tldr.app.mjs index b093bb357fe12..ec7b288b34028 100644 --- a/components/tldr/tldr.app.mjs +++ b/components/tldr/tldr.app.mjs @@ -1,11 +1,60 @@ +import { axios } from "@pipedream/platform"; + export default { type: "app", app: "tldr", - propDefinitions: {}, + propDefinitions: { + inputText: { + type: "string", + label: "Text to Summarize", + description: "The text that needs to be summarized.", + }, + responseStyle: { + type: "string", + label: "Response Style", + description: "Style of the response (e.g., Funny, Serious).", + optional: true, + }, + responseLength: { + type: "integer", + label: "Response Length", + description: "Length of the response summary.", + optional: true, + }, + }, methods: { - // this.$auth contains connected account data authKeys() { console.log(Object.keys(this.$auth)); }, + _baseUrl() { + return "https://runtldr.com"; + }, + async _makeRequest(opts = {}) { + const { + $ = this, method = "POST", path = "/", headers, ...otherOpts + } = opts; + return axios($, { + ...otherOpts, + method, + url: this._baseUrl() + path, + headers: { + ...headers, + "Authorization": `Bearer ${this.$auth.api_key}`, + "Content-Type": "application/json", + }, + }); + }, + async summarize({ + inputText, responseLength, responseStyle, + }) { + return this._makeRequest({ + path: "/summarize", + data: { + inputText, + responseLength, + responseStyle, + }, + }); + }, }, -}; \ No newline at end of file +}; From 865a57157797769e6a3e6987e6fa84b76170bfe0 Mon Sep 17 00:00:00 2001 From: Luan Cazarine Date: Mon, 4 Nov 2024 11:28:47 -0300 Subject: [PATCH 2/3] [Components] tldr #14496 Actions - Summarize Text --- .../actions/summarize-text/summarize-text.mjs | 37 ++++++------- components/tldr/package.json | 5 +- components/tldr/tldr.app.mjs | 55 +++++-------------- 3 files changed, 36 insertions(+), 61 deletions(-) diff --git a/components/tldr/actions/summarize-text/summarize-text.mjs b/components/tldr/actions/summarize-text/summarize-text.mjs index 759fb63776ca6..618b2ea3c80d2 100644 --- a/components/tldr/actions/summarize-text/summarize-text.mjs +++ b/components/tldr/actions/summarize-text/summarize-text.mjs @@ -4,38 +4,37 @@ export default { key: "tldr-summarize-text", name: "Summarize Text", description: "Reads in a piece of text and distills the main points. [See the documentation](https://runtldr.com/documentation)", - version: "0.0.{{ts}}", + version: "0.0.1", type: "action", props: { tldr, inputText: { - propDefinition: [ - tldr, - "inputText", - ], + type: "string", + label: "Text to Summarize", + description: "The text that needs to be summarized.", }, responseStyle: { - propDefinition: [ - tldr, - "responseStyle", - ], + type: "string", + label: "Response Style", + description: "Style of the response (e.g., Funny, Serious).", }, responseLength: { - propDefinition: [ - tldr, - "responseLength", - ], + type: "integer", + label: "Response Length", + description: "Length of the response summary.", }, }, async run({ $ }) { const response = await this.tldr.summarize({ - inputText: this.inputText, - responseLength: this.responseLength || undefined, - responseStyle: this.responseStyle || undefined, + $, + data: { + inputText: this.inputText, + responseLength: this.responseLength, + responseStyle: this.responseStyle, + }, }); - const summary = response.output.summary; - $.export("$summary", `Successfully summarized the text with the following summary: "${summary}"`); - return response.output; + $.export("$summary", `Successfully summarized the text with the following input: "${this.inputText}"`); + return response; }, }; diff --git a/components/tldr/package.json b/components/tldr/package.json index 04c4015ce4b3c..a8353a1194f10 100644 --- a/components/tldr/package.json +++ b/components/tldr/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/tldr", - "version": "0.0.1", + "version": "0.1.0", "description": "Pipedream TLDR Components", "main": "tldr.app.mjs", "keywords": [ @@ -11,5 +11,8 @@ "author": "Pipedream (https://pipedream.com/)", "publishConfig": { "access": "public" + }, + "dependencies": { + "@pipedream/platform": "^3.0.3" } } diff --git a/components/tldr/tldr.app.mjs b/components/tldr/tldr.app.mjs index ec7b288b34028..9cec238fcb7cf 100644 --- a/components/tldr/tldr.app.mjs +++ b/components/tldr/tldr.app.mjs @@ -3,57 +3,30 @@ import { axios } from "@pipedream/platform"; export default { type: "app", app: "tldr", - propDefinitions: { - inputText: { - type: "string", - label: "Text to Summarize", - description: "The text that needs to be summarized.", - }, - responseStyle: { - type: "string", - label: "Response Style", - description: "Style of the response (e.g., Funny, Serious).", - optional: true, - }, - responseLength: { - type: "integer", - label: "Response Length", - description: "Length of the response summary.", - optional: true, - }, - }, methods: { - authKeys() { - console.log(Object.keys(this.$auth)); + _headers() { + return { + "Authorization": `Bearer ${this.$auth.api_key}`, + "Content-Type": "application/json", + }; }, _baseUrl() { - return "https://runtldr.com"; + return "https://runtldr.com/apis/v1"; }, - async _makeRequest(opts = {}) { - const { - $ = this, method = "POST", path = "/", headers, ...otherOpts - } = opts; + _makeRequest({ + $ = this, path, ...opts + }) { return axios($, { - ...otherOpts, - method, url: this._baseUrl() + path, - headers: { - ...headers, - "Authorization": `Bearer ${this.$auth.api_key}`, - "Content-Type": "application/json", - }, + headers: this._headers(), + ...opts, }); }, - async summarize({ - inputText, responseLength, responseStyle, - }) { + summarize(opts = {}) { return this._makeRequest({ + method: "POST", path: "/summarize", - data: { - inputText, - responseLength, - responseStyle, - }, + ...opts, }); }, }, From 009fc3c2cc06441247ff0344fe582121fd8c9920 Mon Sep 17 00:00:00 2001 From: Luan Cazarine Date: Mon, 4 Nov 2024 11:29:27 -0300 Subject: [PATCH 3/3] pnpm update --- pnpm-lock.yaml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 7f849c5ef0338..6ce33f30c3426 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -10437,7 +10437,10 @@ importers: '@pipedream/platform': 1.5.1 components/tldr: - specifiers: {} + specifiers: + '@pipedream/platform': ^3.0.3 + dependencies: + '@pipedream/platform': 3.0.3 components/tmetric: specifiers: {}