Glad to hear !
Btw, are you sure Patrick is here in this thread or was the message meant to be somewhere else?
LOL, so sorry, I meant Andrew. Forgive me. Its early- need more coffee!
No worries! Could you share the screenshot here? Or you can DM me
Sure, I’ll DM you!
can you help write a code step that gets the response from an OpenAI Assistant. If the response is ready, then return the response. If not, use $.flow.rerun to run the step again with a delay of 30 seconds, and max 5 times
To achieve this, you can use the $.flow.rerun
function to retry the request if the response from the OpenAI Assistant is not ready. Here’s an example Pipedream component that implements this logic: ```
import { axios } from “@pipedream/platform”; export default defineComponent({ props: { openai: { type: “app”, app: “openai”, }, }, async run({ steps, $ }) { const MAX_RETRIES = 5; const DELAY = 1000 ** 30; // 30 seconds try { const response = await axios($, { url: https://api.openai.com/v1/assistants/response
, // Replace with the correct endpoint method: “GET”, headers: { Authorization: Bearer ${this.openai.$auth.api_key}
, }, // Add any required parameters here }); // Check if the response is ready if (response.status === “ready”) { return response.data; } else { // If not ready, retry after a delay $.flow.rerun(DELAY, null, MAX_RETRIES); } } catch (error) { // Handle errors and retry $.flow.rerun(DELAY, null, MAX_RETRIES); } }, });
Hi, Pi. I’m getting an “invalid time value” error
oh, you’ll have to tag him — I’m getting an “invalid time value” error
It seems like you’re encountering an “invalid time value” error. This type of error typically occurs when a date or time value is not formatted correctly or is not recognized by the system. Here are a few steps you can take to troubleshoot and resolve this issue: 1. Check the Date/Time Format: Ensure that any date or time values you’re using are in a format that is recognized by the system. Common formats include ISO 8601 (e.g., “2023-10-05T14:48:00.000Z”). 2. Validate Input Data: If the date/time value is coming from an external source or user input, validate the data to ensure it’s in the correct format before processing it. 3. Use Built-in Date Functions: If you’re manipulating date/time values in code, consider using built-in functions or libraries that handle date parsing and formatting, such as JavaScript’s Date
object or libraries like moment.js
. 4. Debugging: Add logging or debugging statements to print out the date/time values being processed. This can help identify where the invalid value is being introduced. If you’re still having trouble, you might want to provide more context or specific code snippets where the error occurs. This can help in diagnosing the issue further. If you need more support, you can visit Pipedream Support for additional assistance.
hello. I’m back. i’ve got everything working (i think), but when i reply to the bot in the thread, the message gets stuck. i’ve worked with pi and it doesn’t have any other suggestions for me.
this is where i am at. much simpler. it will run through the first time no problem. the second time my reply in thread will trigger the workflow but it gets stuck between code 1 and send message.
this is the code:
import { axios } from “@pipedream/platform”;
export default defineComponent({
props: {
openai: { type: “app”, app: “openai” },
thread_id: { type: “string”, label: “OpenAI Thread ID” },
run_id: { type: “string”, label: “Assistant Run ID” },
},
async run({ $ }) {
const POLL_INTERVAL_MS = 2_000; // 2 s
const IN_PROCESS_WINDOW_MS = 30_000; // ← was 25 000
const RERUN_DELAY_MS = 65_000; // ≥ 60 000 ms
const apiKey = this.openai.$auth.api_key;
const threadId = this.thread_id;
const runId = this.run_id;
const headers = {
Authorization: `Bearer ${apiKey}`,
"OpenAI-Beta": "assistants=v2",
};
try {
const deadline = Date.now() + IN_PROCESS_WINDOW_MS;
while (Date.now() < deadline) {
const run = await axios($, {
url: `https://api.openai.com/v1/threads/${threadId}/runs/${runId}`,
method: "GET",
headers,
});
if (run.status === "completed") {
const { data: msgs } = await axios($, {
url: `https://api.openai.com/v1/threads/${threadId}/messages?limit=1&order=desc`,
method: "GET",
headers,
});
const assistantMsg = msgs.find(m => m.role === "assistant");
const message =
assistantMsg?.content?.find(c => c.type === "text")?.text?.value
?? ":shrug: No assistant text found";
return { status: "ready", message };
}
if (["failed", "cancelled", "expired"].includes(run.status)) {
throw new Error(`Assistant run ended with status: ${run.status}`);
}
await new Promise(res => setTimeout(res, POLL_INTERVAL_MS));
}
console.log(`:large_yellow_circle: Run still in progress – rerunning in ${RERUN_DELAY_MS / 1000}s`);
$.flow.rerun(RERUN_DELAY_MS);
} catch (err) {
throw new Error(`Assistant polling failed: ${err.message}`);
}
},
});