Skip to content
Open
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
27 changes: 27 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE/component.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Component PR

Use this template when adding or modifying components in `mellea/stdlib/components/`.

## Description
- [ ] Link to Issue:

<!-- Brief description of the component being added/modified along with an explanation for why it should be in the standard library. -->

## Implementation Checklist

### Protocol Compliance
- [ ] `parts()` returns list of constituent parts (Components or CBlocks)
- [ ] `format_for_llm()` returns TemplateRepresentation or string
- [ ] `_parse(computed: ModelOutputThunk)` parses model output correctly into the specified Component return type

### Content Blocks
- [ ] CBlock used appropriately for text content
- [ ] ImageBlock used for image content (if applicable)

### Integration
- [ ] Component exported in `mellea/stdlib/components/__init__.py` or, if you are adding a library of components, from your sub-module

### Testing
- [ ] Tests added to `tests/components/`
- [ ] New code has 100% coverage
- [ ] Ensure existing tests and github automation passes (a maintainer will kick off the github automation when the rest of the PR is populated)
18 changes: 18 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE/misc.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Misc PR

## Type of PR

- [ ] Bug Fix
- [ ] New Feature
- [ ] Documentation
- [ ] Other

## Description
- [ ] Link to Issue:

<!-- Brief description of the change being made along with an explanation. -->

### Testing
- [ ] Tests added to the respective file if code was changed
- [ ] New code has 100% coverage if code as added
- [ ] Ensure existing tests and github automation passes (a maintainer will kick off the github automation when the rest of the PR is populated)
30 changes: 30 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE/requirement.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Requirement PR

Use this template when adding or modifying requirements in `mellea/stdlib/requirements/`.

## Description
- [ ] Link to Issue:

<!-- Brief description of the requirement being added/modified along with an explanation for why it should be in the standard library. -->

## Implementation Checklist

### Base Class
- [ ] Extends appropriate base class:
- `Requirement` - standard requirement
- `ALoraRequirement` - uses specialized Intrinsic/Adapter for generation-based validation

### Validation Logic
- [ ] `validation_fn` defined (if using Python-based validation)
- [ ] re-usable functionality within the validation_fn should be separated out into `mellea/stdlib/tools/`
- [ ] `validate` returns a `ValidationResult` with
- [ ] a `thunk` and `context` if using a backend to generate
- [ ] a specific `reason` and `score` when possible

### Integration
- [ ] Requirement exported in `mellea/stdlib/requirements/__init__.py` or, if you are adding a library of requirements, from your sub-module

### Testing
- [ ] Tests added to `tests/requirements/`
- [ ] New code has 100% coverage
- [ ] Ensure existing tests and github automation passes (a maintainer will kick off the github automation when the rest of the PR is populated)
28 changes: 28 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE/sampling.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Sampling Strategy PR

Use this template when adding or modifying sampling strategies in `mellea/stdlib/sampling/`.

## Description
- [ ] Link to Issue:

<!-- Brief description of the sampling strategy being added/modified along with an explanation for why it should be in the standard library. -->

## Implementation Checklist

### Base Class
- [ ] Extends appropriate base class:
- `BaseSamplingStrategy` if your changes are mostly modifying the `repair` and/or `select_from_failure` functions
- `SamplingStrategy` if your changes involve a new `sample` method
- Other defined sampling strategies if your implementation is similar to existing implementations

### Return Value
- [ ] Returns a properly typed `SamplingResult`. Specifically, this means:
- `ModelOutputThunk`s in `sample_generations` are properly typed from the Component and the `parsed_repr` is the expected type.

### Integration
- [ ] Strategy exported in `mellea/stdlib/sampling/__init__.py`

### Testing
- [ ] Tests added to `tests/sampling/`
- [ ] New code has 100% coverage
- [ ] Ensure existing tests and github automation passes (a maintainer will kick off the github automation when the rest of the PR is populated)
22 changes: 22 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE/tool.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Tool PR

Use this template when adding or modifying components in `mellea/stdlib/tools/`.

## Description
- [ ] Link to Issue:

<!-- Brief description of the tool being added/modified along with an explanation for why it should be in the standard library. -->

## Implementation Checklist

### Protocol Compliance
- [ ] Ensure compatibility with existing backends and providers
- For most tools being added as functions, this means that calling `convert_function_to_tool` works

### Integration
- [ ] Tool exported in `mellea/stdlib/tools/__init__.py` or, if you are adding a library of components, from your sub-module

