-
Components themselves, which generally contain all of the context needed for a single-turn request. MObjects manage context using fields and methods, Instructions have a grounding_context for RAG-style requests, etc. -
The
Context, which stores and represents a (sometimes partial) history of all previous requests to the LLM made during the current session.
Context mechanism.
When you use the start_session() method, you are actually instantiating a Mellea with a default inference engine, a default model choice, and a default context manager. The following code is equivalent to m.start_session():
SimpleContext — which is the only context we have used so far — is a context manager that resets the chat message history on each model call. That is, the model’s context is entirely determined by the current Component. Mellea also provides a ChatContext, which behaves like a chat history. We can use the ChatContext to interact with chat models:
Context object provides a few useful helpers for introspecting on the current model context; for example, you can always get the last model output:
session.clone() to create a copy of a given session with its context at given point in time. This allows you to make multiple generation requests with the same objects in your context:
Multiply 2x2 and the LLM’s response to that (presumably 4) in their context. By cloning the session, the new requests both operate independently on that context to get the correct answers to 4 x 3 and 4 x 5.