Repository navigation
v0.18.0
What's Changed
- Add docs and classes for formatting objects in prompts by @jackmpcollins in #126
- Upgrade ruff. Format ... on same line by @jackmpcollins in #134
- poetry update by @jackmpcollins in #133
- Switch from deprecated functions param to tools by @jackmpcollins in #144
- Docs: Fix bytes vision example by @mnicstruwig in #146
New Contributors
- @mnicstruwig made their first contribution in #146
Full Changelog: v0.17.0...v0.18.0
Now fully migrated to tool calls 🎉 Which enables using the new Claude-3 models via litellm, as well as parallel function calls. See more at https://magentic.dev/function-calling/
@prompt(
"Sum {a} and {b}. Also subtract {a} from {b}.",
functions=[plus, minus],
)
def plus_and_minus(a: int, b: int) -> ParallelFunctionCall[int]: ...
output = plus_and_minus(2, 3)
print(list(output))
# > [FunctionCall(<function plus at 0x106b8f010>, 2, 3), FunctionCall(<function minus at 0x106b8ef80>, 3, 2)]
output()
# (5, 1)Warning
Breaking Change: FunctionResultMessage now accepts FunctionCall as argument instead of a function
FunctionResultMessage now (again) takes a FunctionCall instance as its second argument. Further, when constructing a chat message history, the same FunctionCall instance must be passed to an AssistantMessage and the corresponding FunctionResultMessage. This so that the result can be correctly linked back to the function call that created it.
def plus(a: int, b: int) -> int:
return a + b
plus_1_2 = FunctionCall(plus, 1, 2)
@chatprompt(
UserMessage("Use the plus function to add 1 and 2."),
AssistantMessage(plus_1_2),
FunctionResultMessage(3, plus_1_2),
)
def do_math() -> str: ...Example of using the new formatting classes to format a prompt. See more at https://magentic.dev/formatting/
from magentic import prompt
from magentic.formatting import NumberedList
@prompt("Continue the list:\n{items}")
def get_next_items(items: NumberedList[str]) -> list[str]: ...
items = NumberedList(["apple", "banana", "cherry"])
print(get_next_items.format(items=items))
# Continue the list:
# 1. apple
# 2. banana
# 3. cherry