我是否以某种方式破坏了API?

我只是简单地询问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?

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注