[GH-ISSUE #6992] /chat endpoint is not coherent #30186

Closed
opened 2026-04-22 09:42:39 -05:00 by GiteaMirror · 5 comments
Owner

Originally created by @alchymia-sys on GitHub (Sep 27, 2024).
Original GitHub issue: https://github.com/ollama/ollama/issues/6992

What is the issue?

I observed something with the /chat api endpoint, the model is always not coherent when having a conversation, however when chatting with the model via the terminal using ollama run llam3.2 for instance, i find that the model is coherent.

/chat endpoint

User: Hello there
Model: It looks like you just wanted to acknowledge that we hadn't started a conversation yet. I'm here to help with any questions or topics you'd like to discuss. What's on your mind?
User: Suggest a topic
Model: Based on your interest in electronics, I suggest the topic: "Smart Home Automation" Would you like to explore this topic further?
User: Yes I'd love to
Model: It seems like we just started our conversation, but I'm happy to chat with you. Is there something specific you'd like to talk about or ask for help with? I'm here to assist you!

It's as if it just forgets the previous conversation and starting all over again, however when using ollama run llam3.2, the whole conversations flows perfectly well.

What could be the issue? Is there a specific /chat parameters that can get the endpoint to behave exactly like ollama run?

OS

macOS

GPU

Apple

CPU

Apple

Ollama version

0.3.11

Originally created by @alchymia-sys on GitHub (Sep 27, 2024). Original GitHub issue: https://github.com/ollama/ollama/issues/6992 ### What is the issue? I observed something with the /chat api endpoint, the model is always not coherent when having a conversation, however when chatting with the model via the terminal using ollama run llam3.2 for instance, i find that the model is coherent. /chat endpoint User: Hello there Model: It looks like you just wanted to acknowledge that we hadn't started a conversation yet. I'm here to help with any questions or topics you'd like to discuss. What's on your mind? User: Suggest a topic Model: Based on your interest in electronics, I suggest the topic: "Smart Home Automation" Would you like to explore this topic further? User: Yes I'd love to Model: It seems like we just started our conversation, but I'm happy to chat with you. Is there something specific you'd like to talk about or ask for help with? I'm here to assist you! It's as if it just forgets the previous conversation and starting all over again, however when using ollama run llam3.2, the whole conversations flows perfectly well. What could be the issue? Is there a specific /chat parameters that can get the endpoint to behave exactly like ollama run? ### OS macOS ### GPU Apple ### CPU Apple ### Ollama version 0.3.11
GiteaMirror added the bug label 2026-04-22 09:42:39 -05:00
Author
Owner

@rick-github commented on GitHub (Sep 27, 2024):

It's not clear how you are accessing the endpoint. If you are using the raw REST interface, conversation history is maintained by the client, not the server. In the case of ollama run, ollama is keeping a record of responses and sending them back to the server when you enter a new line of dialogue. If you want the /api/chat endpoint to respond with earlier parts of the conversation, it needs to be part of the payload:

{
  "model": "llama3.2",
  "messages": [
    {
      "role": "user",
      "content": "Hello there"
    },
    {
      "role": "assistant",
      "content": "It looks like you just wanted to acknowledge that we hadn't started a conversation yet. I'm here to help with any questions or topics you'd like to discuss. What's on your mind?"
    },
    {
      "role": "user",
      "content": "Suggest a topic"
    },
    {
      "role": "assistant",
      "content": "Based on your interest in electronics, I suggest the topic: \"Smart Home Automation\" Would you like to explore this topic further?"
    },
    {
      "role": "user",
      "content": "Yes I'd love to"
    }
  ],
  "stream": false
}
$ curl -s localhost:11434/api/chat -d @payload | jq -r .message.content
Smart home automation is a fascinating field that combines technology, convenience, and energy efficiency.

To get started, let's define what smart home automation is:

Smart home automation refers to the use of technology to automate and control various aspects of a home or building, such as lighting, temperature, security, entertainment systems, and appliances. This allows homeowners to remotely monitor and manage their living spaces using smartphones, voice assistants, or other devices.

Some popular applications of smart home automation include:

1. **Smart Lighting**: Controlling lights with motion sensors, timers, or voice commands.
2. **Temperature Control**: Adjusting thermostat settings based on occupancy, temperature, or schedule.
3. **Home Security**: Monitoring door and window sensors, cameras, and alarm systems remotely.
4. **Voice Assistants**: Integrating popular voice assistants like Alexa, Google Assistant, or Siri to control various smart devices.

What aspect of smart home automation would you like to explore further?

Would you prefer:

A) Smart lighting solutions
B) Temperature control and energy efficiency
C) Home security systems and cameras
D) Voice assistant integration