### Testing
- [ ] Tests added to `tests/stdlib/tools/`
- [ ] New code has 100% coverage
- [ ] Ensure existing tests and github automation passes (a maintainer will kick off the github automation when the rest of the PR is populated)
13 changes: 13 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Pull Request

NOTE: Please ensure you have an issue that has been acknowledged by a core contributor and routed you to open a pull request against this repository. Otherwise, please open an issue before continuing with this pull request.

Only modify this text by checking one of the boxes below. This comment will be overwritten with a specific pull request template based off your choice.

Type of Pull Request:

- [ ] Component
- [ ] Requirement
- [ ] Sampling Strategy
- [ ] Tool
- [ ] Misc: Bug Fix, New Feature, Documentation Update, Other
73 changes: 73 additions & 0 deletions .github/workflows/pr-update.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: PR Bot

on:
pull_request_target:
types: [opened, edited]

jobs:
update-pr-body:
runs-on: ubuntu-latest
if: ${{ !contains(github.event.pull_request.body, 'mellea-pr-edited-marker') }}
permissions:
pull-requests: write
contents: read
steps:
- name: Checkout code # Checks out the base branch, not PR branch.
uses: actions/checkout@v4

- name: Detect PR type from checkboxes
id: detect-type
env:
PR_BODY: ${{ github.event.pull_request.body }}
run: |
PR_TYPE=""

# Check for checked boxes (supports [x] and [X])
if echo "$PR_BODY" | grep -qi '\[x\] Component'; then
PR_TYPE="component"
elif echo "$PR_BODY" | grep -qi '\[x\] Requirement'; then
PR_TYPE="requirement"
elif echo "$PR_BODY" | grep -qi '\[x\] Sampling Strategy'; then
PR_TYPE="sampling"
elif echo "$PR_BODY" | grep -qi '\[x\] Tool'; then
PR_TYPE="tool"
elif echo "$PR_BODY" | grep -qi '\[x\] Misc'; then
PR_TYPE="misc"
fi

if [ -z "$PR_TYPE" ]; then
echo "::error::No PR type selected. Please check one of of the boxes from the original pr template."
exit 1
fi

echo "pr_type=$PR_TYPE" >> "$GITHUB_OUTPUT"
echo "Detected PR type: $PR_TYPE"

- name: Update PR body with checklist
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_BODY: ${{ github.event.pull_request.body }}
PR_TYPE: ${{ steps.detect-type.outputs.pr_type }}
run: |
TEMPLATE_FILE=".github/PULL_REQUEST_TEMPLATE/${PR_TYPE}.md"

if [ -f "$TEMPLATE_FILE" ]; then
MARKER="<!-- mellea-pr-edited-marker: do not remove this marker -->"
TEMPLATE_CONTENT=$(cat "$TEMPLATE_FILE")

NEW_BODY="${MARKER}
${TEMPLATE_CONTENT}"

gh pr edit ${{ github.event.pull_request.number }} --body "$NEW_BODY"
echo "Updated PR body with ${PR_TYPE} checklist"
else
echo "::error::Template file not found: $TEMPLATE_FILE"
echo "Something as gone wrong. Contact a maintainer."
exit 1
fi

