0 votes

I would like to have different variables I can use to send to ChatGPT.

Use case: I ask my users to answer a question, and then send that question to chatgpt using the user_input_chatgpt command. However, I would like to ask a follow up question, save that with a different command, and then send it again to ChatGPT.

Is this possible? When I try now it says that I have already used the *label: API Call earlier in the program.

by (140 points)

1 Answer

0 votes

The ChatGPT API program takes two optional variables, prompt_for_chatgpt and the model to use. The simplest program that would allow your users to ask two consecutive questions would be:

*program: ChatGPT API - public

*clear

*if: success_chatgpt = 1

	*{"RESPONSE FROM CHATGPT:"}*

	{response_from_chatgpt}

*if: success_chatgpt = 0

	*{"ERROR FROM THE CHATGPT API:"}*

	{error_from_chatgpt}
	
*button: Click here to ask a second question! 

*program: ChatGPT API - public

*clear

*if: success_chatgpt = 1

	*{"RESPONSE FROM CHATGPT:"}*

	{response_from_chatgpt}

*if: success_chatgpt = 0

	*{"ERROR FROM THE CHATGPT API:"}*

	{error_from_chatgpt}	

If you don't set the prompt, the user gets to enter it. If you want to build the prompt based on the answers of your program's users, you'll save their answer into a different variable, and then build the prompt for ChatGPT, for example:

*question: Enter a short sentence
	*save: sentence
>>prompt_for_chatgpt = "Give me a sentence that rhymes with: {sentence}"

*program: ChatGPT API - public

What is happening here is that the user gets to enter a sentence that is saved into a variable called sentence. Then, the variable prompt_for_chatgpt is generated, incorporating the value of sentence (the curly brackets around a variable make it output its value). When the program ChatGPT API is run, the variable prompt_for_chatgpt is set so you will notice that the question that was displayed before, ins not displayed now.

Regarding the error message you were getting, the problem is that you copied and pasted the code including the *label, which is like a bookmark and has to be unique. You can omit the *label if you don't have a *goto statement.

by (3.6k points)

So helpful, thank you!

So to be clear: Every time I run the ChatGPT API - public program it will start this process?

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