我尝试了以下代码,但只得到了部分结果,例如
[{"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) 我正在测试 OpenAI 的不同模型,我注意到并非所有模型都经过足够的开发或训练以给出可靠的响应。
我测试的型号如下:
model_engine = "text-davinci-003"
model_engine = "davinci"
model_engine = "curie"
model_engine = "babbage"
model_engine = "ada"
Run Code Online (Sandbox Code Playgroud)
davinci我需要了解和之间的区别text-davinci-003,以及如何改进响应以匹配使用 ChatGPT 时的响应。
我只是使用 OpenAI API 在 Python 中尝试一些简单的函数,但遇到了错误:
我有一个正在使用的有效 API 密钥。
代码:
>>> import os
>>> import openai
>>> openai.api_key = os.getenv("I have placed the key here")
>>> response = openai.Completion.create(model="text-davinci-003", prompt="Say this is a test", temperature=0, max_tokens=7)
Run Code Online (Sandbox Code Playgroud)
在 GPT-3 API 的文档中,它说:
需要记住的一个限制是,对于大多数模型来说,单个 API 请求在提示和完成之间最多只能处理 2,048 个令牌(大约 1,500 个单词)。
在微调模型的文档中,它说:
训练样本越多越好。我们建议至少有几百个例子。一般来说,我们发现数据集大小每增加一倍都会导致模型质量线性增加。
我的问题是,1,500 字的限制是否也适用于微调模型?“数据集大小加倍”是否意味着训练数据集的数量而不是每个训练数据集的大小?
我有一个包含大量数据的 SQL 表,需要使用 Chat Completion API 将 SQL 表数据训练到 ChatGPT。
我尝试使用 ChatGPT 生成 SQL 查询,但这无法按预期工作。有时它会生成不适当的查询。
我正在开发一个 ChatGPT-App,使用 React 和 Axios 向 OpenAI 的 GPT-3.5 API 发出 API 请求。但是,我在尝试发出请求时遇到 404 错误。我希望有人可以帮助我确定问题并指导我如何解决它。以下是 App.js 和 index.js 代码和错误消息:
应用程序.js
function App() {
const [messages, setMessages] = useState([]);
const [input, setInput] = useState("");
const sendMessage = async () => {
if (input.trim() === "") return;
const userInput = input; // Store user input in a temporary variable
setMessages([...messages, { type: "user", text: userInput }]);
setInput("");
try {
const response = await axios.post("http://localhost:5000/api/chat", { text: userInput });
const gptResponse = …Run Code Online (Sandbox Code Playgroud) AuthenticationError我尝试使用下面的代码,但 OpenAI API库中没有该方法。我怎样才能有效地处理这样的错误。
import openai
# Set up your OpenAI credentials
openai.api_key = 'YOUR_API_KEY'
try:
# Perform OpenAI API request
response = openai.some_function() # Replace with the appropriate OpenAI API function
# Process the response
# ...
except openai.AuthenticationError:
# Handle the AuthenticationError
print("Authentication error: Invalid API key or insufficient permissions.")
# Perform any necessary actions, such as displaying an error message or exiting the program
Run Code Online (Sandbox Code Playgroud) 所以我正在编写一些与 chatgpt3 一起使用的 python 代码。它的作用是发送带有提示的请求,然后获取回复,但我不断收到错误。错误是
Traceback (most recent call last):
File "main.py", line 16, in <module>
print(response_json['choices'][0]['text'])
KeyError: 'choices'
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
import json
import requests
import os
data = {
"prompt": "What is the meaning of life?",
"model": "text-davinci-002"
}
response = requests.post("https://api.openai.com/v1/engines/davinci/completions", json=data, headers={
"Content-Type": "application/json",
"Authorization": f"Bearer {apikey}",
})
response_json = json.loads(response.text)
print(response_json['choices'][0]['text'])
Run Code Online (Sandbox Code Playgroud)
我确实有一个有效的 API 密钥和 JSON 代码,但我没有得到 JSON 代码。
{'error': {'message': 'Cannot specify both model and engine', 'type': 'invalid_request_error', 'param': None, 'code': None}}
Run Code Online (Sandbox Code Playgroud)
我尝试过不同的 API 密钥,但没有成功。我什至查找了 chatgpt 的所有不同型号,但它仍然不起作用
当收到来自 OpenAI 模型的响应时text-davinci-003,我能够使用以下 PHP 代码从响应中提取文本:
$response = $response->choices[0]->text;
Run Code Online (Sandbox Code Playgroud)
这是text-davinci-003响应代码:
{
"id": "cmpl-uqkvlQyYK7bGYrRHQ0eXlWi7",
"object": "text_completion",
"created": 1589478378,
"model": "text-davinci-003",
"choices": [
{
"text": "\n\nThis is indeed a test",
"index": 0,
"logprobs": null,
"finish_reason": "length"
}
],
"usage": {
"prompt_tokens": 5,
"completion_tokens": 7,
"total_tokens": 12
}
}
Run Code Online (Sandbox Code Playgroud)
我现在尝试更改我的代码以使用最近发布的gpt-3.5-turbo模型,该模型返回的响应略有不同:
{
"id": "chatcmpl-123",
"object": "chat.completion",
"created": 1677652288,
"choices": [{
"index": 0,
"message": {
"role": "assistant",
"content": "\n\nHello there, how may I assist you today?",
},
"finish_reason": "stop"
}], …Run Code Online (Sandbox Code Playgroud) 我正在尝试对新发布的模型执行 API 调用gpt-3.5-turbo,并具有以下代码,该代码$query应向 API 发送查询(通过变量),然后从 API 中提取响应消息的内容。
但我每次通话都收到空响应。有什么想法我做错了什么吗?
$ch = curl_init();
$query = "What is the capital city of England?";
$url = 'https://api.openai.com/v1/chat/completions';
$api_key = 'sk-**************************************';
$post_fields = [
"model" => "gpt-3.5-turbo",
"messages" => ["role" => "user","content" => $query],
"max_tokens" => 500,
"temperature" => 0.8
];
$header = [
'Content-Type: application/json',
'Authorization: Bearer ' . $api_key
];
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($post_fields));
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
$result = curl_exec($ch);
if …Run Code Online (Sandbox Code Playgroud) 我正在使用 OpenAI 来了解有关 API 集成的更多信息,但在运行 Python 程序时我不断运行此代码。我向 ChatGPT 询问了该Invalid URL (POST /v1/engines/gpt-3.5-turbo/chat/completions)错误,但它似乎没有给我正确的解决方案。
注意:我确实安装了最新的 OpenAI 软件包(即0.27.4)。
代码:
import os
import openai
openai.api_key = "sk-xxxxxxxxxxxxxxxxxxxx"
messages = [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Tell me a joke."}
]
response = openai.ChatCompletion.create(
engine="gpt-3.5-turbo",
messages=messages,
max_tokens=50,
n=1,
stop=None,
temperature=0.7,
)
joke = response.choices[0].text.strip()
print(joke)
Run Code Online (Sandbox Code Playgroud) 我刚刚开始使用法学硕士,特别是 OpenAI 和其他 OSS 模型。有很多关于使用 LlamaIndex 创建所有文档的存储然后查询它们的指南。我用一些示例文档进行了尝试,但发现每个查询很快就会变得非常昂贵。我想我使用了 50 页的 PDF 文档,摘要查询每次查询花费了大约 1.5 美元。我看到有很多令牌被发送,所以我假设它为每个查询发送整个文档。考虑到有人可能想要使用数以千万计的记录,我看不出像 LlamaIndex 这样的东西如何能够以经济高效的方式真正发挥作用。
另一方面,我看到 OpenAI 允许你训练 ChatGPT 模型。或者使用其他经过定制培训的法学硕士来查询您自己的数据不是更便宜、更有效吗?我为什么要设置 LlamaIndex?
openai-api ×12
chatgpt-api ×8
gpt-3 ×6
python ×5
gpt-4 ×2
php ×2
python-3.x ×2
curl ×1
javascript ×1
json ×1
langchain ×1
llama-index ×1
node.js ×1
reactjs ×1