ConnectionRefusedError with ai assistant client code example
#3
by
Sdspieg
- opened
Having loaded gemma-2b-it-q8_0.gguf and started a local inference server, I tried the suggested client code example for ai assistant (python) in a Jupyter Notebook.
# Chat with an intelligent assistant in your terminal
from openai import OpenAI
# Point to the local server
client = OpenAI(base_url="http://localhost:2345/v1", api_key="not-needed")
history = [
{"role": "system", "content": "You are an intelligent assistant. You always provide well-reasoned answers that are both correct and helpful."},
{"role": "user", "content": "Hello, introduce yourself to someone opening this program for the first time. Be concise."},
]
while True:
completion = client.chat.completions.create(
model="local-model", # this field is currently unused
messages=history,
temperature=0.7,
stream=True,
)
new_message = {"role": "assistant", "content": ""}
for chunk in completion:
if chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="", flush=True)
new_message["content"] += chunk.choices[0].delta.content
history.append(new_message)
# Uncomment to see chat history
# import json
# gray_color = "\033[90m"
# reset_color = "\033[0m"
# print(f"{gray_color}\n{'-'*20} History dump {'-'*20}\n")
# print(json.dumps(history, indent=2))
# print(f"\n{'-'*55}\n{reset_color}")
print()
history.append({"role": "user", "content": input("> ")})
'''
But this throws
'''
{
"name": "APIConnectionError",
"message": "Connection error.",
"stack": "---------------------------------------------------------------------------
ConnectionRefusedError Traceback (most recent call last)
File ~/miniconda3/envs/llmware/lib/python3.10/site-packages/httpcore/_exceptions.py:10, in map_exceptions(map)
9 try:
---> 10 yield
11 except Exception as exc: # noqa: PIE786
File ~/miniconda3/envs/llmware/lib/python3.10/site-packages/httpcore/_backends/sync.py:206, in SyncBackend.connect_tcp(self, host, port, timeout, local_address, socket_options)
205 with map_exceptions(exc_map):
--> 206 sock = socket.create_connection(
207 address,
208 timeout,
209 source_address=source_address,
210 )
211 for option in socket_options:
File ~/miniconda3/envs/llmware/lib/python3.10/socket.py:845, in create_connection(address, timeout, source_address)
844 try:
--> 845 raise err
846 finally:
847 # Break explicitly a reference cycle
File ~/miniconda3/envs/llmware/lib/python3.10/socket.py:833, in create_connection(address, timeout, source_address)
832 sock.bind(source_address)
--> 833 sock.connect(sa)
834 # Break explicitly a reference cycle
ConnectionRefusedError: [Errno 111] Connection refused
The above exception was the direct cause of the following exception:
ConnectError Traceback (most recent call last)
File ~/miniconda3/envs/llmware/lib/python3.10/site-packages/httpx/_transports/default.py:66, in map_httpcore_exceptions()
65 try:
---> 66 yield
67 except Exception as exc:
File ~/miniconda3/envs/llmware/lib/python3.10/site-packages/httpx/_transports/default.py:228, in HTTPTransport.handle_request(self, request)
227 with map_httpcore_exceptions():
--> 228 resp = self._pool.handle_request(req)
230 assert isinstance(resp.stream, typing.Iterable)
File ~/miniconda3/envs/llmware/lib/python3.10/site-packages/httpcore/_sync/connection_pool.py:268, in ConnectionPool.handle_request(self, request)
267 self.response_closed(status)
--> 268 raise exc
269 else:
File ~/miniconda3/envs/llmware/lib/python3.10/site-packages/httpcore/_sync/connection_pool.py:251, in ConnectionPool.handle_request(self, request)
250 try:
--> 251 response = connection.handle_request(request)
252 except ConnectionNotAvailable:
253 # The ConnectionNotAvailable exception is a special case, that
254 # indicates we need to retry the request on a new connection.
(...)
258 # might end up as an HTTP/2 connection, but which actually ends
259 # up as HTTP/1.1.
File ~/miniconda3/envs/llmware/lib/python3.10/site-packages/httpcore/_sync/connection.py:99, in HTTPConnection.handle_request(self, request)
98 self._connect_failed = True
---> 99 raise exc
100 elif not self._connection.is_available():
File ~/miniconda3/envs/llmware/lib/python3.10/site-packages/httpcore/_sync/connection.py:76, in HTTPConnection.handle_request(self, request)
75 try:
---> 76 stream = self._connect(request)
78 ssl_object = stream.get_extra_info(\"ssl_object\")
File ~/miniconda3/envs/llmware/lib/python3.10/site-packages/httpcore/_sync/connection.py:124, in HTTPConnection._connect(self, request)
123 with Trace(\"connect_tcp\", logger, request, kwargs) as trace:
--> 124 stream = self._network_backend.connect_tcp(**kwargs)
125 trace.return_value = stream
File ~/miniconda3/envs/llmware/lib/python3.10/site-packages/httpcore/_backends/sync.py:205, in SyncBackend.connect_tcp(self, host, port, timeout, local_address, socket_options)
200 exc_map: ExceptionMapping = {
201 socket.timeout: ConnectTimeout,
202 OSError: ConnectError,
203 }
--> 205 with map_exceptions(exc_map):
206 sock = socket.create_connection(
207 address,
208 timeout,
209 source_address=source_address,
210 )
File ~/miniconda3/envs/llmware/lib/python3.10/contextlib.py:153, in _GeneratorContextManager.__exit__(self, typ, value, traceback)
152 try:
--> 153 self.gen.throw(typ, value, traceback)
154 except StopIteration as exc:
155 # Suppress StopIteration *unless* it's the same exception that
156 # was passed to throw(). This prevents a StopIteration
157 # raised inside the \"with\" statement from being suppressed.
File ~/miniconda3/envs/llmware/lib/python3.10/site-packages/httpcore/_exceptions.py:14, in map_exceptions(map)
13 if isinstance(exc, from_exc):
---> 14 raise to_exc(exc) from exc
15 raise
ConnectError: [Errno 111] Connection refused
The above exception was the direct cause of the following exception:
ConnectError Traceback (most recent call last)
File ~/miniconda3/envs/llmware/lib/python3.10/site-packages/openai/_base_client.py:877, in SyncAPIClient._request(self, cast_to, options, remaining_retries, stream, stream_cls)
876 try:
--> 877 response = self._client.send(
878 request,
879 auth=self.custom_auth,
880 stream=stream or self._should_stream_response_body(request=request),
881 )
882 except httpx.TimeoutException as err:
File ~/miniconda3/envs/llmware/lib/python3.10/site-packages/httpx/_client.py:901, in Client.send(self, request, stream, auth, follow_redirects)
899 auth = self._build_request_auth(request, auth)
--> 901 response = self._send_handling_auth(
902 request,
903 auth=auth,
904 follow_redirects=follow_redirects,
905 history=[],
906 )
907 try:
File ~/miniconda3/envs/llmware/lib/python3.10/site-packages/httpx/_client.py:929, in Client._send_handling_auth(self, request, auth, follow_redirects, history)
928 while True:
--> 929 response = self._send_handling_redirects(
930 request,
931 follow_redirects=follow_redirects,
932 history=history,
933 )
934 try:
File ~/miniconda3/envs/llmware/lib/python3.10/site-packages/httpx/_client.py:966, in Client._send_handling_redirects(self, request, follow_redirects, history)
964 hook(request)
--> 966 response = self._send_single_request(request)
967 try:
File ~/miniconda3/envs/llmware/lib/python3.10/site-packages/httpx/_client.py:1002, in Client._send_single_request(self, request)
1001 with request_context(request=request):
-> 1002 response = transport.handle_request(request)
1004 assert isinstance(response.stream, SyncByteStream)
File ~/miniconda3/envs/llmware/lib/python3.10/site-packages/httpx/_transports/default.py:227, in HTTPTransport.handle_request(self, request)
215 req = httpcore.Request(
216 method=request.method,
217 url=httpcore.URL(
(...)
225 extensions=request.extensions,
226 )
--> 227 with map_httpcore_exceptions():
228 resp = self._pool.handle_request(req)
File ~/miniconda3/envs/llmware/lib/python3.10/contextlib.py:153, in _GeneratorContextManager.__exit__(self, typ, value, traceback)
152 try:
--> 153 self.gen.throw(typ, value, traceback)
154 except StopIteration as exc:
155 # Suppress StopIteration *unless* it's the same exception that
156 # was passed to throw(). This prevents a StopIteration
157 # raised inside the \"with\" statement from being suppressed.
File ~/miniconda3/envs/llmware/lib/python3.10/site-packages/httpx/_transports/default.py:83, in map_httpcore_exceptions()
82 message = str(exc)
---> 83 raise mapped_exc(message) from exc
ConnectError: [Errno 111] Connection refused
During handling of the above exception, another exception occurred:
ConnectionRefusedError Traceback (most recent call last)
File ~/miniconda3/envs/llmware/lib/python3.10/site-packages/httpcore/_exceptions.py:10, in map_exceptions(map)
9 try:
---> 10 yield
11 except Exception as exc: # noqa: PIE786
File ~/miniconda3/envs/llmware/lib/python3.10/site-packages/httpcore/_backends/sync.py:206, in SyncBackend.connect_tcp(self, host, port, timeout, local_address, socket_options)
205 with map_exceptions(exc_map):
--> 206 sock = socket.create_connection(
207 address,
208 timeout,
209 source_address=source_address,
210 )
211 for option in socket_options:
File ~/miniconda3/envs/llmware/lib/python3.10/socket.py:845, in create_connection(address, timeout, source_address)
844 try:
--> 845 raise err
846 finally:
847 # Break explicitly a reference cycle
File ~/miniconda3/envs/llmware/lib/python3.10/socket.py:833, in create_connection(address, timeout, source_address)
832 sock.bind(source_address)
--> 833 sock.connect(sa)
834 # Break explicitly a reference cycle
ConnectionRefusedError: [Errno 111] Connection refused
The above exception was the direct cause of the following exception:
ConnectError Traceback (most recent call last)
File ~/miniconda3/envs/llmware/lib/python3.10/site-packages/httpx/_transports/default.py:66, in map_httpcore_exceptions()
65 try:
---> 66 yield
67 except Exception as exc:
File ~/miniconda3/envs/llmware/lib/python3.10/site-packages/httpx/_transports/default.py:228, in HTTPTransport.handle_request(self, request)
227 with map_httpcore_exceptions():
--> 228 resp = self._pool.handle_request(req)
230 assert isinstance(resp.stream, typing.Iterable)
File ~/miniconda3/envs/llmware/lib/python3.10/site-packages/httpcore/_sync/connection_pool.py:268, in ConnectionPool.handle_request(self, request)
267 self.response_closed(status)
--> 268 raise exc
269 else:
File ~/miniconda3/envs/llmware/lib/python3.10/site-packages/httpcore/_sync/connection_pool.py:251, in ConnectionPool.handle_request(self, request)
250 try:
--> 251 response = connection.handle_request(request)
252 except ConnectionNotAvailable:
253 # The ConnectionNotAvailable exception is a special case, that
254 # indicates we need to retry the request on a new connection.
(...)
258 # might end up as an HTTP/2 connection, but which actually ends
259 # up as HTTP/1.1.
File ~/miniconda3/envs/llmware/lib/python3.10/site-packages/httpcore/_sync/connection.py:99, in HTTPConnection.handle_request(self, request)
98 self._connect_failed = True
---> 99 raise exc
100 elif not self._connection.is_available():
File ~/miniconda3/envs/llmware/lib/python3.10/site-packages/httpcore/_sync/connection.py:76, in HTTPConnection.handle_request(self, request)
75 try:
---> 76 stream = self._connect(request)
78 ssl_object = stream.get_extra_info(\"ssl_object\")
File ~/miniconda3/envs/llmware/lib/python3.10/site-packages/httpcore/_sync/connection.py:124, in HTTPConnection._connect(self, request)
123 with Trace(\"connect_tcp\", logger, request, kwargs) as trace:
--> 124 stream = self._network_backend.connect_tcp(**kwargs)
125 trace.return_value = stream
File ~/miniconda3/envs/llmware/lib/python3.10/site-packages/httpcore/_backends/sync.py:205, in SyncBackend.connect_tcp(self, host, port, timeout, local_address, socket_options)
200 exc_map: ExceptionMapping = {
201 socket.timeout: ConnectTimeout,
202 OSError: ConnectError,
203 }
--> 205 with map_exceptions(exc_map):
206 sock = socket.create_connection(
207 address,
208 timeout,
209 source_address=source_address,
210 )
File ~/miniconda3/envs/llmware/lib/python3.10/contextlib.py:153, in _GeneratorContextManager.__exit__(self, typ, value, traceback)
152 try:
--> 153 self.gen.throw(typ, value, traceback)
154 except StopIteration as exc:
155 # Suppress StopIteration *unless* it's the same exception that
156 # was passed to throw(). This prevents a StopIteration
157 # raised inside the \"with\" statement from being suppressed.
File ~/miniconda3/envs/llmware/lib/python3.10/site-packages/httpcore/_exceptions.py:14, in map_exceptions(map)
13 if isinstance(exc, from_exc):
---> 14 raise to_exc(exc) from exc
15 raise
ConnectError: [Errno 111] Connection refused
The above exception was the direct cause of the following exception:
ConnectError Traceback (most recent call last)
File ~/miniconda3/envs/llmware/lib/python3.10/site-packages/openai/_base_client.py:877, in SyncAPIClient._request(self, cast_to, options, remaining_retries, stream, stream_cls)
876 try:
--> 877 response = self._client.send(
878 request,
879 auth=self.custom_auth,
880 stream=stream or self._should_stream_response_body(request=request),
881 )
882 except httpx.TimeoutException as err:
File ~/miniconda3/envs/llmware/lib/python3.10/site-packages/httpx/_client.py:901, in Client.send(self, request, stream, auth, follow_redirects)
899 auth = self._build_request_auth(request, auth)
--> 901 response = self._send_handling_auth(
902 request,
903 auth=auth,
904 follow_redirects=follow_redirects,
905 history=[],
906 )
907 try:
File ~/miniconda3/envs/llmware/lib/python3.10/site-packages/httpx/_client.py:929, in Client._send_handling_auth(self, request, auth, follow_redirects, history)
928 while True:
--> 929 response = self._send_handling_redirects(
930 request,
931 follow_redirects=follow_redirects,
932 history=history,
933 )
934 try:
File ~/miniconda3/envs/llmware/lib/python3.10/site-packages/httpx/_client.py:966, in Client._send_handling_redirects(self, request, follow_redirects, history)
964 hook(request)
--> 966 response = self._send_single_request(request)
967 try:
File ~/miniconda3/envs/llmware/lib/python3.10/site-packages/httpx/_client.py:1002, in Client._send_single_request(self, request)
1001 with request_context(request=request):
-> 1002 response = transport.handle_request(request)
1004 assert isinstance(response.stream, SyncByteStream)
File ~/miniconda3/envs/llmware/lib/python3.10/site-packages/httpx/_transports/default.py:227, in HTTPTransport.handle_request(self, request)
215 req = httpcore.Request(
216 method=request.method,
217 url=httpcore.URL(
(...)
225 extensions=request.extensions,
226 )
--> 227 with map_httpcore_exceptions():
228 resp = self._pool.handle_request(req)
File ~/miniconda3/envs/llmware/lib/python3.10/contextlib.py:153, in _GeneratorContextManager.__exit__(self, typ, value, traceback)
152 try:
--> 153 self.gen.throw(typ, value, traceback)
154 except StopIteration as exc:
155 # Suppress StopIteration *unless* it's the same exception that
156 # was passed to throw(). This prevents a StopIteration
157 # raised inside the \"with\" statement from being suppressed.
File ~/miniconda3/envs/llmware/lib/python3.10/site-packages/httpx/_transports/default.py:83, in map_httpcore_exceptions()
82 message = str(exc)
---> 83 raise mapped_exc(message) from exc
ConnectError: [Errno 111] Connection refused
During handling of the above exception, another exception occurred:
ConnectionRefusedError Traceback (most recent call last)
File ~/miniconda3/envs/llmware/lib/python3.10/site-packages/httpcore/_exceptions.py:10, in map_exceptions(map)
9 try:
---> 10 yield
11 except Exception as exc: # noqa: PIE786
File ~/miniconda3/envs/llmware/lib/python3.10/site-packages/httpcore/_backends/sync.py:206, in SyncBackend.connect_tcp(self, host, port, timeout, local_address, socket_options)
205 with map_exceptions(exc_map):
--> 206 sock = socket.create_connection(
207 address,
208 timeout,
209 source_address=source_address,
210 )
211 for option in socket_options:
File ~/miniconda3/envs/llmware/lib/python3.10/socket.py:845, in create_connection(address, timeout, source_address)
844 try:
--> 845 raise err
846 finally:
847 # Break explicitly a reference cycle
File ~/miniconda3/envs/llmware/lib/python3.10/socket.py:833, in create_connection(address, timeout, source_address)
832 sock.bind(source_address)
--> 833 sock.connect(sa)
834 # Break explicitly a reference cycle
ConnectionRefusedError: [Errno 111] Connection refused
The above exception was the direct cause of the following exception:
ConnectError Traceback (most recent call last)
File ~/miniconda3/envs/llmware/lib/python3.10/site-packages/httpx/_transports/default.py:66, in map_httpcore_exceptions()
65 try:
---> 66 yield
67 except Exception as exc:
File ~/miniconda3/envs/llmware/lib/python3.10/site-packages/httpx/_transports/default.py:228, in HTTPTransport.handle_request(self, request)
227 with map_httpcore_exceptions():
--> 228 resp = self._pool.handle_request(req)
230 assert isinstance(resp.stream, typing.Iterable)
File ~/miniconda3/envs/llmware/lib/python3.10/site-packages/httpcore/_sync/connection_pool.py:268, in ConnectionPool.handle_request(self, request)
267 self.response_closed(status)
--> 268 raise exc
269 else:
File ~/miniconda3/envs/llmware/lib/python3.10/site-packages/httpcore/_sync/connection_pool.py:251, in ConnectionPool.handle_request(self, request)
250 try:
--> 251 response = connection.handle_request(request)
252 except ConnectionNotAvailable:
253 # The ConnectionNotAvailable exception is a special case, that
254 # indicates we need to retry the request on a new connection.
(...)
258 # might end up as an HTTP/2 connection, but which actually ends
259 # up as HTTP/1.1.
File ~/miniconda3/envs/llmware/lib/python3.10/site-packages/httpcore/_sync/connection.py:99, in HTTPConnection.handle_request(self, request)
98 self._connect_failed = True
---> 99 raise exc
100 elif not self._connection.is_available():
File ~/miniconda3/envs/llmware/lib/python3.10/site-packages/httpcore/_sync/connection.py:76, in HTTPConnection.handle_request(self, request)
75 try:
---> 76 stream = self._connect(request)
78 ssl_object = stream.get_extra_info(\"ssl_object\")
File ~/miniconda3/envs/llmware/lib/python3.10/site-packages/httpcore/_sync/connection.py:124, in HTTPConnection._connect(self, request)
123 with Trace(\"connect_tcp\", logger, request, kwargs) as trace:
--> 124 stream = self._network_backend.connect_tcp(**kwargs)
125 trace.return_value = stream
File ~/miniconda3/envs/llmware/lib/python3.10/site-packages/httpcore/_backends/sync.py:205, in SyncBackend.connect_tcp(self, host, port, timeout, local_address, socket_options)
200 exc_map: ExceptionMapping = {
201 socket.timeout: ConnectTimeout,
202 OSError: ConnectError,
203 }
--> 205 with map_exceptions(exc_map):
206 sock = socket.create_connection(
207 address,
208 timeout,
209 source_address=source_address,
210 )
File ~/miniconda3/envs/llmware/lib/python3.10/contextlib.py:153, in _GeneratorContextManager.__exit__(self, typ, value, traceback)
152 try:
--> 153 self.gen.throw(typ, value, traceback)
154 except StopIteration as exc:
155 # Suppress StopIteration *unless* it's the same exception that
156 # was passed to throw(). This prevents a StopIteration
157 # raised inside the \"with\" statement from being suppressed.
File ~/miniconda3/envs/llmware/lib/python3.10/site-packages/httpcore/_exceptions.py:14, in map_exceptions(map)
13 if isinstance(exc, from_exc):
---> 14 raise to_exc(exc) from exc
15 raise
ConnectError: [Errno 111] Connection refused
The above exception was the direct cause of the following exception:
ConnectError Traceback (most recent call last)
File ~/miniconda3/envs/llmware/lib/python3.10/site-packages/openai/_base_client.py:877, in SyncAPIClient._request(self, cast_to, options, remaining_retries, stream, stream_cls)
876 try:
--> 877 response = self._client.send(
878 request,
879 auth=self.custom_auth,
880 stream=stream or self._should_stream_response_body(request=request),
881 )
882 except httpx.TimeoutException as err:
File ~/miniconda3/envs/llmware/lib/python3.10/site-packages/httpx/_client.py:901, in Client.send(self, request, stream, auth, follow_redirects)
899 auth = self._build_request_auth(request, auth)
--> 901 response = self._send_handling_auth(
902 request,
903 auth=auth,
904 follow_redirects=follow_redirects,
905 history=[],
906 )
907 try:
File ~/miniconda3/envs/llmware/lib/python3.10/site-packages/httpx/_client.py:929, in Client._send_handling_auth(self, request, auth, follow_redirects, history)
928 while True:
--> 929 response = self._send_handling_redirects(
930 request,
931 follow_redirects=follow_redirects,
932 history=history,
933 )
934 try:
File ~/miniconda3/envs/llmware/lib/python3.10/site-packages/httpx/_client.py:966, in Client._send_handling_redirects(self, request, follow_redirects, history)
964 hook(request)
--> 966 response = self._send_single_request(request)
967 try:
File ~/miniconda3/envs/llmware/lib/python3.10/site-packages/httpx/_client.py:1002, in Client._send_single_request(self, request)
1001 with request_context(request=request):
-> 1002 response = transport.handle_request(request)
1004 assert isinstance(response.stream, SyncByteStream)
File ~/miniconda3/envs/llmware/lib/python3.10/site-packages/httpx/_transports/default.py:227, in HTTPTransport.handle_request(self, request)
215 req = httpcore.Request(
216 method=request.method,
217 url=httpcore.URL(
(...)
225 extensions=request.extensions,
226 )
--> 227 with map_httpcore_exceptions():
228 resp = self._pool.handle_request(req)
File ~/miniconda3/envs/llmware/lib/python3.10/contextlib.py:153, in _GeneratorContextManager.__exit__(self, typ, value, traceback)
152 try:
--> 153 self.gen.throw(typ, value, traceback)
154 except StopIteration as exc:
155 # Suppress StopIteration *unless* it's the same exception that
156 # was passed to throw(). This prevents a StopIteration
157 # raised inside the \"with\" statement from being suppressed.
File ~/miniconda3/envs/llmware/lib/python3.10/site-packages/httpx/_transports/default.py:83, in map_httpcore_exceptions()
82 message = str(exc)
---> 83 raise mapped_exc(message) from exc
ConnectError: [Errno 111] Connection refused
The above exception was the direct cause of the following exception:
APIConnectionError Traceback (most recent call last)
Cell In[19], line 13
7 history = [
8 {\"role\": \"system\", \"content\": \"You are an intelligent assistant. You always provide well-reasoned answers that are both correct and helpful.\"},
9 {\"role\": \"user\", \"content\": \"Hello, introduce yourself to someone opening this program for the first time. Be concise.\"},
10 ]
12 while True:
---> 13 completion = client.chat.completions.create(
14 model=\"local-model\", # this field is currently unused
15 messages=history,
16 temperature=0.7,
17 stream=True,
18 )
20 new_message = {\"role\": \"assistant\", \"content\": \"\"}
22 for chunk in completion:
File ~/miniconda3/envs/llmware/lib/python3.10/site-packages/openai/_utils/_utils.py:272, in required_args.<locals>.inner.<locals>.wrapper(*args, **kwargs)
270 msg = f\"Missing required argument: {quote(missing[0])}\"
271 raise TypeError(msg)
--> 272 return func(*args, **kwargs)
File ~/miniconda3/envs/llmware/lib/python3.10/site-packages/openai/resources/chat/completions.py:645, in Completions.create(self, messages, model, frequency_penalty, function_call, functions, logit_bias, logprobs, max_tokens, n, presence_penalty, response_format, seed, stop, stream, temperature, tool_choice, tools, top_logprobs, top_p, user, extra_headers, extra_query, extra_body, timeout)
596 @required_args([\"messages\", \"model\"], [\"messages\", \"model\", \"stream\"])
597 def create(
598 self,
(...)
643 timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
644 ) -> ChatCompletion | Stream[ChatCompletionChunk]:
--> 645 return self._post(
646 \"/chat/completions\",
647 body=maybe_transform(
648 {
649 \"messages\": messages,
650 \"model\": model,
651 \"frequency_penalty\": frequency_penalty,
652 \"function_call\": function_call,
653 \"functions\": functions,
654 \"logit_bias\": logit_bias,
655 \"logprobs\": logprobs,
656 \"max_tokens\": max_tokens,
657 \"n\": n,
658 \"presence_penalty\": presence_penalty,
659 \"response_format\": response_format,
660 \"seed\": seed,
661 \"stop\": stop,
662 \"stream\": stream,
663 \"temperature\": temperature,
664 \"tool_choice\": tool_choice,
665 \"tools\": tools,
666 \"top_logprobs\": top_logprobs,
667 \"top_p\": top_p,
668 \"user\": user,
669 },
670 completion_create_params.CompletionCreateParams,
671 ),
672 options=make_request_options(
673 extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
674 ),
675 cast_to=ChatCompletion,
676 stream=stream or False,
677 stream_cls=Stream[ChatCompletionChunk],
678 )
File ~/miniconda3/envs/llmware/lib/python3.10/site-packages/openai/_base_client.py:1088, in SyncAPIClient.post(self, path, cast_to, body, options, files, stream, stream_cls)
1074 def post(
1075 self,
1076 path: str,
(...)
1083 stream_cls: type[_StreamT] | None = None,
1084 ) -> ResponseT | _StreamT:
1085 opts = FinalRequestOptions.construct(
1086 method=\"post\", url=path, json_data=body, files=to_httpx_files(files), **options
1087 )
-> 1088 return cast(ResponseT, self.request(cast_to, opts, stream=stream, stream_cls=stream_cls))
File ~/miniconda3/envs/llmware/lib/python3.10/site-packages/openai/_base_client.py:853, in SyncAPIClient.request(self, cast_to, options, remaining_retries, stream, stream_cls)
844 def request(
845 self,
846 cast_to: Type[ResponseT],
(...)
851 stream_cls: type[_StreamT] | None = None,
852 ) -> ResponseT | _StreamT:
--> 853 return self._request(
854 cast_to=cast_to,
855 options=options,
856 stream=stream,
857 stream_cls=stream_cls,
858 remaining_retries=remaining_retries,
859 )
File ~/miniconda3/envs/llmware/lib/python3.10/site-packages/openai/_base_client.py:896, in SyncAPIClient._request(self, cast_to, options, remaining_retries, stream, stream_cls)
894 except Exception as err:
895 if retries > 0:
--> 896 return self._retry_request(
897 options,
898 cast_to,
899 retries,
900 stream=stream,
901 stream_cls=stream_cls,
902 response_headers=None,
903 )
905 raise APIConnectionError(request=request) from err
907 log.debug(
908 'HTTP Request: %s %s \"%i %s\"', request.method, request.url, response.status_code, response.reason_phrase
909 )
File ~/miniconda3/envs/llmware/lib/python3.10/site-packages/openai/_base_client.py:958, in SyncAPIClient._retry_request(self, options, cast_to, remaining_retries, response_headers, stream, stream_cls)
954 # In a synchronous context we are blocking the entire thread. Up to the library user to run the client in a
955 # different thread if necessary.
956 time.sleep(timeout)
--> 958 return self._request(
959 options=options,
960 cast_to=cast_to,
961 remaining_retries=remaining,
962 stream=stream,
963 stream_cls=stream_cls,
964 )
File ~/miniconda3/envs/llmware/lib/python3.10/site-packages/openai/_base_client.py:896, in SyncAPIClient._request(self, cast_to, options, remaining_retries, stream, stream_cls)
894 except Exception as err:
895 if retries > 0:
--> 896 return self._retry_request(
897 options,
898 cast_to,
899 retries,
900 stream=stream,
901 stream_cls=stream_cls,
902 response_headers=None,
903 )
905 raise APIConnectionError(request=request) from err
907 log.debug(
908 'HTTP Request: %s %s \"%i %s\"', request.method, request.url, response.status_code, response.reason_phrase
909 )
File ~/miniconda3/envs/llmware/lib/python3.10/site-packages/openai/_base_client.py:958, in SyncAPIClient._retry_request(self, options, cast_to, remaining_retries, response_headers, stream, stream_cls)
954 # In a synchronous context we are blocking the entire thread. Up to the library user to run the client in a
955 # different thread if necessary.
956 time.sleep(timeout)
--> 958 return self._request(
959 options=options,
960 cast_to=cast_to,
961 remaining_retries=remaining,
962 stream=stream,
963 stream_cls=stream_cls,
964 )
File ~/miniconda3/envs/llmware/lib/python3.10/site-packages/openai/_base_client.py:905, in SyncAPIClient._request(self, cast_to, options, remaining_retries, stream, stream_cls)
895 if retries > 0:
896 return self._retry_request(
897 options,
898 cast_to,
(...)
902 response_headers=None,
903 )
--> 905 raise APIConnectionError(request=request) from err
907 log.debug(
908 'HTTP Request: %s %s \"%i %s\"', request.method, request.url, response.status_code, response.reason_phrase
909 )
911 try:
APIConnectionError: Connection error."
}
Any idea what could be wrong and how to fix it? Thanks in advance...