ChatGPT Function Calling
Hi all, I'm trying to use a chatGPT to function call an API to get data when a user enters a postcode - I've set up the function in the AssistantsAPI and in the prompt so its using the function when the postcode is inputted.
I'm having trouble with calling the API using the function and returning the response, I've tested the API keys and such and they are working - however when in typebot it returns:
"status": 500,
"body": {
"message": "400 1 validation error for Request\nbody -> tool_outputs -> 0 -> output\n field required (type=value_error.missing)",
"code": "INTERNAL_SERVER_ERROR"
This is my code in the function:
' const baseUrl = https://epc.opendatacommunities.org/api/v1/domestic/search?postcode=BH10
;
const encodedAPI = "BASE64 Encode"; // Pre-encoded API key
const requestOptions = {
method: "GET",
headers: {
Accept: "application/json",
Authorization: "Basic" + encodedAPI
}
};
try {
const response = await fetch(baseUrl, requestOptions);
if (!response.ok) {
throw new Error('Network response was not ok');
}
const data = await response.json();
console.log(data); // Log the response data
return data; // Return the parsed JSON data
} catch (error) {
console.error("Error fetching data:", error);
throw error; // Re-throw the error for handling outside the function
} '19 Replies
You need to return a string
here it seems you return a JSON object?
Would it better to use the option for csv/text? or convert it to a string with json:
const data = await response.json();
const dataString = JSON.stringify(data); // Convert JSON data to a string
return dataString
that returned the error of {
"status": 500,
"body": {
"message": "400 1 validation error for Request\nbody -> tool_outputs -> 0 -> output\n field required (type=value_error.missing)",
"code": "INTERNAL_SERVER_ERROR"
}
}Unknown User•15mo ago
Message Not Public
Sign In & Join Server To View
Ok, like I said I will publish it first thing in the morning
Unknown User•15mo ago
Message Not Public
Sign In & Join Server To View
You are referring to https://github.com/baptisteArno/typebot.io/pull/1181, right? I told you in DM that you don't have to bother, I will push the changes manually.
Unknown User•15mo ago
Message Not Public
Sign In & Join Server To View
Hmmm so I'm not getting an error anymore but the response isn't from using the function, chatgpt responds by telling me it will use the function getAddress to check for addresses rather than running the function - I've tested the process of calling the API using the webhook block which works in getting the data but would like to use the function calling to understand it for the future
and strange responses such as -
Sorry, I am not able to access external APIs in this environment. However, I can continue the conversation without knowing the specific address. Is there anything else I can assist you with?
Unknown User•15mo ago
Message Not Public
Sign In & Join Server To View
Hmmm I've added that to my script but no luck unfortunately
try {
const response = await fetch(baseUrl, requestOptions);
if (!response.ok) {
throw new Error('Network response was not ok');
}
const data = await response.json();
console.log(data); // Log the response data
return JSON.stringify(data);
} catch (error) { // Moved catch block to the correct position
console.error("Error fetching data:", error);
throw error; // Re-throw the error for handling outside the function
}
Unknown User•15mo ago
Message Not Public
Sign In & Join Server To View
Hmm I can DM you it?
Unknown User•15mo ago
Message Not Public
Sign In & Join Server To View
Just for the API Key, don't want to post it publically
Tried it with the header Accept as application/json and text/csv
Unknown User•15mo ago
Message Not Public
Sign In & Join Server To View
Booom thank you so much 🙂 Simple over looked quote 🙂
Unknown User•15mo ago
Message Not Public
Sign In & Join Server To View
Yeah that approach makes more sense, will use it in the future 🙂