diff --git a/mellea/backends/types.py b/mellea/backends/types.py index 89f03851..3ee0571d 100644 --- a/mellea/backends/types.py +++ b/mellea/backends/types.py @@ -14,8 +14,13 @@ class ModelOption: Create a dictionary containing model options like this: + ```python from mellea.backends.types import ModelOption - model_options = { ModelOption.TEMPERATURE : 0.0, ModelOption.SYSTEM_PROMPT : "You are a helpful assistant" } + model_options = { + ModelOption.TEMPERATURE : 0.0, + ModelOption.SYSTEM_PROMPT : "You are a helpful assistant" + } + ``` """ TOOLS = "@@@tools@@@" diff --git a/mellea/stdlib/genslot.py b/mellea/stdlib/genslot.py index a020d4e8..0124d674 100644 --- a/mellea/stdlib/genslot.py +++ b/mellea/stdlib/genslot.py @@ -739,6 +739,7 @@ def generative(func: Callable[P, R]) -> GenerativeSlot[P, R]: PreconditionException: (raised when calling the generative slot) if the precondition validation of the args fails; catch the exception to get the validation results Examples: + ```python >>> from mellea import generative, start_session >>> session = start_session() >>> @generative @@ -813,6 +814,7 @@ def generative(func: Callable[P, R]) -> GenerativeSlot[P, R]: ... ... >>> >>> reasoning = generate_chain_of_thought(session, problem="How to optimize a slow database query?") + ``` """ if inspect.iscoroutinefunction(func): return AsyncGenerativeSlot(func) diff --git a/mellea/stdlib/session.py b/mellea/stdlib/session.py index 91d1be24..db4f47be 100644 --- a/mellea/stdlib/session.py +++ b/mellea/stdlib/session.py @@ -110,38 +110,27 @@ def start_session( MelleaSession: A session object that can be used as a context manager or called directly with session methods. - Usage: - # As a context manager (sets global session): - with start_session("ollama", "granite3.3:8b") as session: - result = instruct("Generate a story") # Uses current session - # session is also available directly - other_result = session.chat("Hello") - - # Direct usage (no global session set): - session = start_session("ollama", "granite3.3:8b") - result = session.instruct("Generate a story") - # Remember to call session.cleanup() when done - session.cleanup() - Examples: + ```python # Basic usage with default settings with start_session() as session: - response = instruct("Explain quantum computing") + response = session.instruct("Explain quantum computing") # Using OpenAI with custom model options with start_session("openai", "gpt-4", model_options={"temperature": 0.7}): - response = chat("Write a poem") + response = session.chat("Write a poem") # Using HuggingFace with ChatContext for conversations from mellea.stdlib.base import ChatContext with start_session("hf", "microsoft/DialoGPT-medium", ctx=ChatContext()): - chat("Hello!") - chat("How are you?") # Remembers previous message + session.chat("Hello!") + session.chat("How are you?") # Remembers previous message - # Direct usage without context manager + # Direct usage. session = start_session() response = session.instruct("Explain quantum computing") session.cleanup() + ``` """ backend_class = backend_name_to_class(backend_name) if backend_class is None: @@ -211,6 +200,7 @@ def clone(self): a copy of the current session. Keeps the context, backend, and session logger. Examples: + ```python >>> from mellea import start_session >>> m = start_session() >>> m.instruct("What is 2x2?") @@ -224,6 +214,7 @@ def clone(self): >>> out = m2.instruct("Multiply that by 3") >>> print(out) ... 12 + ``` """ return copy(self)