-
Notifications
You must be signed in to change notification settings - Fork 5.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New Components - tldr #14499
New Components - tldr #14499
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,40 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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.1", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
type: "action", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
props: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
tldr, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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).", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
responseLength: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
type: "integer", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
label: "Response Length", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
description: "Length of the response summary.", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
async run({ $ }) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const response = await this.tldr.summarize({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
$, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
data: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
inputText: this.inputText, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
responseLength: this.responseLength, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
responseStyle: this.responseStyle, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
$.export("$summary", `Successfully summarized the text with the following input: "${this.inputText}"`); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return response; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+27
to
+39
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add error handling and input validation. The run method needs the following improvements:
async run({ $ }) {
+ // Validate inputs
+ if (!this.inputText?.trim()) {
+ throw new Error("Input text cannot be empty");
+ }
+
+ try {
const response = await this.tldr.summarize({
$,
data: {
inputText: this.inputText,
responseLength: this.responseLength,
responseStyle: this.responseStyle,
},
});
- $.export("$summary", `Successfully summarized the text with the following input: "${this.inputText}"`);
+ const truncatedInput = this.inputText.slice(0, 50) + (this.inputText.length > 50 ? "..." : "");
+ $.export("$summary", `Successfully summarized ${this.inputText.length} characters of text. Preview: "${truncatedInput}"`);
return response;
+ } catch (error) {
+ throw new Error(`Failed to summarize text: ${error.message}`);
+ }
}, 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <[email protected]> (https://pipedream.com/)", | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"dependencies": { | ||
"@pipedream/platform": "^3.0.3" | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,11 +1,33 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||
import { axios } from "@pipedream/platform"; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
export default { | ||||||||||||||||||||||||||||||||||||||||||||||||||
type: "app", | ||||||||||||||||||||||||||||||||||||||||||||||||||
app: "tldr", | ||||||||||||||||||||||||||||||||||||||||||||||||||
propDefinitions: {}, | ||||||||||||||||||||||||||||||||||||||||||||||||||
methods: { | ||||||||||||||||||||||||||||||||||||||||||||||||||
// this.$auth contains connected account data | ||||||||||||||||||||||||||||||||||||||||||||||||||
authKeys() { | ||||||||||||||||||||||||||||||||||||||||||||||||||
console.log(Object.keys(this.$auth)); | ||||||||||||||||||||||||||||||||||||||||||||||||||
_headers() { | ||||||||||||||||||||||||||||||||||||||||||||||||||
return { | ||||||||||||||||||||||||||||||||||||||||||||||||||
"Authorization": `Bearer ${this.$auth.api_key}`, | ||||||||||||||||||||||||||||||||||||||||||||||||||
"Content-Type": "application/json", | ||||||||||||||||||||||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||
_baseUrl() { | ||||||||||||||||||||||||||||||||||||||||||||||||||
return "https://runtldr.com/apis/v1"; | ||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||
_makeRequest({ | ||||||||||||||||||||||||||||||||||||||||||||||||||
$ = this, path, ...opts | ||||||||||||||||||||||||||||||||||||||||||||||||||
}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
return axios($, { | ||||||||||||||||||||||||||||||||||||||||||||||||||
url: this._baseUrl() + path, | ||||||||||||||||||||||||||||||||||||||||||||||||||
headers: this._headers(), | ||||||||||||||||||||||||||||||||||||||||||||||||||
...opts, | ||||||||||||||||||||||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+16
to
+24
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Add error handling and request timeout. The request method should include error handling and a timeout to prevent hanging requests. _makeRequest({
$ = this, path, ...opts
}) {
return axios($, {
url: this._baseUrl() + path,
headers: this._headers(),
+ timeout: 30000, // 30 seconds timeout
...opts,
- });
+ }).catch(err => {
+ const status = err.response?.status;
+ const message = err.response?.data?.message || err.message;
+ throw new Error(`Request failed with status ${status}: ${message}`);
+ });
}, 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||
summarize(opts = {}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
return this._makeRequest({ | ||||||||||||||||||||||||||||||||||||||||||||||||||
method: "POST", | ||||||||||||||||||||||||||||||||||||||||||||||||||
path: "/summarize", | ||||||||||||||||||||||||||||||||||||||||||||||||||
...opts, | ||||||||||||||||||||||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+25
to
+30
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Add input validation and JSDoc documentation. The summarize method should validate required parameters and include documentation about expected options. +/**
+ * Summarize text using TLDR API
+ * @param {Object} opts - Options for summarization
+ * @param {string} opts.text - Text to summarize
+ * @param {string} [opts.style] - Response style (optional)
+ * @param {number} [opts.length] - Response length (optional)
+ * @returns {Promise<Object>} Summarization response
+ */
summarize(opts = {}) {
+ if (!opts.text) {
+ throw new Error("Text parameter is required");
+ }
return this._makeRequest({
method: "POST",
path: "/summarize",
...opts,
});
}, 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Add validation constraints to props.
Consider adding the following improvements to make the props more robust:
options
toresponseStyle
to limit valid values (e.g., ["Funny", "Serious"])min
andmax
toresponseLength
to prevent unreasonable valuesmin
andmax
length constraints toinputText
📝 Committable suggestion