我正在尝试使用 OpenAI Python SDK,我通过 pip 安装了最新版本,并验证了它是通过 pip list 安装的。现在,当我运行代码并发出一个简单的请求时,我收到一个错误,提示存在我以前从未见过的循环导入。
from openai import OpenAI
client = OpenAI()
response = client.chat.completions.create(
model="gpt-3.5-turbo",
response_format={"type": "json_object"},
messages=[
{
"role": "system",
"content": "You are a helpful assistant designed to output JSON.",
},
{"role": "user", "content": "Who won the world series in 2020?"},
],
)
print(response.content)
Run Code Online (Sandbox Code Playgroud)
这是错误:
ImportError: cannot import name 'OpenAI' from partially initialized module 'openai' (most likely due to a circular import) (.../.pyenv/versions/3.11.5/lib/python3.11/site-packages/openai/__init__.py)
Run Code Online (Sandbox Code Playgroud) 我想知道我是否可以在文本分类问题中使用 OpenAI GPT-3 进行迁移学习?如果是这样,我如何使用 Tensorflow、Keras 开始它。
text-classification keras transfer-learning openai-api gpt-3
我安装了 Node 16.13.1,并使用“npm install -g openai”全局安装了 openai。我使用以下命令将包导入到脚本中:
const { Configuration, OpenAIApi } = require('openai')
Run Code Online (Sandbox Code Playgroud)
但是,当我运行脚本时,出现以下错误:
PS D:\Projects\OpenAI-Chat> node conversation.js
node:internal/modules/cjs/loader:936
throw err;
^
Error: Cannot find module 'openai'
Require stack:
- D:\Projects\OpenAI-Chat\conversation.js
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
at Function.Module._load (node:internal/modules/cjs/loader:778:27)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.<anonymous> (D:\Projects\OpenAI-Chat\conversation.js:1:38)
at Module._compile (node:internal/modules/cjs/loader:1101:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12) {
code: 'MODULE_NOT_FOUND',
requireStack: [ 'D:\\Projects\\OpenAI-Chat\\conversation.js' ]
}
Run Code Online (Sandbox Code Playgroud)
我该如何解决?
在 openai.py 中,Completion.create 突出显示为警报,但也不起作用。错误就在下面。代码有什么问题
response = openai.Completion.create(
engine="text-davinci-002",
prompt="Generate blog topic on: Ethical hacking",
temperature=0.7,
max_tokens=256,
top_p=1,
frequency_penalty=0,
presence_penalty=0
)
$ python openai.py
Traceback (most recent call last):
File "E:\python\openAI\openai.py", line 2, in <module>
import openai
File "E:\python\openAI\openai.py", line 9, in <module>
response = openai.Completion.create(
AttributeError: partially initialized module 'openai' has no attribute 'Completion' (most likely due to a circular import)
Run Code Online (Sandbox Code Playgroud) 我正在使用 WSL2 和 Ubuntu 20.4,我使用 (venv) 创建一个新的虚拟环境,并按照 OpenAI 官方页面所述安装gym-retro ( https://retro.readthedocs.io/en/latest/getting_started.html ),使用以下命令:
pip3 install gym-retro
我在安装它时没有收到错误,然后为了测试它,我运行命令(如前面提到的入门页面中所述):
python3 -m retro.examples.interactive --game Airstriker-Genesis
并得到以下错误:
有人能帮帮我吗?
我还使用最简单的实现(调用retro.make("Game-name"))对其进行了测试,并且也遇到了相同的错误。
因此,我正在亲身体验已公开的 Python 的新 DALL.E api。我收到归因错误,因为运行以下代码后未检测到 Open ai 中的图像模型:
response = openai.Image.create(
prompt="a white siamese cat",
n=1,
size="1024x1024"
)
image_url = response['data'][0]['url']
Run Code Online (Sandbox Code Playgroud)
为什么我会收到此错误?
我有一个包含大量数据的 SQL 表,需要使用 Chat Completion API 将 SQL 表数据训练到 ChatGPT。
我尝试使用 ChatGPT 生成 SQL 查询,但这无法按预期工作。有时它会生成不适当的查询。
我正在尝试创建一个简单的函数,它将接受消息(字符串)并将其传递给openai.ChatCompletion.create(),但是当我使用 F 字符串时,它会返回一个对象错误。对调试Python不太熟悉,所以我有点卡在这里。
def get_response(message):
response = openai.ChatCompletion.create(
model = 'gpt-3.5-turbo',
temperature = 1,
messages = [
f"{{'role': 'user', 'content': '{message}'}}"
]
)
return response.choices[0]["message"]["content"]
# get_response('What is 2 + 2?')
Run Code Online (Sandbox Code Playgroud)
它返回:
InvalidRequestError: "{'role': 'user', 'content': 'What is 2 + 2?'}" is not of type 'object' - 'messages.0'
Run Code Online (Sandbox Code Playgroud)
我想我可能需要将字符串转换为openai已创建的某个独特的类,但我不太确定如何执行。查看了源代码,但找不到对该类的引用。
我正在开发一个 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) openai-api ×10
python ×5
chatgpt-api ×3
gpt-3 ×2
javascript ×2
node.js ×2
gpt-4 ×1
keras ×1
npm ×1
openai-gym ×1
reactjs ×1