- name: Comment on PR
uses: mshick/add-pr-comment@b8f338c590a895d50bcbfa6c5859251edc8952fc
with:
message: |
The PR description has been updated. Please fill out the template for your PR to be reviewed.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ the output is checked against the constraints using (in this case) LLM-as-a-judg
```python
# file: https://github.com/generative-computing/mellea/blob/main/docs/examples/instruct_validate_repair/101_email_with_validate.py
from mellea import MelleaSession
from mellea.backends.types import ModelOption
from mellea.backends import ModelOption
from mellea.backends.ollama import OllamaModelBackend
from mellea.backends import model_ids
from mellea.stdlib.sampling import RejectionSamplingStrategy
Expand Down
2 changes: 1 addition & 1 deletion cli/decompose/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from mellea import MelleaSession
from mellea.backends.ollama import OllamaModelBackend
from mellea.backends.openai import OpenAIBackend
from mellea.backends.types import ModelOption
from mellea.backends import ModelOption

from .prompt_modules import (
constraint_extractor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
from typing import Any, TypeVar, final

from mellea import MelleaSession
from mellea.backends.types import ModelOption
from mellea.stdlib.chat import Message
from mellea.backends import ModelOption
from mellea.stdlib.components import Message

from .._prompt_modules import PromptModule, PromptModuleString
from ._exceptions import BackendGenerationError, TagExtractionError
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
from typing import Any, TypeVar, final

from mellea import MelleaSession
from mellea.backends.types import ModelOption
from mellea.stdlib.chat import Message
from mellea.backends import ModelOption
from mellea.stdlib.components import Message

from .._prompt_modules import PromptModule, PromptModuleString
from ._exceptions import BackendGenerationError, TagExtractionError
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
from typing_extensions import Unpack

from mellea import MelleaSession
from mellea.backends.types import ModelOption
from mellea.stdlib.chat import Message
from mellea.backends import ModelOption
from mellea.stdlib.components import Message

from .._prompt_modules import PromptModule, PromptModuleString
from ._exceptions import BackendGenerationError, TagExtractionError
Expand Down
6 changes: 3 additions & 3 deletions cli/decompose/prompt_modules/subtask_list/_subtask_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
from typing import Any, TypeVar, final

from mellea import MelleaSession
from mellea.backends.types import ModelOption
from mellea.stdlib.chat import Message
from mellea.backends import ModelOption
from mellea.stdlib.components import Message

from .._prompt_modules import PromptModule, PromptModuleString
from ._exceptions import (
Expand All @@ -15,7 +15,7 @@
from ._prompt import get_system_prompt, get_user_prompt
from ._types import SubtaskItem

# from mellea.stdlib.requirement import Requirement
# from mellea.stdlib.requirements import requirement

T = TypeVar("T")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
from typing_extensions import Unpack

from mellea import MelleaSession
from mellea.backends.types import ModelOption
from mellea.stdlib.chat import Message
from mellea.backends import ModelOption
from mellea.stdlib.components import Message

from .._prompt_modules import PromptModule, PromptModuleString
from ._exceptions import BackendGenerationError, TagExtractionError
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
from typing import Any, Final, Literal, TypeVar, final

from mellea import MelleaSession
from mellea.backends.types import ModelOption
from mellea.stdlib.chat import Message
from mellea.backends import ModelOption
from mellea.stdlib.components import Message

from .._prompt_modules import PromptModule, PromptModuleString
from ._exceptions import BackendGenerationError, TagExtractionError
Expand Down
4 changes: 2 additions & 2 deletions cli/eval/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
from typing import List

import mellea
from mellea.stdlib.base import ModelOutputThunk
from mellea.core import ModelOutputThunk
from mellea.stdlib.test_based_eval import TestBasedEval
from mellea.backends.types import ModelOption
from mellea.backends import ModelOption

from rich.console import Console
from rich.progress import BarColumn, Progress, SpinnerColumn, TextColumn
Expand Down
3 changes: 2 additions & 1 deletion docs/dev/requirement_aLoRA_rerouting.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ Suppose that the user creates a backend and then adds a generic constraint check

```python
from mellea import start_session
from mellea.stdlib.requirement import Requirement
from mellea.core import Requirement
from mellea.backends.adapters import GraniteCommonAdapter

m = start_session(
"huggingface.LocalHFBackend:ibm-granite/granite-3.2-8b-instruct")
Expand Down
19 changes: 8 additions & 11 deletions docs/examples/agents/react.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,9 @@
from jinja2 import Template

import mellea
import mellea.backends
import mellea.backends.types
import mellea.stdlib
import mellea.stdlib.base
import mellea.stdlib.chat
from mellea.backends import model_ids
from mellea.helpers.fancy_logger import FancyLogger
from mellea.stdlib.base import ChatContext
import mellea.stdlib.components.chat
from mellea.core import FancyLogger
from mellea.stdlib.context import ChatContext

FancyLogger.get_logger().setLevel("ERROR")

Expand Down Expand Up @@ -120,8 +115,8 @@ def react(

# Add the system prompt and the goal to the chat history.
m.ctx = m.ctx.add(
mellea.stdlib.chat.Message(role="system", content=_sys_prompt)
).add(mellea.stdlib.chat.Message(role="user", content=f"{goal}"))
mellea.stdlib.components.chat.Message(role="system", content=_sys_prompt)
).add(mellea.stdlib.components.chat.Message(role="user", content=f"{goal}"))

# The main ReACT loop as a dynamic program:
# ( ?(not done) ;
Expand Down Expand Up @@ -162,7 +157,9 @@ def react(

print("### Observation")
tool_output = react_toolbox.call_tool(selected_tool, act_args.content)
m.ctx = m.ctx.add(mellea.stdlib.chat.Message(role="tool", content=tool_output))
m.ctx = m.ctx.add(
mellea.stdlib.components.chat.Message(role="tool", content=tool_output)
)
print(tool_output)

print("### Done Check")
Expand Down
Loading