Skip to content

v0.16.0

Choose a tag to compare

@jackmpcollins jackmpcollins released this 28 Feb 07:09
· 168 commits to main since this release

What's Changed

Full Changelog: v0.15.0...v0.16.0


New docs site 🎉 https://magentic.dev


Custom types can now be registered to be used as return type annotations with @prompt-decorated functions. For example, after registering a pandas DataFrame the following example works. See the docs page for how to do this: https://magentic.dev/examples/registering_custom_type/

import pandas as pd
from magentic import prompt


@prompt(
    "Create a table listing the ingredients needed to cook {dish}."
    "Include a column for the quantity of each ingredient."
    "Also include a column with alergy information."
)
def list_ingredients(dish: str) -> pd.DataFrame:
    ...


list_ingredients("lasagna")
# <DataFrame of ingredients>

The Placeholder class has been added to enable better templating of AssistantMessage and custom Message subclasses. More info in docs https://magentic.dev/chat-prompting/#placeholder . Sample usage:

from magentic import chatprompt, AssistantMessage, Placeholder, UserMessage
from pydantic import BaseModel


class Quote(BaseModel):
    quote: str
    character: str


@chatprompt(
    UserMessage("Tell me a quote from {movie}"),
    AssistantMessage(Placeholder(Quote, "quote")),
    UserMessage("What is a similar quote from the same movie?"),
)
def get_similar_quote(movie: str, quote: Quote) -> Quote:
    ...


get_similar_quote(
    movie="Star Wars",
    quote=Quote(quote="I am your father", character="Darth Vader"),
)
# Quote(quote='The Force will be with you, always.', character='Obi-Wan Kenobi')