Initial commit: PROMETHEUS v0.1.0 - Prompt optimizer

- Clean architecture (domain/application/infrastructure)
- DSPy-based evolution engine with scoring
- CLI via pyproject.toml entry point
- Unit + integration tests (~300 tests)
- Configs for glm-5.1 and glm-4.5-air models
- Z.AI endpoint integration
This commit is contained in:
2026-03-29 11:44:03 +00:00
commit 837a44970f
49 changed files with 6599 additions and 0 deletions

View File

@@ -0,0 +1,47 @@
"""
Adapter: Reflective Mutation Proposer.
Implements the ProposerPort via the DSPy InstructionProposer.
Converts trajectories into readable format for the LLM proposer.
"""
from __future__ import annotations
from prometheus.domain.entities import Prompt, Trajectory
from prometheus.domain.ports import ProposerPort
from prometheus.infrastructure.dspy_modules import InstructionProposer
class DSPyProposerAdapter(ProposerPort):
"""Uses evaluation trajectories to build a failure report and propose a new prompt."""
def __init__(self) -> None:
self._proposer = InstructionProposer()
def propose(
self,
current_prompt: Prompt,
trajectories: list[Trajectory],
task_description: str,
) -> Prompt:
failure_examples = self._format_failures(trajectories)
pred = self._proposer(
current_instruction=current_prompt.text,
task_description=task_description,
failure_examples=failure_examples,
)
return Prompt(text=pred.new_instruction)
@staticmethod
def _format_failures(trajectories: list[Trajectory]) -> str:
"""Convert trajectories into a structured textual report."""
sections: list[str] = []
for i, t in enumerate(trajectories, 1):
section = (
f"# Example {i}\n"
f"## Input\n{t.input_text}\n\n"
f"## Generated Output\n{t.output_text}\n\n"
f"## Score\n{t.score:.2f}\n\n"
f"## Feedback\n{t.feedback}\n"
)
sections.append(section)
return "\n---\n".join(sections)