Magentic

Latest version: v0.32.0

Safety actively analyzes 682416 Python packages for vulnerabilities to keep your Python projects secure.

Scan your dependencies

Page 5 of 10

0.19.0a0

Prerelease for testing PR https://github.com/jackmpcollins/magentic/pull/174

0.18.1

What's Changed
* Fix: LiteLLM Anthropic async tool calls by jackmpcollins in https://github.com/jackmpcollins/magentic/pull/155
* Make dependabot ignore patch version updates by jackmpcollins in https://github.com/jackmpcollins/magentic/pull/157
* Add github workflow options to run existing live tests by jackmpcollins in https://github.com/jackmpcollins/magentic/pull/159
* Load .env file for tests. Fix flaky return_dict test. by jackmpcollins in https://github.com/jackmpcollins/magentic/pull/160
* Remove tool_call.type check to fix LiteLLM Mistral tool calling by jackmpcollins in https://github.com/jackmpcollins/magentic/pull/161


**Full Changelog**: https://github.com/jackmpcollins/magentic/compare/v0.18.0...v0.18.1

0.18.0

What's Changed
* Add docs and classes for formatting objects in prompts by jackmpcollins in https://github.com/jackmpcollins/magentic/pull/126
* Upgrade ruff. Format ... on same line by jackmpcollins in https://github.com/jackmpcollins/magentic/pull/134
* poetry update by jackmpcollins in https://github.com/jackmpcollins/magentic/pull/133
* Switch from deprecated functions param to tools by jackmpcollins in https://github.com/jackmpcollins/magentic/pull/144
* Docs: Fix bytes vision example by mnicstruwig in https://github.com/jackmpcollins/magentic/pull/146

New Contributors
* mnicstruwig made their first contribution in https://github.com/jackmpcollins/magentic/pull/146

**Full Changelog**: https://github.com/jackmpcollins/magentic/compare/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/

python
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.

python
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/

python
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

0.18.0a0

Prerelease for testing PR https://github.com/jackmpcollins/magentic/pull/144

0.17.0

What's Changed
* Add support for GPT4 vision by jackmpcollins in https://github.com/jackmpcollins/magentic/pull/116


**Full Changelog**: https://github.com/jackmpcollins/magentic/compare/v0.16.0...v0.17.0

---

Add support for GPT4 Vision with new `UserImageMessage` message type. See https://magentic.dev/vision/

python
from magentic import chatprompt, OpenaiChatModel, Placeholder, UserMessage
from magentic.vision import UserImageMessage


IMAGE_URL_WOODEN_BOARDWALK = "https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Gfp-wisconsin-madison-the-nature-boardwalk.jpg/2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg"


chatprompt(
UserMessage("Describe the following image in one sentence."),
UserImageMessage(Placeholder(str, "image_url")),
model=OpenaiChatModel("gpt-4-vision-preview", max_tokens=2000),
)
def describe_image(image_url: str) -> str:
...


describe_image(IMAGE_URL_WOODEN_BOARDWALK)
'A wooden boardwalk meanders through lush green wetlands under a partly cloudy blue sky.'

0.16.0

What's Changed
* Enable registration of new FunctionSchemas by jackmpcollins in https://github.com/jackmpcollins/magentic/pull/119
* Update pre-commit hooks by jackmpcollins in https://github.com/jackmpcollins/magentic/pull/120
* Add docs site by jackmpcollins in https://github.com/jackmpcollins/magentic/pull/124
* Add Placeholder class for templating by jackmpcollins in https://github.com/jackmpcollins/magentic/pull/118
* poetry update by jackmpcollins in https://github.com/jackmpcollins/magentic/pull/125


**Full Changelog**: https://github.com/jackmpcollins/magentic/compare/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/

python
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:

python
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')

Page 5 of 10

© 2024 Safety CLI Cybersecurity Inc. All Rights Reserved.