我只是简单地询问AI它感觉如何
async generateArticles() { console.log('article') const response = await fetch('https://api.openai.com/v1/engines/davinci-codex/completions', { method: 'POST', headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${this.apiKey}` }, body: JSON.stringify({ prompt: `Hey, how are you?`, max_tokens: 2048, n: 1, temperature: 0.7 }) }); console.log(response) const data = await response.json(); console.log(data) const generatedText = data.choices[0].text.trim(); console.log(generatedText) }
但我得到的响应似乎是Open AI使用的代码的一部分,例如:
'positive': [ 'That\'s great!', 'Nice!', 'Good!', 'Alright!', 'Cool!', 'Yeah!',],'negative': [ 'That\'s too bad', 'Too bad', 'I\'m sorry',],'current_user': [ 'My name is {}', 'My name is {}. Nice to meet you', 'The name\'s {}', 'The name\'s {}. Pleased to meet you',],
或者像这样的内容
# def greet():# print("Hey, how are you?")# print("I hope you are fine!")# print("Bye!")## def say_bye():# print("Bye!")## def greet_bye():# greet()# say_bye()## print("I am not in the function")# greet_bye()
这很奇怪,甚至有一次是俄语。所以这是不是坏了,或者我错过了什么,才会得到这样的奇怪响应。
回答:
你并没有破坏API端点,但你使用的是Codex端点,它是为代码补全设计的。仅使用此端点来生成代码。
对于通用自然语言处理,你需要使用OpenAI的completions端点:
https://api.openai.com/v1/completions
你还需要在请求体中添加model
属性:
model: 'text-davinci-003'
我重写了你的代码:
const response = await fetch('https://api.openai.com/v1/completions', { method: 'POST', headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${this.apiKey}`, }, body: JSON.stringify({ prompt: `Hey, how are you?`, model: 'text-davinci-003', max_tokens: 2048, n: 1, temperature: 0.7 })});console.log(response)const data = await response.json();console.log(data)const generatedText = data.choices[0].text.trim();console.log(generatedText)
我从GPT3收到了以下响应:
I'm doing well, thank you. How about you?