标签: gpt-3

OpenAI API:在发送 API 请求之前(!)如何计算令牌?

OpenAI 的文本模型具有上下文长度,例如:Curie 的上下文长度为 2049 个标记。它们提供 max_tokens 和 stop 参数来控制生成序列的长度。因此,当获得停止令牌或达到 max_tokens 时,生成就会停止。

问题是:生成文本时,我不知道提示符包含多少个标记。因为我不知道,所以我无法设置 max_tokens = 2049 - number_tokens_in_prompt。

这使我无法为各种长度的文本动态生成文本。我需要的是继续生成直到停止令牌。

我的问题是:

  • 如何计算Python API中的token数量?这样我就会相应地设置 max_tokens 参数。
  • 有没有办法将 max_tokens 设置为最大上限,这样我就不需要计算提示令牌的数量?

openai-api gpt-3 chatgpt-api gpt-4

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

OpenAI GPT-3 API 错误:“此模型的最大上下文长度为 4097 个令牌”

我正在向完成端点发出请求。我的提示是 1360 个令牌,经 Playground 和 Tokenizer 验证。我不会显示提示,因为对于这个问题来说有点太长了。

这是我使用 openai npm 包在 Nodejs 中对 openai 的请求。

const response = await openai.createCompletion({
  model: 'text-davinci-003',
  prompt,
  max_tokens: 4000,
  temperature: 0.2
})
Run Code Online (Sandbox Code Playgroud)

在 Playground 中进行测试时,响应后我的总代币数为 1374。

通过完成 API 提交提示时,我收到以下错误:

error: {
  message: "This model's maximum context length is 4097 tokens, however you requested 5360 tokens (1360 in your prompt; 4000 for the completion). Please reduce your prompt; or completion length.",
  type: 'invalid_request_error',
  param: null,
  code: null
}
Run Code Online (Sandbox Code Playgroud)

如果您能够解决这个问题,我很想听听您是如何做到的。

openai-api gpt-3

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

ChatGPT 令牌限制

我希望 ChatGPT 记住过去的对话并进行一致(有状态)的对话。

我见过几个ChatGPT提示工程的代码。

有两种方法可以设计如下所示的提示(伪代码):

  1. 使用单个输入(便宜)<- 如果可能的话更好

  2. 堆叠所有以前的历史记录(昂贵,令牌限制)

def openai_chat(prompt):
    completions = openai.Completion.create(
        engine = "text-davinci-003",
        prompt = prompt,
        max_tokens = 1024,
        n = 1,
        temperature = 0.8,
    )
    response = completions.choices[0].text.strip()
    return response

# 1. Use a single input
while True:
    prompt = input("User: ")
    completion = openai_chat(prompt)

# 2. Stack all of previous history (prompt + completion)
prompt = ""
while True:
    cur_prompt = input("User: ")
    prompt += cur_prompt  # pseudo code
    completion = openai_chat(prompt)
    prompt …
Run Code Online (Sandbox Code Playgroud)

text nlp prompt openai-api gpt-3

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

GPT-3 API invalid_request_error:您必须提供模型参数

我是 API 新手,我试图了解如何使用 OpenAI 的 GPT-3 API(使用 api.openai.com/v1/completions)从提示中获取响应。我正在使用邮递员来做到这一点。文档说只有一个必需的参数,即“模型”。但是,我收到一条错误消息,提示“您必须提供模型参数”,尽管我已经提供了该参数。

我究竟做错了什么?

API错误截图

rest http-post postman openai-api gpt-3

16
推荐指数
2
解决办法
3万
查看次数

OpenAI:流中断(客户端断开连接)

我正在尝试 OpenAI。

\n

我已经准备好了训练数据,并使用了fine_tunes.create. 几分钟后,显示Stream interrupted (client disconnected)

\n
$ openai api fine_tunes.create -t data_prepared.jsonl\nUpload progress: 100%|\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88| 47.2k/47.2k [00:00<00:00, 44.3Mit/s]\nUploaded file from data_prepared.jsonl: file-r6dbTH7rVsp6jJMgbX0L0bZx\nCreated fine-tune: ft-JRGzkYfXm7wnScUxRSBA2M2h\nStreaming events until fine-tuning is complete...\n\n(Ctrl-C will interrupt the stream, but not cancel the fine-tune)\n[2022-12-02 11:10:08] Created fine-tune: ft-JRGzkYfXm7wnScUxRSBA2M2h\n[2022-12-02 11:10:23] Fine-tune costs $0.06\n[2022-12-02 11:10:24] Fine-tune enqueued. Queue number: 11\n\nStream interrupted (client disconnected).\nTo resume the stream, run:\n\n  openai api fine_tunes.follow -i ft-JRGzkYfXm7wnScUxRSBA2M2h\n
Run Code Online (Sandbox Code Playgroud)\n

