Use own chatgpt API
# 🤝help
g
Hello, sorry to bother with the newbie question. I try to use code to link my own OpenAI but it cant generate a response. Is there someting wrong this the workflow (like let the code capture the question) or with the code. Thank you so much for your time.

https://cdn.discordapp.com/attachments/1143169978359615591/1143169979072655470/image.png

https://cdn.discordapp.com/attachments/1143169978359615591/1143169979441745970/image.png

b
Hi try this
`const apiKey = env.gpt_key; const {data} = await axios.post("https://api.openai.com/v1/chat/completions", { "model": "gpt-3.5-turbo-0301", "messages": [{"role": "user", "content": event.preview}] }, { headers: {'Authorization':
Bearer ${apiKey}
}}); workflow.chatGPTResponse = data.choices[0].message.content;`
of course put your api key
but use event.preview in "content" and tell me
event.preview refers to the last input placed
also try ghatgpt 3.5 first
f
@green-answer-87939 I think your code is missing the "question" variable
g
Do i need to create a questin variable as event.preview already save the user last input. e.g. const question = workflow.userquestion; I tried use event.preview in "content" and replace it with a question variable. neither of them works.
f
what do you mean by neither of them works?
what are you trying to achieve?
event.preview holds the last input from the user side
did you try sending a static value? just to make sure that the rest of the code is correct?
also are you sure that this "data.choices[0].message.content" works?
is this code generated by chatGPT?
sorry for so many questions 🙈
7 Views