关于chat-gpt3.5模型更换一些问题
Opened this issue · 0 comments
simonlau4201 commented
之前用的text-davinci-003模型跑成功了,但是想更换gpt-3.5-turbo,纯纯小白完全搞不懂了,轻置玉臀等一位大佬帮帮忙
目的是接入谷歌云盘中的excel批量处理工作
代码如下
const SECRET_KEY = 'sk-2h4DDOS5YkvGwvRckQ36DU4lAEtOrRwsm83qJIvp50ZrQfZe';
const MAX_TOKENS = 200;
// For more cool AI snippets and demos, follow me on Twitter: https://twitter.com/_abi_
/**
- Completes your prompt with GPT-3.5-turbo
- @param {string} prompt Prompt
- @param {number} temperature (Optional) Temperature. 1 is super creative while 0 is very exact and precise. Defaults to 0.4.
- @param {string} model (Optional) GPT-3.5-turbo Model to use. Defaults to "gpt-3.5-turbo".
- @return Completion returned by GPT-3.5-turbo
- @customfunction
*/
function AI(prompt, temperature = 0.4, model = "gpt-3.5-turbo") {
const url = "https://api.closeai-proxy.xyz/v1/completions";
const payload = {
model: model,
prompt: prompt,
temperature: temperature,
max_tokens: MAX_TOKENS,
};
const options = {
contentType: "application/json",
headers: { Authorization: "Bearer " + SECRET_KEY },
payload: JSON.stringify(payload),
};
const res = JSON.parse(UrlFetchApp.fetch(url, options).getContentText());
return res.choices[0].text.trim();
}
/**
- Classifies an item into a fixed set of categories
- @param {range} categories Set of categories
- @param {string} item Item to classify
- @param {range} rules (Optional) Set of rules written in plain text
- @return Completion returned by GPT-3.5-turbo
- @customfunction
*/
function CATEGORIZE(categories, input, rules=[]) {
const prompt = "The available categories are " + categories.map((c) =>"${c}"
).join(", ") + ". " + rules.join(". ") + "The category for '" + input + "' is ";
console.log(prompt);
const completion = AI(prompt, 0, "gpt-3.5-turbo");
// Replace "s and .s at the start and end of the string
return completion.replace(/^"/g, '').replace(/["|.]{0,2}$/, '');
}
// For more cool AI snippets and demos, follow me on Twitter: https://twitter.com/_abi_
这是报错
09:28:41 错误
Exception: Request failed for https://api.closeai-proxy.xyz returned code 401. Truncated server response: {"error":{"message":"无效的sk token,请检查token是否正确","type":"error","param":null,"code":null}} (use muteHttpExceptions option to examine full response)
AI @ 代码.gs:28