小编Rok*_*nko的帖子

OpenAI API:如何指定补全应返回的最大字数?

如何指定 Open AI 补全应返回的字数?

例如想象我问人工智能这个问题

埃隆·马斯克是谁?

我可以使用什么参数来确保 AI 发回的结果小于或等于 300 个字?

我认为max_tokens参数是为了这个,但它似乎max_tokens是为了分解输入而不是输出。

javascript node.js openai-api

7
推荐指数
1
解决办法
6162
查看次数

OpenAI GPT-3 API:如何扩展 TL;DR 输出的长度?

我想使用 OpenAI 的 TLDR 从 2-3 页的文章中生成 3-6 句话的摘要。我已经粘贴了文章文本,但输出似乎只停留在 1 到 2 句话之间。

openai-api gpt-3

6
推荐指数
1
解决办法
1156
查看次数

OpenAI GPT-3 API:如何让模型记住过去的对话?

有没有办法训练大型语言模型(LLM)来存储特定的上下文?例如,我有一个很长的故事,我想提出问题,但我不想把整个故事放在每个提示中。如何才能让LLM“记住这个故事”?

openai-api gpt-3

5
推荐指数
1
解决办法
5632
查看次数

OpenAI ChatGPT (GPT-3.5) API 错误:“openai.createChatCompletion 不是函数”

我的 MERN 堆栈代码文件中有这个,并且运行良好。

exports.chatbot = async (req, res) => {
  console.log("OpenAI Chatbot Post");

  const { textInput } = req.body;

  try {

    const response = await openai.createCompletion({
      model: "text-davinci-003",
      prompt: `
            What is your name?
            My name is Chatbot.
            How old are you?
            I am 900 years old.
            ${textInput}`,
      max_tokens: 100,
      temperature: 0,
    });
    if (response.data) {
      if (response.data.choices[0].text) {
        return res.status(200).json(response.data.choices[0].text);
      }
    }
  } catch (err) {
    return res.status(404).json({ message: err.message });
  }
};
Run Code Online (Sandbox Code Playgroud)

当我更改API请求时,使用新的API来完成聊天,这个不起作用(API代码来自openAI网站,并且适用于postman)


exports.chatbot = async (req, res) …
Run Code Online (Sandbox Code Playgroud)

axios openai-api chatgpt-api

5
推荐指数
2
解决办法
6938
查看次数

OpenAI ChatGPT (GPT-3.5) API 错误 400:“错误请求”(从 GPT-3 API 迁移到 GPT-3.5 API)

