This code import { axios } from “@pipedream/platform”;
export default defineComponent({
props: {
openai: {
type: “app”,
app: “openai”,
},
},
async run({ steps, $ }) {
const systemMessage = steps.data_stores.$return_value;
const history = steps.Store_The_Conversation_History_and_Filter_Old_Messages.$return_value.conversationHistory;
const userMessage = steps.Store_The_Conversation_History_and_Filter_Old_Messages.$return_value.newMessage.content; // Extract content
**const** assistantResponse = **await** axios($, {
method: "post",
url: 'https://api.openai.com/v1/chat/completions',
headers: {
Authorization: `Bearer ${**this**.openai.$auth.api_key}`,
},
data: {
model: "gpt-3.5-turbo",
messages: [
{ role: "user", content: systemMessage },
...history,
{ role: "user", content: userMessage }
],
max_tokens: 340,
temperature: 0.2,
top_p: 1,
n: 1,
stream: **false**,
},
});
_// Construct the assistantResponse object with role and content_
**const** assistantResponseData = {
role: "assistant",
content: assistantResponse.data.choices[0].message.content
};
_// Return an object containing assistantResponse and userMessage_
**return** {
assistantResponse: assistantResponseData,
userMessage: userMessage
};
},
});
is returning this error:
TypeError
Cannot read properties of undefined (reading ‘choices’)
DETAILS
at Object.run (file:///tmp/__pdg__/dist/code/92c3f54652a2b1a268650d579cda8d35e1d44045bf38a99a7d22938cc7649cef/component.mjs:40:39)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at null.executeComponent (/var/task/launch_worker.js:229:22)
at MessagePort.messageHandler (/var/task/launch_worker.js:726:28)
Detailed/code mode
OpenAI (ChatGPT) Account
OpenAI (ChatGPT)
code
CODE
RESULTS
Warning (possibly out of date)
Steps above this one were re-tested. These results are possibly out of date. Test this step again
Success
Reference exports in future steps via the steps object
steps.code{1}
$return_value:
null
send_message_private_channel
CONFIGURE
RESULTS
Warning (possibly out of date)
Steps above this one were re-tested. These results are possibly out of date. Test this step again
Success
Reference exports in future steps via the steps object
steps.send_message_private_channel{1}
$return_value{5}
ok:
true
channel:
C05PXTZEGES
ts:
1693398958.411779
message{8}response_metadata{2}