Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

APIConnectionError #271

Open
pluto-tu opened this issue Mar 19, 2024 · 6 comments
Open

APIConnectionError #271

pluto-tu opened this issue Mar 19, 2024 · 6 comments

Comments

@pluto-tu
Copy link

Hi ,I can call openai api interface with my api key ,but when i run ,it error. can you show how did you slove this problem.
api example:
curl https://api.openai.com/v1/chat/completions
-H "Content-Type: application/json"
-H "Authorization: Bearer key"
-d '{
"model": "gpt-3.5-turbo",
"messages": [{"role": "user", "content": "how to use mysql!"}],
"temperature": 0.7
}'

when run generate code :
pypoetry/virtualenvs/backend-FuQBPevx-py3.11/lib/python3.11/site-packages/openai/_base_client.py", line 1504, in _request
raise APIConnectionError(request=request) from err
openai.APIConnectionError: Connection error.

@abi
Copy link
Owner

abi commented Mar 19, 2024

@pluto-tu so you're seeing the curl works but generate code doesn't work? Are both running locally?

@pluto-tu
Copy link
Author

@pluto-tu so you're seeing the curl works but generate code doesn't work? Are both running locally?

yes , both running locally . example is
`❯ curl https://api.openai.com/v1/chat/completions
-H "Content-Type: application/json"
-H "Authorization: Bearer key"
-d '{
"model": "gpt-3.5-turbo",
"messages": [{"role": "user", "content": "how to use mysql!"}],
"temperature": 0.7
}'

{
"id": "cxxxxxx",
"object": "chat.completion",
"created": 1710945410,
"model": "gpt-3.5-turbo-0125",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "To use MySQL, you will need to follow these steps:\n\n1. Install MySQL: Download and install MySQL from the official website. Make sure to choose the appropriate version for your operating system.\n\n2. Start MySQL server: Once installed, start the MySQL server by running the appropriate command or service.\n\n3. Access MySQL shell: You can access the MySQL shell by running the command mysql -u username -p. Replace username with your MySQL username.\n\n4. Create a database: To create a new database, use the command CREATE DATABASE database_name;.\n\n5. Select a database: To select a database to work with, use the command USE database_name;.\n\n6. Create tables: To create tables within the selected database, use the CREATE TABLE command.\n\n7. Insert data: Use the INSERT INTO command to insert data into the tables.\n\n8. Query data: Use the SELECT command to query data from the tables.\n\n9. Update and delete data: Use the UPDATE and DELETE commands to update and delete data from the tables.\n\n10. Manage users: Use the CREATE USER, GRANT, and REVOKE commands to manage users and their privileges.\n\nThese are basic steps to get started with using MySQL. There are many more advanced features and commands you can explore as you become more familiar with the database management system."
},
"logprobs": null,
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 12,
"completion_tokens": 282,
"total_tokens": 294
},
"system_fingerprint": "xxxx"
}`

@abi
Copy link
Owner

abi commented Mar 20, 2024

Hmm, I'm really unsure what could be causing the issue then. You could try specifying the base URL with the env var described in the README. I think it needs to be "https://api.openai.com/v1" or "https://api.openai.com"

Are you running this code within Docker or in your default OS?

You could also try asking people on https://github.com/openai/openai-python to help since that's the library we use.

Let me know if you figure out a solution.

@pluto-tu
Copy link
Author

I try now

@pluto-tu
Copy link
Author

same error ,I will to submit issue on https://github.com/openai/openai-python

File "/Users/xxx/Library/Caches/pypoetry/virtualenvs/backend-FuQBPevx-py3.11/lib/python3.11/site-packages/openai/_base_client.py", line 1494, in _request
return await self._retry_request(
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/xxx/Library/Caches/pypoetry/virtualenvs/backend-FuQBPevx-py3.11/lib/python3.11/site-packages/openai/_base_client.py", line 1563, in _retry_request
return await self._request(
^^^^^^^^^^^^^^^^^^^^
File "/Users/xxxx/Library/Caches/pypoetry/virtualenvs/backend-FuQBPevx-py3.11/lib/python3.11/site-packages/openai/_base_client.py", line 1504, in _request
raise APIConnectionError(request=request) from err
openai.APIConnectionError: Connection error.

@penelope1234564867
Copy link

I meet this error too,how you solve it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants