Skip to content

Commit 4ee56a9

Browse files
feat: add async and streaming support (#137)
* init changes for ollama and common functions * feat: add async support to all backends; add some helpers * feat: add support for generatelogs to async; fix a few bugs * fix: don't copy objects in a context * feat: move processing funcs to partial bind, cleanup genlogs * feat: add async tests and minor tweaks * fix: watsonx tests * feat: add support for aloras; could not test vllm * fix: fix validation sig errors caused by rebasing to main * fix: cleanup * fix: cleanup code * test: fixing testing for openai tests with ollama * fix: some tests and add some comments * fix: apply proper pytest marks to new tests * ci: adding action to free disk space * fix: resolve addtl references to backend.generate_from_context --------- Co-authored-by: Avinash Balakrishnan <[email protected]>
1 parent b18e03d commit 4ee56a9

File tree

34 files changed

+1875
-546
lines changed

34 files changed

+1875
-546
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: 'Free Disk Space'
2+
description: 'Frees disk space on the runner'
3+
runs:
4+
using: "composite"
5+
steps:
6+
- name: Print disk space before cleanup
7+
run: |
8+
df -h
9+
shell: bash
10+
- name: Free Disk Space Linux
11+
if: runner.os == 'Linux'
12+
run: |
13+
sudo docker rmi "$(docker image ls -aq)" >/dev/null 2>&1 || true
14+
sudo rm -rf \
15+
/usr/share/dotnet /usr/local/lib/android /opt/ghc \
16+
/usr/local/share/powershell /usr/share/swift /usr/local/.ghcup \
17+
/usr/lib/jvm || true
18+
sudo apt install aptitude -y >/dev/null 2>&1
19+
sudo aptitude purge '~n ^mysql' -f -y >/dev/null 2>&1
20+
sudo aptitude purge '~n ^dotnet' -f -y >/dev/null 2>&1
21+
sudo apt-get autoremove -y >/dev/null 2>&1
22+
sudo apt-get autoclean -y >/dev/null 2>&1
23+
shell: bash
24+
- name: Print disk space after cleanup
25+
run: |
26+
df -h
27+
shell: bash

.github/workflows/quality.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ jobs:
2121
python-version: ['3.10', '3.11', '3.12'] # Need to add 3.13 once we resolve outlines issues.
2222
steps:
2323
- uses: actions/checkout@v4
24+
- name: Free disk space
25+
uses: ./.github/actions/free-disk-space
2426
- name: Install uv and set the python version
2527
uses: astral-sh/setup-uv@v5
2628
with:

cli/decompose/prompt_modules/constraint_extractor/_constraint_extractor.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from mellea import MelleaSession
66
from mellea.backends.types import ModelOption
7+
from mellea.stdlib.base import CBlock
78
from mellea.stdlib.instruction import Instruction
89

910
from .._prompt_modules import PromptModule, PromptModuleString
@@ -114,9 +115,8 @@ def generate( # type: ignore[override]
114115
instruction = Instruction(description=user_prompt, prefix=system_prompt)
115116

116117
try:
117-
gen_result = mellea_session.backend.generate_from_context(
118+
gen_result = mellea_session.act(
118119
action=instruction,
119-
ctx=mellea_session.ctx,
120120
model_options={
121121
ModelOption.TEMPERATURE: 0,
122122
ModelOption.MAX_NEW_TOKENS: max_new_tokens,

cli/decompose/prompt_modules/subtask_constraint_assign/_subtask_constraint_assign.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,9 +216,8 @@ def generate( # type: ignore[override]
216216
instruction = Instruction(description=user_prompt, prefix=system_prompt)
217217

218218
try:
219-
gen_result = mellea_session.backend.generate_from_context(
219+
gen_result = mellea_session.act(
220220
action=instruction,
221-
ctx=mellea_session.ctx,
222221
model_options={
223222
ModelOption.TEMPERATURE: 0,
224223
ModelOption.MAX_NEW_TOKENS: max_new_tokens,

cli/decompose/prompt_modules/subtask_list/_subtask_list.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,8 @@ def generate(
144144
instruction = Instruction(description=user_prompt, prefix=system_prompt)
145145

146146
try:
147-
gen_result = mellea_session.backend.generate_from_context(
147+
gen_result = mellea_session.act(
148148
action=instruction,
149-
ctx=mellea_session.ctx,
150149
model_options={
151150
ModelOption.TEMPERATURE: 0,
152151
ModelOption.MAX_NEW_TOKENS: max_new_tokens,

cli/decompose/prompt_modules/subtask_prompt_generator/_subtask_prompt_generator.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,8 @@ def generate( # type: ignore[override]
218218
instruction = Instruction(description=user_prompt, prefix=system_prompt)
219219

220220
try:
221-
gen_result = mellea_session.backend.generate_from_context(
221+
gen_result = mellea_session.act(
222222
action=instruction,
223-
ctx=mellea_session.ctx,
224223
model_options={
225224
ModelOption.TEMPERATURE: 0,
226225
ModelOption.MAX_NEW_TOKENS: max_new_tokens,

docs/examples/mify/rich_document_advanced.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
# Note: Because the template for a RichDocument just outputs it as markdown,
4545
# the model doesn't really know what to do with it in this context. However, this
4646
# is a useful pattern if you want to use a component with a specified template.
47-
thunk = m.backend.generate_from_context(action=rd, ctx=m.ctx)
47+
thunk = m.act(action=rd)
4848
print(thunk.value) # > - user: What is the primary goal of the GLTR tool...
4949

5050
# 5. The class is opinionated and outputs the document as markdown to the model (like in the initial example).
@@ -87,7 +87,7 @@ def from_document_file(
8787
rds.format_for_llm().args
8888
) # > {'titles': ['GLTR: Statistical Detection and Visualization of Generated Text', 'Abstract', ..., 'References']}
8989

90-
thunk = m.backend.generate_from_context(action=rds, ctx=m.ctx)
90+
thunk = m.act(action=rds)
9191
print(thunk.value) # > The document appears to be an academic research paper...
9292

9393
# 6. We can also pass this document as grounding context to an instruction.

mellea/backends/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,9 @@ def generate_from_context(
4141
*,
4242
format: type[BaseModelSubclass] | None = None,
4343
model_options: dict | None = None,
44-
generate_logs: list[GenerateLog] | None = None,
4544
tool_calls: bool = False,
4645
) -> ModelOutputThunk: # i.e., ContextDiff
47-
"""Generates a model output from a context. May not mutate the context.
46+
"""Generates a model output from a context. May not mutate the context. This must be called from a running event loop as it creates a task to run the generation request.
4847
4948
Args:
5049
action: The last item of the context should be passed in as an `action` instead of as part of the `ctx`. See `docs/dev/generate_signature_decisions.md`.

mellea/backends/aloras/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import abc
44

5-
from mellea.stdlib.base import CBlock
5+
from mellea.stdlib.base import CBlock, ModelOutputThunk
66

77

88
class Alora(abc.ABC):
@@ -24,8 +24,8 @@ def __init__(self, name: str):
2424
self.name: str = name
2525

2626
@abc.abstractmethod
27-
def generate_using_strings(self, *args, **kwargs) -> str:
28-
"""Generates from the ALora using raw strings as the interface for both inputs and outputs.
27+
def generate_using_strings(self, *args, **kwargs) -> ModelOutputThunk:
28+
"""Generates from the ALora using raw strings as the interface for inputs. In most cases, must be run from a running event loop.
2929
3030
This has a generic signature because each aLoRA has different parameters depending on its functionality and how it gets called.
3131
"""

0 commit comments

Comments
 (0)