I'm getting null in this google script code const gptQuery = () => { var schema =…
- User
I'm getting null in this google script code
const gptQuery = () => { var schema = 'questions' const gptRequestUrl = "https://api.openai.com/v1/chat/completions"
const headers = { "Content-Type": 'application/json', Authorization:
Bearer ${gptAuth}, }const query = { "model": "gpt-4o", "messages": [{ "role": "user", "content": [{ "type": "text", "text": "capital of japan?" }] }], "functions": [schemas[schema]], "function_call": { name:
${schema}} }const options = { method: "POST", headers: headers, payload: JSON.stringify(query) };
const request = UrlFetchApp.fetch(gptRequestUrl, options)
const result = JSON.parse(request)
const resultParsed = result.choices[0].message.content
Logger.log(resultParsed)
return resultParsed
}
const schemas = { "questions": { name: "questions", description: "Get a list of questions based on the given content", parameters: { type: "object", properties: { response: { type: "array", items: { type: "object", properties: { question: { type: "string" }, type: { type: "string" }, options: { type: "array", items: { type: "string" }, description: "Optional. Only for multiple choice questions." } }, required: ["question", "type"] } } }, required: ["response"] } }, "plain": { name: "plain", description: "Get a plain response", parameters: { type: "object", properties: { response: { type: "string" } }, required: ["response"] } } }
- Assistant