Open Kaleemullahqasim opened 3 months ago
I met the same question, debugged the code and found that the error code is 502, I tried to find the place where the response is generated but the code wrapped too deep and is hard to locate precisely.
So I tried to use the python packge request
directly and succeeded, here is the code:
import requests
import json
url = "http://localhost:11434/api/chat"
data = {
"model": "phi3",
"messages": [
{
'role': 'user',
'content': 'Why is the sky blue?',
}
],
"stream": False
}
response = requests.post(url, json=data)
if response.status_code == 200:
response_data = response.json()
print(json.dumps(response_data, indent=4))
else:
print(f"status_code{response.status_code}")
print(response.text)
here is the result:
{
"model": "phi3",
"created_at": "2024-05-25T14:55:39.889174Z",
"message": {
"role": "assistant",
"content": " The sky appears blue to the human eye because of a phenomenon called Rayleigh scattering. As sunlight travels through Earth's atmosphere, it encounters molecules and small particles which scatter the light in all directions. Blue light has a shorter wavelength and is scattered more than other colors since it travels as shorter, smaller waves. This selective scattering causes the sky to look blue in the daytime. However, at sunrise and sunset, the light passes through more of Earth's atmosphere, which scatters away most of the blue light, allowing reds, oranges, and yellows to dominate our view."
},
"done_reason": "stop",
"done": true,
"total_duration": 5341346800,
"load_duration": 2678940100,
"prompt_eval_count": 13,
"prompt_eval_duration": 61936000,
"eval_count": 139,
"eval_duration": 2598396000
}
simple codes like below
ollama.chat(model='mistral:instruct', messages=[{'role': 'user', 'content': 'Why is the sky blue?'}])
OR
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