我正在制作一个 Python 脚本以通过其 API 使用 OpenAI。但是,我收到此错误:
openai.error.RateLimitError:您超出了当前配额,请检查您的计划和账单详细信息
我的脚本如下:
#!/usr/bin/env python3.8
# -*- coding: utf-8 -*-
import openai
openai.api_key = "<My PAI Key>"
completion = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=[
{"role": "user", "content": "Tell the world about the ChatGPT API in the style of a pirate."}
]
)
print(completion.choices[0].message.content)
Run Code Online (Sandbox Code Playgroud)
我正在声明 shebang python3.8,因为我正在使用pyenv。我认为它应该可以工作,因为我做了 0 个 API 请求,所以我假设我的代码中有错误。
之后pip install openai,当我尝试时import openai,它显示此错误:
urllib3 的“ssl”模块是使用 LibreSSL 而不是 OpenSSL 编译的
我刚刚学习了一个关于使用 OpenAI API 的项目教程。但是当我到达第一步,即安装并导入 OpenAI 时,我陷入了困境。我试图找到该错误的解决方案,但一无所获。
这是我尝试导入 OpenAI 后的消息:
Python 3.9.6 (default, Mar 10 2023, 20:16:38)
[Clang 14.0.3 (clang-1403.0.22.14.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import openai
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/yule/Library/Python/3.9/lib/python/site-packages/openai/__init__.py", line 19, in <module>
from openai.api_resources import (
File "/Users/mic/Library/Python/3.9/lib/python/site-packages/openai/api_resources/__init__.py", line 1, in <module>
from openai.api_resources.audio import Audio # noqa: …Run Code Online (Sandbox Code Playgroud) 我目前正在开发一个由大型语言模型 (LLM) 提供支持的聊天机器人,我希望它能够根据我自己的文档提供响应。我知道在我的文档上使用微调模型可能不会产生直接响应,因此我正在探索检索增强生成 (RAG) 的概念以增强其性能。
在我的研究中,我遇到了两种工具,Langchain 和 LlamaIndex,它们似乎有助于 RAG。然而,我很难理解它们之间的主要区别。我注意到一些教程和资源同时使用这两种工具,我很好奇为什么人们会选择使用一种工具而不是另一种工具,或者什么时候一起使用它们才有意义。
有人可以深入了解 Langchain 和 LlamaIndex for RAG 之间的主要区别,以及何时使用一种工具优于另一种工具或在聊天机器人开发中将它们结合起来?
chatbot openai-api llama-index langchain large-language-model
OpenAI 的文本模型具有上下文长度,例如:Curie 的上下文长度为 2049 个标记。它们提供 max_tokens 和 stop 参数来控制生成序列的长度。因此,当获得停止令牌或达到 max_tokens 时,生成就会停止。
问题是:生成文本时,我不知道提示符包含多少个标记。因为我不知道,所以我无法设置 max_tokens = 2049 - number_tokens_in_prompt。
这使我无法为各种长度的文本动态生成文本。我需要的是继续生成直到停止令牌。
我的问题是:
我正在使用 openAI API,并尝试继续对话。例如:
import openai
openai.api_key = mykey
prompt= "write me a haiku"
response = openai.Completion.create(engine="text-davinci-001",
prompt=prompt,
max_tokens=50)
print(response)
Run Code Online (Sandbox Code Playgroud)
这会产生以下格式的俳句:
{
"choices": [
{
"finish_reason": "stop",
"index": 0,
"logprobs": null,
"text": "\n\n\n\nThis world is\nfull of wonders\nSo much to see and do"
}
],
"created": 1670379922,
"id": "cmpl-6KePalYQFhm1cXmwOOJdyKiygSMUq",
"model": "text-davinci-001",
"object": "text_completion",
"usage": {
"completion_tokens": 17,
"prompt_tokens": 5,
"total_tokens": 22
}
}
Run Code Online (Sandbox Code Playgroud)
这太棒了。但是,如果我现在想要求“再给我写一封信”怎么办?如果我使用 openAI Playground 聊天或 chatGPT,我就能够继续对话。我想通过我的 python 脚本来做到这一点。我注意到我收到了id回复。我可以用它来继续我的谈话吗?
我目前正在尝试使用 OpenAI 的最新模型:gpt-3.5-turbo. 我正在遵循一个非常基本的教程。
我正在使用 Google Collab 笔记本进行工作。我必须对提示列表中的每个提示发出请求,为了简单起见,该请求如下所示:
prompts = ['What are your functionalities?', 'what is the best name for an ice-cream shop?', 'who won the premier league last year?']
Run Code Online (Sandbox Code Playgroud)
我定义了一个函数来执行此操作:
import openai
# Load your API key from an environment variable or secret management service
openai.api_key = 'my_API'
def get_response(prompts: list, model = "gpt-3.5-turbo"):
responses = []
restart_sequence = "\n"
for item in prompts:
response = openai.Completion.create(
model=model,
messages=[{"role": "user", "content": prompt}],
temperature=0,
max_tokens=20,
top_p=1, …Run Code Online (Sandbox Code Playgroud) 我正在向完成端点发出请求。我的提示是 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,并使用pip install openai.
已安装在我的笔记本电脑上,并安装在我的代码文件所在的同一文件夹中。但是当我尝试运行代码时我得到了ImportError: No module named openai
这是文件中的代码。很简单:
import openai
openai.api_key = API_KEY
prompt = "Say this is a test"
response = openai.Completion.create(
engine="text-davinci-001", prompt=prompt, max_tokens=6
)
print(response)
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
我正在尝试使用 Express NodeJS 中的以下代码向 openai API 发出请求:
import { Configuration, OpenAIApi } from "openai";
const configuration = new Configuration({
organization: "org-Fn2EqsTpiUCTKb8m61wr6H8m",
apiKey: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
});
const openai = new OpenAIApi(configuration);
async function callApi() {
const response = await openai.createCompletion({
model: "text-davinci-003",
prompt: "Say this is a test",
max_tokens: 3000,
temperature: 0,
});
console.log(response.data.choices[0].text);
}
callApi();
Run Code Online (Sandbox Code Playgroud)
问题是我不断收到错误 429 Too much requests。
这里有更多信息:
我们有一个 ChatGPT 的用例,用于总结长文本(语音到文本的对话可能超过一个小时)。
然而,我们发现 4k 令牌限制往往会导致输入文本由于令牌限制而被截断为一半左右。
零件加工似乎没有保留以前零件的历史。
对于提交超过 4k 代币的较长请求,我们有哪些选项?
openai-api ×10
python ×5
chatgpt-api ×4
gpt-3 ×2
chatbot ×1
completion ×1
express ×1
gpt-4 ×1
langchain ×1
llama-index ×1
node.js ×1
prompt ×1
urllib3 ×1