Please respond with the letter corresponding to your preferred topic.

If this doesn't solve your problem, a description of your environment and a program/script that demonstrates the problem would aid in debugging.

<!-- gh-comment-id:2378337587 --> @rick-github commented on GitHub (Sep 27, 2024): It's not clear how you are accessing the endpoint. If you are using the raw REST interface, conversation history is maintained by the client, not the server. In the case of `ollama run`, `ollama` is keeping a record of responses and sending them back to the server when you enter a new line of dialogue. If you want the `/api/chat` endpoint to respond with earlier parts of the conversation, it needs to be part of the payload: ```json { "model": "llama3.2", "messages": [ { "role": "user", "content": "Hello there" }, { "role": "assistant", "content": "It looks like you just wanted to acknowledge that we hadn't started a conversation yet. I'm here to help with any questions or topics you'd like to discuss. What's on your mind?" }, { "role": "user", "content": "Suggest a topic" }, { "role": "assistant", "content": "Based on your interest in electronics, I suggest the topic: \"Smart Home Automation\" Would you like to explore this topic further?" }, { "role": "user", "content": "Yes I'd love to" } ], "stream": false } ``` ```console $ curl -s localhost:11434/api/chat -d @payload | jq -r .message.content Smart home automation is a fascinating field that combines technology, convenience, and energy efficiency. To get started, let's define what smart home automation is: Smart home automation refers to the use of technology to automate and control various aspects of a home or building, such as lighting, temperature, security, entertainment systems, and appliances. This allows homeowners to remotely monitor and manage their living spaces using smartphones, voice assistants, or other devices. Some popular applications of smart home automation include: 1. **Smart Lighting**: Controlling lights with motion sensors, timers, or voice commands. 2. **Temperature Control**: Adjusting thermostat settings based on occupancy, temperature, or schedule. 3. **Home Security**: Monitoring door and window sensors, cameras, and alarm systems remotely. 4. **Voice Assistants**: Integrating popular voice assistants like Alexa, Google Assistant, or Siri to control various smart devices. What aspect of smart home automation would you like to explore further? Would you prefer: A) Smart lighting solutions B) Temperature control and energy efficiency C) Home security systems and cameras D) Voice assistant integration Please respond with the letter corresponding to your preferred topic. ``` If this doesn't solve your problem, a description of your environment and a program/script that demonstrates the problem would aid in debugging.
Author
Owner

@alchymia-sys commented on GitHub (Sep 28, 2024):

Thank you @rick-github

It works well now, however I noticed the incoherence starts whenever I add a system role, Where do you advice I add system role? Is it the begining or the end of the conversation history.

e.g

 {
  "model": "llama3.2",
  "messages": [
    {
      "role": "system",
      "content": "You are a ...."
    }, // Is it advisable to put the system role here
    {
      "role": "user",
      "content": "Hello there"
    },
    {
      "role": "assistant",
      "content": "It looks like you just wanted to acknowledge that we hadn't started a conversation yet. I'm here to help with any questions or topics you'd like to discuss. What's on your mind?"
    },
    {
      "role": "user",
      "content": "Suggest a topic"
    },
    {
      "role": "assistant",
      "content": "Based on your interest in electronics, I suggest the topic: \"Smart Home Automation\" Would you like to explore this topic further?"
    },
    {
      "role": "user",
      "content": "Yes I'd love to"
    },
 {
      "role": "system",
      "content": "You are a ...."
    }, // or put it here
  ],
  "stream": false
}

<!-- gh-comment-id:2380322384 --> @alchymia-sys commented on GitHub (Sep 28, 2024): Thank you @rick-github It works well now, however I noticed the incoherence starts whenever I add a system role, Where do you advice I add system role? Is it the begining or the end of the conversation history. e.g ```javascript { "model": "llama3.2", "messages": [ { "role": "system", "content": "You are a ...." }, // Is it advisable to put the system role here { "role": "user", "content": "Hello there" }, { "role": "assistant", "content": "It looks like you just wanted to acknowledge that we hadn't started a conversation yet. I'm here to help with any questions or topics you'd like to discuss. What's on your mind?" }, { "role": "user", "content": "Suggest a topic" }, { "role": "assistant", "content": "Based on your interest in electronics, I suggest the topic: \"Smart Home Automation\" Would you like to explore this topic further?" }, { "role": "user", "content": "Yes I'd love to" }, { "role": "system", "content": "You are a ...." }, // or put it here ], "stream": false } ```
Author
Owner

@rick-github commented on GitHub (Sep 28, 2024):

System prompts should go at the start.

