OpenAI 的文本模型具有上下文长度,例如:Curie 的上下文长度为 2049 个标记。它们提供 max_tokens 和 stop 参数来控制生成序列的长度。因此,当获得停止令牌或达到 max_tokens 时,生成就会停止。
问题是:生成文本时,我不知道提示符包含多少个标记。因为我不知道,所以我无法设置 max_tokens = 2049 - number_tokens_in_prompt。
这使我无法为各种长度的文本动态生成文本。我需要的是继续生成直到停止令牌。
我的问题是:
我正在向完成端点发出请求。我的提示是 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)
如果您能够解决这个问题,我很想听听您是如何做到的。
我希望 ChatGPT 记住过去的对话并进行一致(有状态)的对话。
我见过几个ChatGPT提示工程的代码。
有两种方法可以设计如下所示的提示(伪代码):
使用单个输入(便宜)<- 如果可能的话更好
堆叠所有以前的历史记录(昂贵,令牌限制)
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) 我是 API 新手,我试图了解如何使用 OpenAI 的 GPT-3 API(使用 api.openai.com/v1/completions)从提示中获取响应。我正在使用邮递员来做到这一点。文档说只有一个必需的参数,即“模型”。但是,我收到一条错误消息,提示“您必须提供模型参数”,尽管我已经提供了该参数。
我究竟做错了什么?
我正在尝试 OpenAI。
\n我已经准备好了训练数据,并使用了fine_tunes.create
. 几分钟后,显示Stream interrupted (client disconnected)
。
$ 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
,几分钟后,仍然失败:
$ openai api fine_tunes.follow -i …
Run Code Online (Sandbox Code Playgroud) 我有三个问题:
给定 LLM 参数的数量(以十亿为单位),您如何计算出运行模型需要多少 GPU RAM?
如果您有足够的 CPU-RAM(即没有 GPU),您可以运行该模型,即使它很慢
你可以在混合 GPU-RAM 和 CPU-RAM 中运行 LLM 模型(如 h2ogpt、open-assistant)吗?
artificial-intelligence deep-learning gpt-3 large-language-model
我正在围绕 GPT-3 构建一个应用程序,我想知道我发出的每个请求使用了多少令牌。这可能吗?如何实现?
我不断收到如下错误
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) 我尝试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) 我使用带有“提示”和“完成”的自定义文本来训练新模型。
这是我用来根据数据创建自定义模型的教程:
beta.openai.com/docs/guides/fine-tuning/advanced-usage
然而,即使在训练模型并向模型发送提示文本之后,我仍然得到并不总是适合我的通用结果。
如何确保提示的完成结果仅来自我用于模型的文本,而不是来自通用 OpenAI 模型?
我可以使用一些标志来消除通用模型的结果吗?
gpt-3 ×10
openai-api ×7
nlp ×2
python ×2
azure ×1
azure-openai ×1
chatgpt-api ×1
gpt-4 ×1
http-post ×1
postman ×1
prompt ×1
rest ×1
text ×1