标签: openai-api

如何从 LangChain QAMapReduceChain 流式传输响应

我正在使用 Langchain 与一长段文本进行交互。文本被分成块,这些块作为下面的变量传入docs

我已经建立了一个链来传输我的响应,但是我发现handleLLMNewToken在 OpenAI 返回所有代的令牌(其中包括每个文档的映射步骤)时调用该链。

这会导致混乱的响应,这是所有一代的组合,而不仅仅是输出一代。我找不到一种方法可以让我仅在生成最终结果时对其进行流式传输。

如果我使用该变量,我可以访问已完成的提示chainResult- 但与回调不同,它不可流式传输。

const SUMMARISE_MODEL = {
        temperature: 0.5,
        modelName: "gpt-3.5-turbo-16k",
        maxTokens: 5000,
        verbose: false,
        maxConcurrency: 2,
        streaming: true,
}

//...OTHER CODE

const chain = loadQAMapReduceChain(model, {returnIntermediateSteps: true});
const chainResult = await chain.call({
            input_documents: docs,
            question: templateString,
        }, [

            {
                handleLLMNewToken(token: string) {
                    updateResponse(token);
                },
            }
        ],);
Run Code Online (Sandbox Code Playgroud)

typescript openai-api langchain

6
推荐指数
0
解决办法
1498
查看次数

GPT-2的“提示”中可以输入多少个字符

我正在使用github上的 OpenAI GPT-2 模型

我认为 top_k 参数决定了采样的令牌数量。这也是决定可以给出多大提示的参数吗?

如果top_k = 40,提示符可以有多大?

python nlp openai-api gpt-2

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

openai.error.InvalidRequestError:找不到引擎

尝试访问 OpenAPI 示例 -解释代码 但它显示错误为 -

InvalidRequestError:找不到引擎

enter code response = openai.Completion.create(
engine="code-davinci-002",
prompt="class Log:\n    def __init__(self, path):\n        dirname = os.path.dirname(path)\n        os.makedirs(dirname, exist_ok=True)\n        f = open(path, \"a+\")\n\n        # Check that the file is newline-terminated\n        size = os.path.getsize(path)\n        if size > 0:\n            f.seek(size - 1)\n            end = f.read(1)\n            if end != \"\\n\":\n                f.write(\"\\n\")\n        self.f = f\n        self.path = path\n\n    def log(self, event):\n        event[\"_event_id\"] = str(uuid.uuid4())\n        json.dump(event, self.f)\n        self.f.write(\"\\n\")\n\n    def state(self):\n        state = {\"complete\": set(), \"last\": None}\n        for line in open(self.path):\n …
Run Code Online (Sandbox Code Playgroud)

python api openai-api

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

如何在 PHP 中实现 OpenAI GPT-3 Api 客户端?

我需要帮助理解https://packagist.org/packages/orhanerday/open-ai上的模糊说明

我从https://github.com/orhanerday/open-ai下载了软件包

我通过在命令提示符中运行“composer require orhanerday/open-ai”来安装该软件包

指示从那里开始就没有意义了......

“use Orhanerday\OpenAi\OpenAi;” 是什么意思?代码的含义及其应用在哪里?我是否要创建一个 php 文件,例如 index.php,其内容为:

<?php

use Orhanerday\OpenAi\OpenAi;

$complete = $open_ai->complete([

   'engine' => 'davinci',
   'prompt' => 'Hello',
   'temperature' => 0.9,
   'max_tokens' => 150,
   'frequency_penalty' => 0,
   'presence_penalty' => 0.6,
]
?>
Run Code Online (Sandbox Code Playgroud)

如何以及在哪里添加我的 api 密钥?我是否要创建一个文件 Orhanerday\OpenAi\OpenAi.php 并在其中输入我的 api 密钥?IEOPENAI_API_KEY=sk-**********************************************

php openai-api

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

如何为 OpenAI 的 Whisper ASR 提供​​一些提示短语?

我使用 OpenAI 的Whisper python 库进行语音识别。我如何给出一些提示短语,就像使用其他 ASR(例如Google)可以完成的那样?


使用 OpenAI 的Whisper进行转录(在 Ubuntu 20.04 x64 LTS 上使用 Nvidia GeForce RTX 3090 进行测试):

conda create -y --name whisperpy39 python==3.9
conda activate whisperpy39
pip install git+https://github.com/openai/whisper.git 
sudo apt update && sudo apt install ffmpeg
whisper recording.wav
whisper recording.wav --model large
Run Code Online (Sandbox Code Playgroud)

如果使用 Nvidia GeForce RTX 3090,请在后面添加以下内容conda activate whisperpy39

pip install -f https://download.pytorch.org/whl/torch_stable.html
conda install pytorch==1.10.1 torchvision torchaudio cudatoolkit=11.0 -c pytorch
Run Code Online (Sandbox Code Playgroud)

python speech-recognition openai-api openai-whisper hint-phrases

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

Expo react-native 错误:使用 openai.createImage 时未实现 URL.search 一般 API 讨论

这是我的功能

async function generateImage() {
    try {
      const response = await openai.createImage({
        prompt: 'a white siamese cat',
        n: 1,
        size: '1024x1024',
      });
      console.log(response);
    } catch (error) {
      console.error(error);
    }
  }
Run Code Online (Sandbox Code Playgroud)

我在移动设备上使用时收到此错误:错误:URL.search 未实现

我真的陷入了困境,所以非常感谢任何帮助

react-native openai-api

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

如何在没有人窃取令牌的情况下使用我的移动应用程序中的 API

我正在构建一个使用OpenAI API的应用程序

他们为我提供了一个 API 令牌,我用它来从我的 Android 移动应用程序(反应本机)进行 API 调用

我知道在移动客户端上存储此 API 令牌是一种不好的做法,因为攻击者可能会保留它并使用我的配额和资金。

我有什么选择?简单的解决方案是构建一个后端,但我不想开始实现所有原始 API 方法,我只是更喜欢直接从客户端使用它。

我尝试以无法找到的方式存储令牌,但找不到方法。

security android react-native openai-api

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

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万
查看次数