When the model provider is Ollama, the stop_sequence does not work #4093

Closed
opened 2026-02-21 18:04:43 -05:00 by yindo · 3 comments
Owner

Originally created by @sunglasses88 on GitHub (Jun 14, 2024).

Originally assigned to: @laipz8200 on GitHub.

Self Checks

  • This is only for bug report, if you would like to ask a question, please head to Discussions.
  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
  • Please do not modify this template :) and fill in all the required fields.

Dify version

0.6.10

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

  1. In the workflow, set the model of the LLM node to the model deployed by Ollama.
  2. Set the stop sequence to 3.
  3. The debug prompt is as follows: Count from 1 to 5 using Arabic numerals: 1, 2, 3, 4, 5.

image

✔️ Expected Behavior

Expected Response:"Sure, here is the count from 1 to 5 in Arabic numerals:\n\n1, 2",
However, if I directly call Ollama's API, I can get the response I expect.
image

Actual Behavior

Actual Response:"Sure, here is the count from 1 to 5 using Arabic numerals:

1, 2, 3, 4, 5",
However, in practice, the response from the Dify workflow is:
image

Originally created by @sunglasses88 on GitHub (Jun 14, 2024). Originally assigned to: @laipz8200 on GitHub. ### Self Checks - [X] This is only for bug report, if you would like to ask a question, please head to [Discussions](https://github.com/langgenius/dify/discussions/categories/general). - [X] I have searched for existing issues [search for existing issues](https://github.com/langgenius/dify/issues), including closed ones. - [X] I confirm that I am using English to submit this report (我已阅读并同意 [Language Policy](https://github.com/langgenius/dify/issues/1542)). - [X] Please do not modify this template :) and fill in all the required fields. ### Dify version 0.6.10 ### Cloud or Self Hosted Self Hosted (Docker) ### Steps to reproduce 1. In the workflow, set the model of the LLM node to the model deployed by Ollama. 2. Set the stop sequence to 3. 3. The debug prompt is as follows: Count from 1 to 5 using Arabic numerals: 1, 2, 3, 4, 5. ![image](https://github.com/langgenius/dify/assets/38178396/4d9f5505-d208-43c9-8b59-5e7a4fe05c63) ### ✔️ Expected Behavior Expected Response:"Sure, here is the count from 1 to 5 in Arabic numerals:\n\n1, 2", However, if I directly call Ollama's API, I can get the response I expect. ![image](https://github.com/langgenius/dify/assets/38178396/3b55c0a5-6fac-4300-9459-d0842a735219) ### ❌ Actual Behavior Actual Response:"Sure, here is the count from 1 to 5 using Arabic numerals: 1, 2, 3, 4, 5", However, in practice, the response from the Dify workflow is: ![image](https://github.com/langgenius/dify/assets/38178396/ab1d095d-924c-4be4-a975-a7fc50eb7a8e)
yindo added the 🐞 bug label 2026-02-21 18:04:43 -05:00
yindo closed this issue 2026-02-21 18:04:43 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Jun 14, 2024):

Hi @iYaDongWang! I'm here to help with your bug report. I can assist with solving bugs, answering questions, and becoming a contributor.

The stop_sequence parameter does not work as expected because the stop parameter is being joined into a single string with newline characters (\n) in the _generate method. This means that the stop sequences are not being treated as individual stop sequences but as a single concatenated string.

if stop:
    data["stop"] = "\n".join(stop)

To fix this, you should ensure that the stop parameter is passed as a list of strings to the API without joining them [1].

To continue talking to Dosu, mention @dosu.

@dosubot[bot] commented on GitHub (Jun 14, 2024): <!-- Greeting --> Hi @iYaDongWang! I'm here to help with your bug report. I can assist with solving bugs, answering questions, and becoming a contributor. <!-- Answer --> The `stop_sequence` parameter does not work as expected because the `stop` parameter is being joined into a single string with newline characters (`\n`) in the `_generate` method. This means that the stop sequences are not being treated as individual stop sequences but as a single concatenated string. ```python if stop: data["stop"] = "\n".join(stop) ``` To fix this, you should ensure that the `stop` parameter is passed as a list of strings to the API without joining them <sup>[[1]](https://github.com/langgenius/dify/blob/main/api/core/model_runtime/model_providers/ollama/llm/llm.py)</sup>. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.*
Author
Owner

@laipz8200 commented on GitHub (Jun 14, 2024):

Looks like Ollama has updated their API structure. I’ll fix it later.

@laipz8200 commented on GitHub (Jun 14, 2024): Looks like Ollama has updated their API structure. I’ll fix it later.
Author
Owner

@sunglasses88 commented on GitHub (Jun 14, 2024):

Perhaps it would be better if the Dify documentation stated the supported versions of model providers for each version.

@sunglasses88 commented on GitHub (Jun 14, 2024): Perhaps it would be better if the Dify documentation stated the supported versions of model providers for each version.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#4093