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

ResponseError(without error information) when running with python #83

Open
Kaleemullahqasim opened this issue Mar 7, 2024 · 0 comments

Comments

@Kaleemullahqasim
Copy link

simple codes like below

ollama.chat(model='mistral:instruct', messages=[{'role': 'user', 'content': 'Why is the sky blue?'}])

OR

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

An error is being thrown, but there is no specific issue being printed.
"It works perfectly fine in the command-line interface (CLI) when I run ollama run mistral:instruct

Here is the error

ResponseError                             Traceback (most recent call last)
Cell In[2], [line 1](vscode-notebook-cell:?execution_count=2&line=1)
----> [1](vscode-notebook-cell:?execution_count=2&line=1) ollama.chat(model='mistral:instruct', messages=[{'role': 'user', 'content': 'Why is the sky blue?'}])

File [~/Documents/GitHub/upwork_Sentiment_job/.venv/lib/python3.12/site-packages/ollama/_client.py:177](https://file+.vscode-resource.vscode-cdn.net/Users/kaleemullahqasim/Documents/GitHub/upwork_Sentiment_job/~/Documents/GitHub/upwork_Sentiment_job/.venv/lib/python3.12/site-packages/ollama/_client.py:177), in Client.chat(self, model, messages, stream, format, options, keep_alive)
    [174](https://file+.vscode-resource.vscode-cdn.net/Users/kaleemullahqasim/Documents/GitHub/upwork_Sentiment_job/~/Documents/GitHub/upwork_Sentiment_job/.venv/lib/python3.12/site-packages/ollama/_client.py:174)   if images := message.get('images'):
    [175](https://file+.vscode-resource.vscode-cdn.net/Users/kaleemullahqasim/Documents/GitHub/upwork_Sentiment_job/~/Documents/GitHub/upwork_Sentiment_job/.venv/lib/python3.12/site-packages/ollama/_client.py:175)     message['images'] = [_encode_image(image) for image in images]
--> [177](https://file+.vscode-resource.vscode-cdn.net/Users/kaleemullahqasim/Documents/GitHub/upwork_Sentiment_job/~/Documents/GitHub/upwork_Sentiment_job/.venv/lib/python3.12/site-packages/ollama/_client.py:177) return self._request_stream(
    [178](https://file+.vscode-resource.vscode-cdn.net/Users/kaleemullahqasim/Documents/GitHub/upwork_Sentiment_job/~/Documents/GitHub/upwork_Sentiment_job/.venv/lib/python3.12/site-packages/ollama/_client.py:178)   'POST',
    [179](https://file+.vscode-resource.vscode-cdn.net/Users/kaleemullahqasim/Documents/GitHub/upwork_Sentiment_job/~/Documents/GitHub/upwork_Sentiment_job/.venv/lib/python3.12/site-packages/ollama/_client.py:179)   '[/api/chat](https://file+.vscode-resource.vscode-cdn.net/api/chat)',
    [180](https://file+.vscode-resource.vscode-cdn.net/Users/kaleemullahqasim/Documents/GitHub/upwork_Sentiment_job/~/Documents/GitHub/upwork_Sentiment_job/.venv/lib/python3.12/site-packages/ollama/_client.py:180)   json={
    [181](https://file+.vscode-resource.vscode-cdn.net/Users/kaleemullahqasim/Documents/GitHub/upwork_Sentiment_job/~/Documents/GitHub/upwork_Sentiment_job/.venv/lib/python3.12/site-packages/ollama/_client.py:181)     'model': model,
    [182](https://file+.vscode-resource.vscode-cdn.net/Users/kaleemullahqasim/Documents/GitHub/upwork_Sentiment_job/~/Documents/GitHub/upwork_Sentiment_job/.venv/lib/python3.12/site-packages/ollama/_client.py:182)     'messages': messages,
    [183](https://file+.vscode-resource.vscode-cdn.net/Users/kaleemullahqasim/Documents/GitHub/upwork_Sentiment_job/~/Documents/GitHub/upwork_Sentiment_job/.venv/lib/python3.12/site-packages/ollama/_client.py:183)     'stream': stream,
    [184](https://file+.vscode-resource.vscode-cdn.net/Users/kaleemullahqasim/Documents/GitHub/upwork_Sentiment_job/~/Documents/GitHub/upwork_Sentiment_job/.venv/lib/python3.12/site-packages/ollama/_client.py:184)     'format': format,
    [185](https://file+.vscode-resource.vscode-cdn.net/Users/kaleemullahqasim/Documents/GitHub/upwork_Sentiment_job/~/Documents/GitHub/upwork_Sentiment_job/.venv/lib/python3.12/site-packages/ollama/_client.py:185)     'options': options or {},
    [186](https://file+.vscode-resource.vscode-cdn.net/Users/kaleemullahqasim/Documents/GitHub/upwork_Sentiment_job/~/Documents/GitHub/upwork_Sentiment_job/.venv/lib/python3.12/site-packages/ollama/_client.py:186)     'keep_alive': keep_alive,
    [187](https://file+.vscode-resource.vscode-cdn.net/Users/kaleemullahqasim/Documents/GitHub/upwork_Sentiment_job/~/Documents/GitHub/upwork_Sentiment_job/.venv/lib/python3.12/site-packages/ollama/_client.py:187)   },
    [188](https://file+.vscode-resource.vscode-cdn.net/Users/kaleemullahqasim/Documents/GitHub/upwork_Sentiment_job/~/Documents/GitHub/upwork_Sentiment_job/.venv/lib/python3.12/site-packages/ollama/_client.py:188)   stream=stream,
    [189](https://file+.vscode-resource.vscode-cdn.net/Users/kaleemullahqasim/Documents/GitHub/upwork_Sentiment_job/~/Documents/GitHub/upwork_Sentiment_job/.venv/lib/python3.12/site-packages/ollama/_client.py:189) )

File [~/Documents/GitHub/upwork_Sentiment_job/.venv/lib/python3.12/site-packages/ollama/_client.py:97](https://file+.vscode-resource.vscode-cdn.net/Users/kaleemullahqasim/Documents/GitHub/upwork_Sentiment_job/~/Documents/GitHub/upwork_Sentiment_job/.venv/lib/python3.12/site-packages/ollama/_client.py:97), in Client._request_stream(self, stream, *args, **kwargs)
     [91](https://file+.vscode-resource.vscode-cdn.net/Users/kaleemullahqasim/Documents/GitHub/upwork_Sentiment_job/~/Documents/GitHub/upwork_Sentiment_job/.venv/lib/python3.12/site-packages/ollama/_client.py:91) def _request_stream(
     [92](https://file+.vscode-resource.vscode-cdn.net/Users/kaleemullahqasim/Documents/GitHub/upwork_Sentiment_job/~/Documents/GitHub/upwork_Sentiment_job/.venv/lib/python3.12/site-packages/ollama/_client.py:92)   self,
     [93](https://file+.vscode-resource.vscode-cdn.net/Users/kaleemullahqasim/Documents/GitHub/upwork_Sentiment_job/~/Documents/GitHub/upwork_Sentiment_job/.venv/lib/python3.12/site-packages/ollama/_client.py:93)   *args,
     [94](https://file+.vscode-resource.vscode-cdn.net/Users/kaleemullahqasim/Documents/GitHub/upwork_Sentiment_job/~/Documents/GitHub/upwork_Sentiment_job/.venv/lib/python3.12/site-packages/ollama/_client.py:94)   stream: bool = False,
     [95](https://file+.vscode-resource.vscode-cdn.net/Users/kaleemullahqasim/Documents/GitHub/upwork_Sentiment_job/~/Documents/GitHub/upwork_Sentiment_job/.venv/lib/python3.12/site-packages/ollama/_client.py:95)   **kwargs,
     [96](https://file+.vscode-resource.vscode-cdn.net/Users/kaleemullahqasim/Documents/GitHub/upwork_Sentiment_job/~/Documents/GitHub/upwork_Sentiment_job/.venv/lib/python3.12/site-packages/ollama/_client.py:96) ) -> Union[Mapping[str, Any], Iterator[Mapping[str, Any]]]:
---> [97](https://file+.vscode-resource.vscode-cdn.net/Users/kaleemullahqasim/Documents/GitHub/upwork_Sentiment_job/~/Documents/GitHub/upwork_Sentiment_job/.venv/lib/python3.12/site-packages/ollama/_client.py:97)   return self._stream(*args, **kwargs) if stream else self._request(*args, **kwargs).json()

File [~/Documents/GitHub/upwork_Sentiment_job/.venv/lib/python3.12/site-packages/ollama/_client.py:73](https://file+.vscode-resource.vscode-cdn.net/Users/kaleemullahqasim/Documents/GitHub/upwork_Sentiment_job/~/Documents/GitHub/upwork_Sentiment_job/.venv/lib/python3.12/site-packages/ollama/_client.py:73), in Client._request(self, method, url, **kwargs)
     [71](https://file+.vscode-resource.vscode-cdn.net/Users/kaleemullahqasim/Documents/GitHub/upwork_Sentiment_job/~/Documents/GitHub/upwork_Sentiment_job/.venv/lib/python3.12/site-packages/ollama/_client.py:71)   response.raise_for_status()
     [72](https://file+.vscode-resource.vscode-cdn.net/Users/kaleemullahqasim/Documents/GitHub/upwork_Sentiment_job/~/Documents/GitHub/upwork_Sentiment_job/.venv/lib/python3.12/site-packages/ollama/_client.py:72) except httpx.HTTPStatusError as e:
---> [73](https://file+.vscode-resource.vscode-cdn.net/Users/kaleemullahqasim/Documents/GitHub/upwork_Sentiment_job/~/Documents/GitHub/upwork_Sentiment_job/.venv/lib/python3.12/site-packages/ollama/_client.py:73)   raise ResponseError(e.response.text, e.response.status_code) from None
     [75](https://file+.vscode-resource.vscode-cdn.net/Users/kaleemullahqasim/Documents/GitHub/upwork_Sentiment_job/~/Documents/GitHub/upwork_Sentiment_job/.venv/lib/python3.12/site-packages/ollama/_client.py:75) return response

ResponseError:`
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

1 participant