尝试调用刚刚为 ChatGPT 发布的 got-3.5-turbo API,但我收到了错误的请求错误?


    var body = new
                    {
                        model = "gpt-3.5-turbo",
                        messages = data
                    };

                    string jsonMessage = JsonConvert.SerializeObject(body);

  using (HttpClient client = new HttpClient())
                    {
                        ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

                        HttpRequestMessage requestMessage = new
                        HttpRequestMessage(HttpMethod.Post, "https://api.openai.com/v1/completions")
                        {
                            Content = new StringContent(jsonMessage, Encoding.UTF8, "application/json")
                        };

                        string api_key = PageExtension_CurrentUser.Community.CAIChatGPTAPIKey.Length > 30 ? PageExtension_CurrentUser.Community.CAIChatGPTAPIKey : Genesis.Generic.ReadAppSettingsValue("chatGPTAPIKey");
                        requestMessage.Headers.Add("Authorization", $"Bearer {api_key}");

                        HttpResponseMessage response = client.SendAsync(requestMessage).Result;
                        if (response.StatusCode == HttpStatusCode.OK)
                        {
                            string responseData = response.Content.ReadAsStringAsync().Result;
                            dynamic responseObj = JsonConvert.DeserializeObject(responseData);
                            string choices = responseObj.choices[0].text;
                           
                    } …
Run Code Online (Sandbox Code Playgroud)

post openai-api chatgpt-api

5
推荐指数
1
解决办法
1万
查看次数

OpenAI API 404 响应

我正在尝试将 ChatGPT 用于我的Telegram机器人。我曾经使用“text-davinci-003”模型,它运行良好(即使现在也运行良好),但我对其响应不满意。

现在我尝试将模型更改为“gpt-3.5-turbo”,它抛出一个 404 响应代码,其中包含文本“错误:请求失败,状态代码 404”,仅此而已。这是我的代码:

import { Configuration, OpenAIApi } from "openai";
import { env } from "../utils/env.js";

const model = "gpt-3.5-turbo"; // works fine when it's "text-davinci-003"
const configuration = new Configuration({
  apiKey: env.OPENAI_API_KEY,
});
const openai = new OpenAIApi(configuration);

export async function getChatGptResponse(request) {
  try {
    const response = await openai.createCompletion({
      model,
      prompt: request, // request comes as a string
      max_tokens: 2000,
      temperature: 1,
      stream: false
    });

    console.log("Full response: ", response, `Choices: `, ...response.data.choices) …
Run Code Online (Sandbox Code Playgroud)

javascript node.js telegram-bot openai-api chatgpt-api

5
推荐指数
1
解决办法
5197
查看次数

OpenAI GPT-3 API 错误:“无效 URL (POST /v1/chat/completions)”

这是我的代码片段:

const { Configuration, OpenAI, OpenAIApi } = require ("openai");
const configuration = new Configuration({
    apiKey: 'MY KEY'
})

const openai = new OpenAIApi(configuration)

async function start() {
    const response = await openai.createChatCompletion({
        model:"text-davinci-003",
        prompt: "Write a 90 word essay about Family Guy",
        temperature: 0,
        max_tokens: 1000
    })

    console.log(response.data.choices[0].text)
}

start()
Run Code Online (Sandbox Code Playgroud)

当我跑步时:node index

我遇到这个问题:

data: {
      error: {
        message: 'Invalid URL (POST /v1/chat/completions)',
        type: 'invalid_request_error',
        param: null,
        code: null
      }
    }
  },
  isAxiosError: true,
  toJSON: [Function: toJSON]
}
Run Code Online (Sandbox Code Playgroud)

Node.js …

node.js openai-api gpt-3

5
推荐指数
1
解决办法
1万
查看次数

OpenAI API:如何使用 gpt-4-vision-preview 模型启用 JSON 模式?

更新:他们似乎在 API 文档中犯了一个错误,现在已修复。

早些时候,它说“当调用gpt-4-vision-preview或 时gpt-3.5-turbo”,但现在改为“当调用gpt-4-1106-preview或 时gpt-3.5-turbo-1106”。


根据Text Generation - OpenAI API,“当调用gpt-4-vision-preview或时gpt-3.5-turbo,您可以将 response_format 设置{ type: "json_object" }为启用 JSON 模式。”

但是,以下代码会引发错误:

 {'error': {'message': '1 validation error for Request\nbody -> response_format\n  extra fields not permitted (type=value_error.extra)', 'type': 'invalid_request_error', 'param': None, 'code': None}}
Run Code Online (Sandbox Code Playgroud)

如果我发表评论"response_format": {"type": "json_object"},效果很好。

    headers = {
        "Content-Type": "application/json",
        "Authorization": f"Bearer {api_key}"
    }
    
    payload = {
        "model": "gpt-4-vision-preview",
        "response_format": {"type": "json_object"},
        "messages": [
          { …
Run Code Online (Sandbox Code Playgroud)

python openai-api gpt-4

5
推荐指数
2
解决办法
9103
查看次数

OpenAI API 错误:“您尝试访问 openai.Completion,但 openai>=1.0.0 不再支持此操作”

我想使用 GPT 4 模型将 csv 文件中的文本翻译成英语,但我不断收到以下错误。即使我更新了版本,我仍然收到相同的错误。

\n
import openai\nimport pandas as pd\nimport os\nfrom tqdm import tqdm\n\n\nopenai.api_key = os.getenv("API")\n\ndef translate_text(text):\n    response = openai.Completion.create(\n        model="text-davinci-003",  # GPT-4 modeli\n        prompt=f"Translate the following Turkish text to English: '{text}'",\n        max_tokens=60\n    )\n    # Yeni API yap\xc4\xb1s\xc4\xb1na g\xc3\xb6re yan\xc4\xb1t\xc4\xb1n al\xc4\xb1nmas\xc4\xb1\n    return response.choices[0].text.strip()\n\ndf = pd.read_excel('/content/3500-turkish-dataset-column-name.xlsx')\n\ncolumn_to_translate = 'review'\n\ndf[column_to_translate + '_en'] = ''\n\nfor index, row in tqdm(df.iterrows(), total=df.shape[0]):\n    translated_text = translate_text(row[column_to_translate])\n    df.at[index, column_to_translate + '_en'] = translated_text\n\ndf.to_csv('path/to/your/translated_csvfile.csv', index=False)\n\n
Run Code Online (Sandbox Code Playgroud)\n
 0%|          | 0/3500 [00:00<?, ?it/s]\n---------------------------------------------------------------------------\nAPIRemovedInV1                            Traceback (most recent call last)\n<ipython-input-27-337b5b6f4d32> in …
Run Code Online (Sandbox Code Playgroud)

python openai-api gpt-3

5
推荐指数
1
解决办法
2万
查看次数

OpenAI GPT-3 API:为什么我只能部分完成?为何完成被切断?

我尝试了以下代码,但只得到了部分结果,例如

[{"light_id": 0, "color
Run Code Online (Sandbox Code Playgroud)

我期待本页建议的完整 JSON:

https://medium.com/@richardhayes777/using-chatgpt-to-control-hue-lights-37729959d94f

import json
import os
import time
from json import JSONDecodeError
from typing import List

import openai
openai.api_key =  "xxx"

HEADER = """
I have a hue scale from 0 to 65535. 
red is 0.0
orange is 7281
yellow is 14563
purple is 50971
pink is 54612
green is 23665
blue is 43690

Saturation is from 0 to 254
Brightness is from 0 to 254

Two JSONs should be returned in a list. Each …
Run Code Online (Sandbox Code Playgroud)

python openai-api gpt-3

4
推荐指数
1
解决办法
4362
查看次数