Mellea.ai build enterprise AI without guesswork

uv pip install mellea
GitHub

Write simple, effective program in place of “instruction essays”

With Mellea
Without Mellea
  • Unpredictability ManagementProvide structures for failure detection and recovery for LLM outputs.
  • Robust and ComposableRequirement-driven pipelines deliver rock-solid libraries and apps.
  • Ready to ScaleSwap engines and models effortlessly. Scale in a single line.
  • Efficiency in Model UsageGenerative programs can do Big Model Things without Big model hardware.
  • Model AgnosticMore precise and predictable outcomes, regardless of the initial model.
  • Reusability & PortabilityPortable libraries that simplify prompts and optimize implementations.
  • Clean interfaces for Gen AI output validation and sampling strategies.

    Learn more
    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
    
  • Build 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)
    
  • Seamlessly sprinkle GenAI into existing systems.

    Learn more
    import 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))
    
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