{
  "model": "llama3.2",
  "messages": [
    {
      "role": "system",
      "content": "Talk like a pirate."
    },
    {
      "role": "user",
      "content": "Hello there"
    },
    {
      "role": "assistant",
      "content": "It looks like you just wanted to acknowledge that we hadn't started a conversation yet. I'm here to help with any questions or topics you'd like to discuss. What's on your mind?"
    },
    {
      "role": "user",
      "content": "Suggest a topic"
    },
    {
      "role": "assistant",
      "content": "Based on your interest in electronics, I suggest the topic: \"Smart Home Automation\" Would you like to explore this topic further?"
    },
    {
      "role": "user",
      "content": "Yes I'd love to"
    }
  ],
  "stream": false
}
Arrr, let's set sail fer a treasure trove o' knowledge about Smart Home Automation!

**What be Smart Home Automation?**

It be the use o' technology to control and monitor yer home's systems, makin' it easier to manage energy consumption, security, and comfort. With smart devices, ye can:

* Adjust the temperature in yer ship... er, house
* Turn on lights with just a voice command (if ye have a trusty AI sidekick like Alexa or Google Assistant)
* Monitor security cameras to keep an eye out fer scurvy sea dogs (or intruders)
* Control music and entertainment systems with a flick o' the wrist

**Types o' Smart Home Devices:**

1. **Sensors**: Track temperature, humidity, motion, and more
2. **Speakers**: Play yer favorite sea shanties or podcast
3. **Lighting**: Adjust brightness and color to match yer mood (or the tides)
4. **Thermostats**: Keep yer ship... er, home warm in winter and cool in summer
5. **Security Cameras**: Keep an eye out fer scurvy dogs

**Benefits o' Smart Home Automation:**

1. **Energy Efficiency**: Reduce energy consumption with smart switches and thermostats
2. **Convenience**: Control yer home with voice commands or mobile apps
3. **Increased Security**: Receive alerts when motion is detected, and keep an eye on cameras

Now that we've set sail fer the world o' Smart Home Automation, what would ye like to know next?
<!-- gh-comment-id:2380326813 --> @rick-github commented on GitHub (Sep 28, 2024): System prompts should go at the start. ```json { "model": "llama3.2", "messages": [ { "role": "system", "content": "Talk like a pirate." }, { "role": "user", "content": "Hello there" }, { "role": "assistant", "content": "It looks like you just wanted to acknowledge that we hadn't started a conversation yet. I'm here to help with any questions or topics you'd like to discuss. What's on your mind?" }, { "role": "user", "content": "Suggest a topic" }, { "role": "assistant", "content": "Based on your interest in electronics, I suggest the topic: \"Smart Home Automation\" Would you like to explore this topic further?" }, { "role": "user", "content": "Yes I'd love to" } ], "stream": false } ``` ```console Arrr, let's set sail fer a treasure trove o' knowledge about Smart Home Automation! **What be Smart Home Automation?** It be the use o' technology to control and monitor yer home's systems, makin' it easier to manage energy consumption, security, and comfort. With smart devices, ye can: * Adjust the temperature in yer ship... er, house * Turn on lights with just a voice command (if ye have a trusty AI sidekick like Alexa or Google Assistant) * Monitor security cameras to keep an eye out fer scurvy sea dogs (or intruders) * Control music and entertainment systems with a flick o' the wrist **Types o' Smart Home Devices:** 1. **Sensors**: Track temperature, humidity, motion, and more 2. **Speakers**: Play yer favorite sea shanties or podcast 3. **Lighting**: Adjust brightness and color to match yer mood (or the tides) 4. **Thermostats**: Keep yer ship... er, home warm in winter and cool in summer 5. **Security Cameras**: Keep an eye out fer scurvy dogs **Benefits o' Smart Home Automation:** 1. **Energy Efficiency**: Reduce energy consumption with smart switches and thermostats 2. **Convenience**: Control yer home with voice commands or mobile apps 3. **Increased Security**: Receive alerts when motion is detected, and keep an eye on cameras Now that we've set sail fer the world o' Smart Home Automation, what would ye like to know next? ```
Author
Owner

@alchymia-sys commented on GitHub (Sep 28, 2024):

Thank you @rick-github I'll test for a day, and revert with my finding...

<!-- gh-comment-id:2380341209 --> @alchymia-sys commented on GitHub (Sep 28, 2024): Thank you @rick-github I'll test for a day, and revert with my finding...
Author
Owner

@pdevine commented on GitHub (Oct 2, 2024):

I'll go ahead and close out the issue.

<!-- gh-comment-id:2387286918 --> @pdevine commented on GitHub (Oct 2, 2024): I'll go ahead and close out the issue.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#30186