Mellea
build enterprise AI without guesswork
build enterprise AI without guesswork
uv pip install melleaCopy
Mellea
Build reliable generative programs with our library that merges the power of LLMs with the predictability of engineering.
Get started- Python not ProseWrite object-oriented code instead of free-form text.
- Requirements DrivenDefine requirements that ensure good model responses.
- Predictable and ResilientProvide structures for failure detection and recovery.
- MCP and A2A CompatibleConnect Mellea programs with other agent frameworks.
Clean interfaces for Gen AI output validation and sampling strategies.
Learn moreimport mellea from mellea.stdlib.sampling import RejectionSamplingStrategy def write_email_with_strategy(m: mellea.MelleaSession, name: str, notes: str) -> str: email_candidate = m.instruct( f"Write an email to {name} using the notes following: {notes}.", requirements=[ "The email should have a salutation.", "Use a formal tone.", ], strategy=RejectionSamplingStrategy(loop_budget=3), return_sampling_results=True, ) if email_candidate.success: return str(email_candidate.result) # If sampling fails, use the first generation print("Expect sub-par result.") return email_candidate.sample_generations[0].valueCopyBuild composable Gen AI using tried-and-true abstractions.
Learn more@mellea.generative def classify_sentiment(text: str) -> Literal["positive", "negative"]: """Classify the sentiment of the input text as 'positive' or 'negative'.""" sentiment = classify_sentiment(m, text=customer_review) if sentiment == "positive": msg = m.instruct("Thank the customer for their post") else: msg = m.instruct( description="Apologize for the customer's negative experience and offer a 5% discount for their next visit", grounding_context={"review": customer_review} ) post_response(msg)CopySeamlessly sprinkle GenAI into existing systems.
Learn moreimport mellea from mellea.stdlib.mify import mify, MifiedProtocol import pandas from io import StringIO @mify(fields_include={"table"}, template="{{ table }}") class MyCompanyDatabase: table: str = """| Store | Sales | | ---------- | ------- | | Northeast | $250 | | Southeast | $80 | | Midwest | $420 |""" def transpose(self): pandas.read_csv( StringIO(self.table), sep='|', skipinitialspace=True, header=0, index_col=False ) m = mellea.start_session() db = MyCompanyDatabase() assert isinstance(db, MifiedProtocol) answer = m.query(db, "What were sales for the Northeast branch this month?") print(str(answer))Copy
import mellea
from mellea.stdlib.sampling import RejectionSamplingStrategy
def write_email_with_strategy(m: mellea.MelleaSession, name: str, notes: str) -> str:
email_candidate = m.instruct(
f"Write an email to {name} using the notes following: {notes}.",
requirements=[
"The email should have a salutation.",
"Use a formal tone.",
],
strategy=RejectionSamplingStrategy(loop_budget=3),
return_sampling_results=True,
)
if email_candidate.success:
return str(email_candidate.result)
# If sampling fails, use the first generation
print("Expect sub-par result.")
return email_candidate.sample_generations[0].value
Copy