[GH-ISSUE #831] Context modification #46908

Closed
opened 2026-04-28 01:58:42 -05:00 by GiteaMirror · 6 comments
Owner

Originally created by @VladimirKras on GitHub (Oct 18, 2023).
Original GitHub issue: https://github.com/ollama/ollama/issues/831

Sometimes I would like to steer a dialogue in a certain direction by adding a fake message on behalf of the LLM. How to achieve that with Ollama seems quite opaque:

  1. The context that is sent is just an array of token ids, which is hard to manipulate.
  2. The tokenizer and de-tokenizer aren't exposed.
Originally created by @VladimirKras on GitHub (Oct 18, 2023). Original GitHub issue: https://github.com/ollama/ollama/issues/831 Sometimes I would like to steer a dialogue in a certain direction by adding a fake message on behalf of the LLM. How to achieve that with Ollama seems quite opaque: 1. The context that is sent is just an array of token ids, which is hard to manipulate. 2. The tokenizer and de-tokenizer aren't exposed.
GiteaMirror added the questionfeedback wanted labels 2026-04-28 01:58:49 -05:00
Author
Owner

@mxyng commented on GitHub (Oct 25, 2023):

The context is intended to be opaque to the user. In that sense, you're expected to pass into the context what was returned by the previous response.

If your use case requires changing history, it'll probably be better to not use the context at all but track the conversation yourself.

<!-- gh-comment-id:1779903701 --> @mxyng commented on GitHub (Oct 25, 2023): The context is intended to be opaque to the user. In that sense, you're expected to pass into the context what was returned by the previous response. If your use case requires changing history, it'll probably be better to not use the context at all but track the conversation yourself.
Author
Owner

@MelihOzb commented on GitHub (Oct 28, 2023):

The context shouldn't be opaque to the user, assume I want to load a past conversation with AI (just like you can do with ChatGPT and other LLMs). If we can insert context (i.e. access to tokenizer) then we can read the whole conversation from a database, tokenize them and insert them into context and continue where we left. But now, I have to choose another method to be able to continue past conversation.

<!-- gh-comment-id:1783679216 --> @MelihOzb commented on GitHub (Oct 28, 2023): The context shouldn't be opaque to the user, assume I want to load a past conversation with AI (just like you can do with ChatGPT and other LLMs). If we can insert context (i.e. access to tokenizer) then we can read the whole conversation from a database, tokenize them and insert them into context and continue where we left. But now, I have to choose another method to be able to continue past conversation.
Author
Owner

@mxyng commented on GitHub (Oct 28, 2023):

@MelihOzb the current implementation supports that without needing to tokenize a previous conversation. You can see an example of exactly what you've described in https://github.com/mxyng/discollama. It saves the context in redis which can be loaded at a later point to continue the conversation.

<!-- gh-comment-id:1783708598 --> @mxyng commented on GitHub (Oct 28, 2023): @MelihOzb the current implementation supports that without needing to tokenize a previous conversation. You can see an example of exactly what you've described in https://github.com/mxyng/discollama. It [saves](https://github.com/mxyng/discollama/blob/main/discollama.py#L61) the context in redis which can be [loaded](https://github.com/mxyng/discollama/blob/main/discollama.py#L69) at a later point to continue the conversation.
Author
Owner

@emsi commented on GitHub (Dec 1, 2023):

OK, so regardless the context modification, how I can fake previous LLM response with ollama? This technique is used to better guide models without system prompt and acts as an example. Is it possible at all with ollama?

<!-- gh-comment-id:1836754854 --> @emsi commented on GitHub (Dec 1, 2023): OK, so regardless the context modification, how I can fake previous LLM response with ollama? This technique is used to better guide models without system prompt and acts as an example. Is it possible at all with ollama?
Author
Owner

@emsi commented on GitHub (Dec 14, 2023):

It's possible that chat api #1392 addresses that but I didn't test it yet.

<!-- gh-comment-id:1855810201 --> @emsi commented on GitHub (Dec 14, 2023): It's possible that chat api #1392 addresses that but I didn't test it yet.
Author
Owner

@mxyng commented on GitHub (Jan 16, 2024):

While it might not the intent of the issue creator, you can create and modify chat history as well as use multi-shot inputs using the chat API.

<!-- gh-comment-id:1894621930 --> @mxyng commented on GitHub (Jan 16, 2024): While it might not the intent of the issue creator, you can create and modify chat history as well as use multi-shot inputs using the chat API.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#46908