0 votes

I'd like to be able to embed chatbots (a few different ones) that users can have a dialogue with. Ideally, they would have a certain number of conversation turns and then be required to respond to a question. I've been trying to create code that would take previous GPT responses and user inputs as part of the 'payload' for another API call, but I can't work it out. Any help would be much appreciated.

by (120 points)

1 Answer

0 votes

As you can see in ChatGPT's API reference, the parameter messages takes a list of messages with the conversation so far. The GuidedTrack program ChatGPT API - public only sends one message inside the list:

>> payload["messages"] = [ { "role" -> "user", "content" -> prompt_for_chatgpt } ]

You can use the program ChatGPT API with seleted parameters - public (https://www.guidedtrack.com/programs/22860) in order to include your whole conversation history inside the parameter messages. Create an association with the name payload on your main program, structure it as follows and then invoke the program:

>>payload = {"messages"-> [{"role"-> "user","content"-> "tell me a joke"},{"role"-> "assistant", "content"-> "why did the chicken cross the road" }, {"role"-> "user", "content"-> "I don't know, why did the chicken cross the road" }]}
*program: ChatGPT API with seleted parameters - public

For understanding roles: https://help.openai.com/en/articles/7042661-chatgpt-api-transition-guide
Also you may find this thread useful.

by (3.6k points)

Thanks so much for that, Belen. I was going to wait until I had successfully run the program before I responded, but I haven't gotten there yet and I thought I should say thanks.

I get the logic of what you're suggesting (I think): save each prompt and each response within the parameter "messages" in an association called 'payload' and send it to ChatGPT API each time. I can't work out the syntax though- how to save the user inputs and the responses and then structure them in the payload.

I keep getting the error message "cannot process (my command) because it is not a valid command".

Update: I think I worked it out through a little bit of trial and error.

Cheers belen!

Welcome to Guidedtrack Q&A, where you can ask questions and receive answers from other members of the community.
134 questions
144 answers
55 comments
40 users