Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion mellea/backends/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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@@@"
Expand Down
2 changes: 2 additions & 0 deletions mellea/stdlib/genslot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
27 changes: 9 additions & 18 deletions mellea/stdlib/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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?")
Expand All @@ -224,6 +214,7 @@ def clone(self):
>>> out = m2.instruct("Multiply that by 3")
>>> print(out)
... 12
```
"""
return copy(self)

Expand Down
Loading