ChatGPT
ChatGPT copied to clipboard
Connection error
CODE 1:
import openai
openai.api_key = '' # For self-hosted version you can leave it empty
openai.base_url = "http://localhost:3040/v1" # For self-hosted version, use "http://localhost:3040/v1"
completion = openai.chat.completions.create(
model="gpt-3.5-turbo",
messages=[
{"role": "user", "content": "How do I list all files in a directory using Python?"},
],
)
print(completion.choices[0].message.content)
Error 1
(env) PS E:\DEV\Chatgpt test> py .\main.py
Traceback (most recent call last):
File "E:\DEV\Chatgpt test\env\Lib\site-packages\httpx\_transports\default.py", line 69, in map_httpcore_exceptions
yield
File "E:\DEV\Chatgpt test\env\Lib\site-packages\httpx\_transports\default.py", line 233, in handle_request
resp = self._pool.handle_request(req)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "E:\DEV\Chatgpt test\env\Lib\site-packages\httpcore\_sync\connection_pool.py", line 216, in handle_request
raise exc from None
File "E:\DEV\Chatgpt test\env\Lib\site-packages\httpcore\_sync\connection_pool.py", line 196, in handle_request
response = connection.handle_request(
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "E:\DEV\Chatgpt test\env\Lib\site-packages\httpcore\_sync\connection.py", line 101, in handle_request
return self._connection.handle_request(request)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "E:\DEV\Chatgpt test\env\Lib\site-packages\httpcore\_sync\http11.py", line 143, in handle_request
raise exc
File "E:\DEV\Chatgpt test\env\Lib\site-packages\httpcore\_sync\http11.py", line 93, in handle_request
self._send_request_headers(**kwargs)
File "E:\DEV\Chatgpt test\env\Lib\site-packages\httpcore\_sync\http11.py", line 151, in _send_request_headers
with map_exceptions({h11.LocalProtocolError: LocalProtocolError}):
File "C:\Python312\Lib\contextlib.py", line 155, in __exit__
self.gen.throw(value)
File "E:\DEV\Chatgpt test\env\Lib\site-packages\httpcore\_exceptions.py", line 14, in map_exceptions
raise to_exc(exc) from exc
httpcore.LocalProtocolError: Illegal header value b'Bearer '
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "E:\DEV\Chatgpt test\env\Lib\site-packages\openai\_base_client.py", line 931, in _request
response = self._client.send(
^^^^^^^^^^^^^^^^^^
File "E:\DEV\Chatgpt test\env\Lib\site-packages\httpx\_client.py", line 914, in send
response = self._send_handling_auth(
^^^^^^^^^^^^^^^^^^^^^^^^^
File "E:\DEV\Chatgpt test\env\Lib\site-packages\httpx\_client.py", line 942, in _send_handling_auth
response = self._send_handling_redirects(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "E:\DEV\Chatgpt test\env\Lib\site-packages\httpx\_client.py", line 979, in _send_handling_redirects
response = self._send_single_request(request)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "E:\DEV\Chatgpt test\env\Lib\site-packages\httpx\_client.py", line 1015, in _send_single_request
response = transport.handle_request(request)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "E:\DEV\Chatgpt test\env\Lib\site-packages\httpx\_transports\default.py", line 232, in handle_request
with map_httpcore_exceptions():
File "C:\Python312\Lib\contextlib.py", line 155, in __exit__
self.gen.throw(value)
File "E:\DEV\Chatgpt test\env\Lib\site-packages\httpx\_transports\default.py", line 86, in map_httpcore_exceptions
raise mapped_exc(message) from exc
httpx.LocalProtocolError: Illegal header value b'Bearer '
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "E:\DEV\Chatgpt test\main.py", line 6, in <module>
completion = openai.chat.completions.create(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "E:\DEV\Chatgpt test\env\Lib\site-packages\openai\_utils\_utils.py", line 275, in wrapper
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "E:\DEV\Chatgpt test\env\Lib\site-packages\openai\resources\chat\completions.py", line 667, in create
return self._post(
^^^^^^^^^^^
File "E:\DEV\Chatgpt test\env\Lib\site-packages\openai\_base_client.py", line 1213, in post
return cast(ResponseT, self.request(cast_to, opts, stream=stream, stream_cls=stream_cls))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "E:\DEV\Chatgpt test\env\Lib\site-packages\openai\_base_client.py", line 902, in request
return self._request(
^^^^^^^^^^^^^^
File "E:\DEV\Chatgpt test\env\Lib\site-packages\openai\_base_client.py", line 955, in _request
return self._retry_request(
^^^^^^^^^^^^^^^^^^^^
File "E:\DEV\Chatgpt test\env\Lib\site-packages\openai\_base_client.py", line 1026, in _retry_request
return self._request(
^^^^^^^^^^^^^^
File "E:\DEV\Chatgpt test\env\Lib\site-packages\openai\_base_client.py", line 955, in _request
return self._retry_request(
^^^^^^^^^^^^^^^^^^^^
File "E:\DEV\Chatgpt test\env\Lib\site-packages\openai\_base_client.py", line 1026, in _retry_request
return self._request(
^^^^^^^^^^^^^^
File "E:\DEV\Chatgpt test\env\Lib\site-packages\openai\_base_client.py", line 965, in _request
raise APIConnectionError(request=request) from err
openai.APIConnectionError: Connection error.
CODE 2:
import openai
openai.api_key = 'stringexample' # For self-hosted version you can leave it empty
openai.base_url = "http://localhost:3040/v1" # For self-hosted version, use "http://localhost:3040/v1"
completion = openai.chat.completions.create(
model="gpt-3.5-turbo",
messages=[
{"role": "user", "content": "How do I list all files in a directory using Python?"},
],
)
print(completion.choices[0].message.content)
ERROR 2:
(env) PS E:\DEV\Chatgpt test> py .\main.py
Traceback (most recent call last):
File "E:\DEV\Chatgpt test\main.py", line 6, in <module>
completion = openai.chat.completions.create(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "E:\DEV\Chatgpt test\env\Lib\site-packages\openai\_utils\_utils.py", line 275, in wrapper
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "E:\DEV\Chatgpt test\env\Lib\site-packages\openai\resources\chat\completions.py", line 667, in create
return self._post(
^^^^^^^^^^^
File "E:\DEV\Chatgpt test\env\Lib\site-packages\openai\_base_client.py", line 1213, in post
return cast(ResponseT, self.request(cast_to, opts, stream=stream, stream_cls=stream_cls))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "E:\DEV\Chatgpt test\env\Lib\site-packages\openai\_base_client.py", line 902, in request
return self._request(
^^^^^^^^^^^^^^
File "E:\DEV\Chatgpt test\env\Lib\site-packages\openai\_base_client.py", line 993, in _request
raise self._make_status_error_from_response(err.response) from None
openai.NotFoundError: Error code: 404 - {'status': False, 'error': {'message': 'The requested endpoint was not found. please make sure to use "http://localhost:3040/v1" as the base URL.', 'type': 'invalid_request_error'},
'support': 'https://discord.pawan.krd'}
(env) PS E:\DEV\Chatgpt test>
Use http://localhost:3040/v1/
(a slash at the end is needed).
npm start
[email protected] start tsc && node dist/app.js
src/app.ts:1:58 - error TS2307: Cannot find module 'express' or its corresponding type declarations.
1 import express, { Request, Response, NextFunction } from "express"; ~~~~~~~~~
src/app.ts:2:24 - error TS2307: Cannot find module 'body-parser' or its corresponding type declarations.
2 import bodyParser from "body-parser"; ~~~~~~~~~~~~~
src/app.ts:3:19 - error TS2307: Cannot find module 'axios' or its corresponding type declarations.
3 import axios from "axios"; ~~~~~~~
src/app.ts:4:19 - error TS2307: Cannot find module 'https' or its corresponding type declarations.
4 import https from "https"; ~~~~~~~
src/app.ts:5:28 - error TS2307: Cannot find module 'crypto' or its corresponding type declarations.
5 import { randomUUID } from "crypto"; ~~~~~~~~
src/app.ts:35:23 - error TS2580: Cannot find name 'Buffer'. Do you need to install type definitions for node? Try npm i --save-dev @types/node
.
35 const bufferChunk = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk); ~~~~~~
src/app.ts:35:56 - error TS2580: Cannot find name 'Buffer'. Do you need to install type definitions for node? Try npm i --save-dev @types/node
.
35 const bufferChunk = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk); ~~~~~~
Found 7 errors in the same file, starting at: src/app.ts:1
@Ptagdam, there are no errors, you need to install the dependencies first.
Run the start.bat or start.sh file as I mentioned in the instructions,
or execute npm install
before npm start
.
@Ptagdam, there are no errors, you need to install the dependencies first.
Run the start.bat or start.sh file as I mentioned in the instructions, or execute
npm install
beforenpm start
. Again same error
@Ptagdam, please follow the instructions. Make sure you have Node.js version 19 or later. delete node_modules
folder if exists, Use the start file (start.bat for Windows and start.sh for Linux). If you encounter any errors when executing the start file, show them to me.