I am trying to use Workflows Send HTTP Request to send a message to ChatGPT. How can I get the response from ChatGPT?
Here is an example link for GTP.
Here is an example link for GTP.
HTML Code:
var response = UrlFetchApp.fetch('https://api.openai.com/v1/chat/completions', { method: 'post', headers: { 'Authorization': 'Bearer ' + OPENAI_API_KEY, 'Content-Type': 'application/json' }, payload: JSON.stringify({ 'model': 'gpt-3.5-turbo', 'messages': [ {'role': 'system', 'content': '以下の文章に「外国籍可」を示す内容が含まれていますか?'}, {'role': 'user', 'content': text}, {'role': 'system', 'content': '回答は「はい」または「いいえ」で答えてください。'} ], 'max_tokens': 10, 'temperature': 0.2 }), muteHttpExceptions: true }); var json = JSON.parse(response.getContentText()); Logger.log(json); return json.choices && json.choices[0] && json.choices[0].message.content.trim() === 'はい' && !text.includes('外国籍:不可');
Comment