我尝试了fine_tunes.follow,几分钟后,仍然失败:

\n
$ openai api fine_tunes.follow -i …
Run Code Online (Sandbox Code Playgroud)

openai-api gpt-3

11
推荐指数
2
解决办法
7026
查看次数

确定运行 LLM 模型的一般规范

我有三个问题:

给定 LLM 参数的数量(以十亿为单位),您如何计算出运行模型需要多少 GPU RAM?

如果您有足够的 CPU-RAM(即没有 GPU),您可以运行该模型,即使它很慢

你可以在混合 GPU-RAM 和 CPU-RAM 中运行 LLM 模型(如 h2ogpt、open-assistant)吗?

artificial-intelligence deep-learning gpt-3 large-language-model

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

我如何知道 GPT-3 请求使用了多少令牌?

我正在围绕 GPT-3 构建一个应用程序,我想知道我发出的每个请求使用了多少令牌。这可能吗?如何实现?

gpt-3

10
推荐指数
2
解决办法
9462
查看次数

OpenAI GPT-3 API 错误:“请求超时”

我不断收到如下错误

Request timed out: HTTPSConnectionPool(host='api.openai.com', port=443): Read timed out. (read timeout=600)

当我运行下面的代码时

def generate_gpt3_response(user_text, print_output=False):
    """
    Query OpenAI GPT-3 for the specific key and get back a response
    :type user_text: str the user's text to query for
    :type print_output: boolean whether or not to print the raw output JSON
    """
    time.sleep(5)
    completions = ai.Completion.create(
        engine='text-davinci-003',  # Determines the quality, speed, and cost.
        temperature=0.5,            # Level of creativity in the response
        prompt=user_text,           # What the user typed in
        max_tokens=150,             # Maximum …
Run Code Online (Sandbox Code Playgroud)

python openai-api gpt-3

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

为什么在调用 Azure OpenAI GPT 时使用“函数”时会收到错误“无法识别的请求参数提供:函数”?

我尝试functions在调用 Azure OpenAI GPT 时使用,如https://platform.openai.com/docs/api-reference/chat/create#chat/create-functions中所述

我用:

import openai
openai.api_type = "azure"
openai.api_base = "https://XXXXXXXX.openai.azure.com/"
openai.api_version = "2023-06-01-preview"
openai.api_key = os.getenv("OPENAI_API_KEY")
response = openai.ChatCompletion.create(
            engine="gpt-35-turbo-XXX",
            model="gpt-35-turbo-0613-XXXX"
            messages=messages,
            functions=functions,
            function_call="auto",
        )
Run Code Online (Sandbox Code Playgroud)

但我收到错误:

openai.error.InvalidRequestError:
Unrecognized request argument supplied: functions
Run Code Online (Sandbox Code Playgroud)

为什么?


运行上面示例代码的数据(messages并且functions需要定义):

messages = [{"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": "Hello!"}]
functions = [
    {
        "name": "fetch_pages",
        "description": "Fetch the content of specified pages from the document.",
        "parameters": {
            "type": "object",
            "properties": …
Run Code Online (Sandbox Code Playgroud)

python azure gpt-3 azure-openai large-language-model

9
推荐指数
1
解决办法
7757
查看次数

如何确保答案来自自定义(微调)数据集?

我使用带有“提示”和“完成”的自定义文本来训练新模型。

这是我用来根据数据创建自定义模型的教程:

beta.openai.com/docs/guides/fine-tuning/advanced-usage

然而,即使在训练模型并向模型发送提示文本之后,我仍然得到并不总是适合我的通用结果。

如何确保提示的完成结果仅来自我用于模型的文本,而不是来自通用 OpenAI 模型?

我可以使用一些标志来消除通用模型的结果吗?

customization nlp openai-api gpt-3

8
推荐指数
1
解决办法
7971
查看次数