我是否以某种方式破坏了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

L1-L2正则化的不同系数

我想对网络的权重同时应用L1和L2正则化。然而,我找不…

使用scikit-learn的无监督方法将列表分类成不同组别,有没有办法?

我有一系列实例,每个实例都有一份列表,代表它所遵循的不…

f1_score metric in lightgbm

我想使用自定义指标f1_score来训练一个lgb模型…

通过相关系数矩阵进行特征选择

我在测试不同的算法时,如逻辑回归、高斯朴素贝叶斯、随机…

可以将机器学习库用于流式输入和输出吗?

已关闭。此问题需要更加聚焦。目前不接受回答。 想要改进…

在TensorFlow中,queue.dequeue_up_to()方法的用途是什么?

我对这个方法感到非常困惑,特别是当我发现这个令人费解的…

发表回复

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