ollama-python icon indicating copy to clipboard operation
ollama-python copied to clipboard

Met the 503 code status error when run ollama to connect localhost for chat on M3 apple silicon

Open smile836 opened this issue 1 month ago • 0 comments

Description

I met the 503 code status error, when I run ollama to connect localhost for chat on apple silicon. Local machine: M3 Max MacBook Pro, Ollama, llama3, python3.11

The code:

import ollama

response = ollama.chat(model='llama3', messages=[
  {
    'role': 'user',
    'content': 'Why is the sky blue?',
  },
])
print(response['message']['content'])```


the error:

Traceback (most recent call last):
  File "/Users/jing/Desktop/hj/lesson1/test4.py", line 10, in <module>
    chat_completion = client.chat.completions.create(
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/jing/miniconda3/lib/python3.11/site-packages/openai/_utils/_utils.py", line 277, in wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/Users/jing/miniconda3/lib/python3.11/site-packages/openai/resources/chat/completions.py", line 579, in create
    return self._post(
           ^^^^^^^^^^^
  File "/Users/jing/miniconda3/lib/python3.11/site-packages/openai/_base_client.py", line 1240, in post
    return cast(ResponseT, self.request(cast_to, opts, stream=stream, stream_cls=stream_cls))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/jing/miniconda3/lib/python3.11/site-packages/openai/_base_client.py", line 921, in request
    return self._request(
           ^^^^^^^^^^^^^^
  File "/Users/jing/miniconda3/lib/python3.11/site-packages/openai/_base_client.py", line 1005, in _request
    return self._retry_request(
           ^^^^^^^^^^^^^^^^^^^^
  File "/Users/jing/miniconda3/lib/python3.11/site-packages/openai/_base_client.py", line 1053, in _retry_request
    return self._request(
           ^^^^^^^^^^^^^^
  File "/Users/jing/miniconda3/lib/python3.11/site-packages/openai/_base_client.py", line 1005, in _request
    return self._retry_request(
           ^^^^^^^^^^^^^^^^^^^^
  File "/Users/jing/miniconda3/lib/python3.11/site-packages/openai/_base_client.py", line 1053, in _retry_request
    return self._request(
           ^^^^^^^^^^^^^^
  File "/Users/jing/miniconda3/lib/python3.11/site-packages/openai/_base_client.py", line 1020, in _request
    raise self._make_status_error_from_response(err.response) from None
openai.InternalServerError: Error code: 503```

Root casuse analysis

I try curl to test API is OK

curl -X POST http://localhost:11434/v1/chat/completions -H "Content-Type: application/json" -d '{
 "model": "llama3",
 "messages": [
   {"role": "user", "content": "Say this is a test"}
 ]
}'

check server is OK

$lsof -i :11434

COMMAND   PID USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
ollama  29656 jing    3u  IPv4 0x5cf26da56a7362d3      0t0  TCP localhost:11434 (LISTEN)

add timeout, but also get 503

Attempt 1 failed with error: Error code: 503
Attempt 2 failed with error: Error code: 503
Attempt 3 failed with error: Error code: 503
Attempt 4 failed with error: Error code: 503
Attempt 5 failed with error: Error code: 503
An error occurred: Error code: 503

I would like to know the root cause of this error. I suspect it's because the apple silicon is not supported, is that correct?

smile836 avatar May 21 '24 03:05 smile836