I always get quotation marks put into the function call parameters, which breaks the request.
{
role: 'assistant',
content: null,
function_call: {
name: 'fetchAvailableURLs',
arguments: '{\n' +
' "domains": ["companeasy.com", "namelyhelp.com", "nameassist.com", "companyaid.com", "businessnaming.com", "domainfinder.com", "domaintopick.com", "pick businessname.com"]\n' +
'}'
}
try {
const messages = [
{
role: "system",
content:
`
Remove all linebreaks in your response and function calls, also never include any quotation marks like ' or " in your response or function calls.
Get a list of example urls and check if they are available for purchase.
`
},
{ role: "user", content: question },
];
const runner = client.beta.chat.completions
.runFunctions({
model: "gpt-4",
messages: messages,
functions: [
{
function: fetchAvailableEndings,
parameters: { type: "object", properties: {} },
},
{
function: fetchAvailableURLs,
parameters: {
type: "object",
properties: {
domains: {
type: "array",
description:
"Takes in an object with the key 'domains' containing an array of domains and will return which one of these domains that are available for purchase.",
items: {
type: "string",
},
},
},
required: ["domains"],
},
},
],
// function_call: "auto"
function_call: {'name': "fetchAvailableURLs"},
})
.on("message", (message) => console.log(message));
console.log("runner", runner);
const finalContent = await runner.finalContent();
return finalContent;
} catch (error) {
console.error("Error in handleUserQuery:", error);
throw new Error("Failed to process the user query");
}
error
Error in handleUserQuery: OpenAIError: Unexpected end of JSON input
at eval (webpack-internal:///(rsc)/./node_modules/openai/lib/AbstractChatCompletionRunner.mjs:54:37)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
cause: SyntaxError: Unexpected end of JSON input
at JSON.parse (<anonymous>)
at parseJSONFromBytes (node:internal/deps/undici/undici:6662:19)
at successSteps (node:internal/deps/undici/undici:6636:27)
at node:internal/deps/undici/undici:1236:60
at node:internal/process/task_queues:140:7
at AsyncResource.runInAsyncScope (node:async_hooks:206:9)
at AsyncResource.runMicrotask (node:internal/process/task_queues:137:8)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
}
POST route error: Error: Failed to process the user query
at handleUserQuery (webpack-internal:///(rsc)/./src/app/api/openapi/route.js:84:15)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async POST (webpack-internal:///(rsc)/./src/app/api/openapi/route.js:90:24)
at async /Users/Alexander/Documents/CODE/urlchecker/node_modules/next/dist/compiled/next-server/app-route.runtime.dev.js:6:62591