This topic was automatically generated from Slack. You can find the original thread here.
Can you iterate on an the output of a step using a standard integration instead of writing code? ie if I want to send N prompts to chatgpt, can I use it with the openapi chat integration directly, or is coding it the right way?
I need a component to iterate over an array of prompts to OpenAI ChatGPT, it could reuse the existing ChatGPT component only change it to accept an array of prompts and iterate over each one. The returned value should also be an array of objects with one child per response from OpenAI
change it to use the gpt-3.5-turbo model, also it should use the openai app prop for the api keys
The Post URL is https://api.openai.com/v1/chat/completions and the model is another parameter in the body.
Here’s an updated version of the custom Pipedream component that uses the gpt-3.5-turbo model and the openai app for API keys: import { axios } from "@pipedream/platform"; export default defineComponent({ props: { prompts: { type: "string[]", label: "Prompts", description: "An array of prompts to send to OpenAI ChatGPT", }, openai: { type: "app", app: "openai", label: "OpenAI", description: "Your OpenAI app for authentication", }, }, async run({ $ }) { const results = []; for (const prompt of this.prompts) { const response = await axios($, { method: "POST", url: "https://api.openai.com/v1/chat/completions", headers: { "Content-Type": "application/json", "Authorization": `Bearer ${this.openai.$auth.api_key}`, }, data: { model: "gpt-3.5-turbo", messages: [{ role: "system", content: "You are a helpful assistant." }, { role: "user", content: prompt }], max_tokens: 50, n: 1, stop: null, temperature: 0.5, }, }); results.push({ prompt: prompt, response: response.data.choices[0].message.content.trim(), }); } return results; }, }); This component now uses the gpt-3.5-turbo model and the openai app for authentication. The POST URL is updated to https://api.openai.com/v1/chat/completions, and the model is specified as a parameter in the request body.
you can use this latest one just paste it into a JS CodeStep and it works to accept as many prompts as you want (or pass it an array of prompts to run) and it will return an array of all responses.
I just tested and confirmed it works with two prompts.