How can I resolve this error?

Options

When calling the ChatGPT api endpoint using the External API Request, no matter how I enter the parameters/set up my function, I keep getting this error:

Exception: xano\extension\xs\Strings::xano\extension\xs\{closure}(): Return value must be of type string, array returned

I import this curl as the template:

curl https://api.openai.com/v1/chat/completions -H "Content-Type: application/json" -H "Authorization: Bearer $OPENAI_API_KEY" -d '{
"model": "gpt-3.5-turbo-16k-0613",
"messages": [
{
"role": "system",
"content": "You are a helpful assistant."
},
{
"role": "user",
"content": "Hello!"
}
]
}'

I have tried debugging statements before and after the function, the error occurs sometime during the execution of the External API Request. I used Postman to check the curl command, and everything worked just fine. I tried using this curl command identical to the way it's posted now (with a replaced env variable for the OpenAI API key), but still the same error. The strangest part is, there are other functions in my workspace that call OpenAI Chat Completion endpoint, and work just fine, returning the appropriate response. I've tried copying the working API call from those functions identically, I've tried recreating this function in a new function, deleting the original and remaking it. Is this some kind of error within Xano itself, outside of my ability to fix?

Answers

  • Michael Udinski
    Michael Udinski Administrator

    ADMIN

    Options

    Return value must be of type string, array returned

    Sounds like you are applying a filter to to an array that is only used for text strings

  • Michael Udinski
    Michael Udinski Administrator

    ADMIN

    Options

    Can you provide screenshots of the function where the error happens? Hint: by using the debugger, you can see the last function to run, this is where the error is ocurring

  • tripleshrimp
    Options

    Thank you for your time, I actually just managed to solve the problem by cloning our Xano api call that had a working version of the external api call, and just rewriting everything around it to fit. Not exactly a satisfactory solution for others with this issue but, there it is.