How can I use context parameter? #14

Closed
opened 2026-02-15 16:27:27 -05:00 by yindo · 1 comment
Owner

Originally created by @YRG999 on GitHub (Jan 28, 2024).

How can I use the context parameter from the API to keep a conversational memory?

Originally created by @YRG999 on GitHub (Jan 28, 2024). How can I use the `context` parameter [from the API](https://github.com/ollama/ollama/blob/main/docs/api.md#parameters) to keep a conversational memory?
yindo closed this issue 2026-02-15 16:27:27 -05:00
Author
Owner

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

The response from a generate call will return a context object. To continue the conversation, you can pass this directly into the next call:

r1 = ollama.generate(model='llama2', prompt='hi!')
r2 = ollama.generate(model='llama2', prompt='hi again!', context=r1['context'])

Context is the token representations of the inputs and outputs up to and including the response

@mxyng commented on GitHub (Jan 29, 2024): The response from a generate call will return a context object. To continue the conversation, you can pass this directly into the next call: ```python r1 = ollama.generate(model='llama2', prompt='hi!') r2 = ollama.generate(model='llama2', prompt='hi again!', context=r1['context']) ``` Context is the token representations of the inputs and outputs up to and including the response
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: ollama/ollama-python#14