https://discord.gg/botpress logo
#🤝help
Use GPT to ask question, then have those results go into an API
# 🤝help
b

brainy-planet-775

07/20/2023, 11:19 PM
I am trying to figure out how to have Chat GPT ask a question and then have it sort the answer into fields that can be fed to an API? For example: User is looking for a Honda Civic with less than 35,000 miles for under $20k. I'm not a skilled coder, so trying to figure this out. Thanks in advance.
g

gorgeous-telephone-56581

07/20/2023, 11:29 PM
the easiest way i figured it out is to have the AI respond in a json format. with two fields. Message + nextaction then you can take the next action and parse it into whatever api you are using. but you need to have the AI know how your endpoint works so it can generate a proper link. after that you can get the result. feed it into the AI and have it spit that data out in a well formatted way.
@brainy-planet-775 hope that helps you. there are most likely other ways but this is the easiest way for me at least.
b

brainy-planet-775

07/20/2023, 11:44 PM
I appreciate the response but that is a bit over my head probably. No clue how to have AI respond in json format
g

gorgeous-telephone-56581

07/20/2023, 11:55 PM
in the system message you can define how it should respond. here is an example from my own bot
Copy code
js
let gptThought = ` You must respond in a JSON format like this with no formatting:
    {"message": "Hello","nextAction": "askGPT"}
    // message is the text you want to send to the client
    // nextAction is the next action you want to take. It can be "askGPT" or "endChat"
    // AskGPT will ask return the client's response to the GPT-4 model
    // endChat will end the chat `
then i take the output and parse it on my end. Make sure to json parse the output
e

early-train-33247

07/21/2023, 12:16 AM
Hey @gorgeous-telephone-56581, thanks for the detailed suggestion!
g

gorgeous-telephone-56581

07/21/2023, 12:19 AM
if you don't have technical knowledge in coding it might be very hard for you to implement this yourself.
e

early-train-33247

07/21/2023, 12:20 AM
@brainy-planet-775, are the fields always going to be the same? In your example, the output could be:
Copy code
json
{
 "manufacturer": "Honda",
 "model": "Civic",
 "priceRangeMax": 20000,
 "milesRangeMax": 35000
}
What data is the API expecting to receive in order to search for cars? Do you own the API? That should tell you how your AI output should look like
You can do as @gorgeous-telephone-56581 suggested and instruct the AI to respond with a specific format, no need to be a JSON though, but the variable where the result will be stored needs to be an object, then you will send that object in the request to the cars API
If you give more details about your use case and infrastructure we might be able to provide with a more detailed guide
b

brainy-planet-775

07/21/2023, 12:27 AM
How do I instruct the AI to decipher what the visitor typed in and then use that in "get" format for a public API?
g

gorgeous-telephone-56581

07/21/2023, 12:27 AM
you need to inform the AI what the API expects. so Make Model Year or etc. and once the customer satisfies all the conditions it runs a flow to grab the data.
what public api are you trying to code this for
do you know what it expects as a input
b

brainy-planet-775

07/21/2023, 12:29 AM
it's actually for a Zillow API and I am getting home data (I just didn't want to make the idea public on here) . So, I want the user to be able to say $500k house in San Diego with at least 3 bedrooms https://rapidapi.com/apimaker/api/zillow-com1/
same idea though, sorry for the confusion