Magentic

Latest version: v0.32.0

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

Scan your dependencies

Page 4 of 10

0.22.0

What's Changed

- 🚀 Forced function calling using the new `tool_choice: "required"` argument from OpenAI. This means no more `StructuredOutputError` caused by the model returning a string when it was not in the return annotation (for prompt-functions with a union return type. Single return types were already forced).

PRs

* Use tool_choice required for OpenaiChatModel by jackmpcollins in https://github.com/jackmpcollins/magentic/pull/201
* Bump tqdm from 4.66.2 to 4.66.3 by dependabot in https://github.com/jackmpcollins/magentic/pull/200
* Bump mkdocs from 1.5.3 to 1.6.0 by dependabot in https://github.com/jackmpcollins/magentic/pull/198
* Bump pytest from 8.1.1 to 8.2.0 by dependabot in https://github.com/jackmpcollins/magentic/pull/197
* Bump mypy from 1.9.0 to 1.10.0 by dependabot in https://github.com/jackmpcollins/magentic/pull/196

**Full Changelog**: https://github.com/jackmpcollins/magentic/compare/v0.21.1...v0.22.0

0.21.1

What's Changed
* Remove duplicate chat prompting section from readme by jackmpcollins in https://github.com/jackmpcollins/magentic/pull/193
* Bump ruff from 0.3.0 to 0.4.1 by dependabot in https://github.com/jackmpcollins/magentic/pull/192
* Bump openai from 1.17.1 to 1.23.2 by dependabot in https://github.com/jackmpcollins/magentic/pull/190
* Bump pydantic from 2.6.3 to 2.7.0 by dependabot in https://github.com/jackmpcollins/magentic/pull/191
* Include generated text in error message for "string not expected" by jackmpcollins in https://github.com/jackmpcollins/magentic/pull/195


**Full Changelog**: https://github.com/jackmpcollins/magentic/compare/v0.21.0...v0.21.1

---

The error message for when the model returns a string when not expected now contains the start of the returned string. For example:


StructuredOutputError: String was returned by model but not expected. You may need to update your prompt to encourage the model to return a specific type. Model output: '{ "name": "return_list_of_int", "arguments": { "properties": { "value": { "items": [1, 2, 3], [...]'

0.21.0

What's Changed
* Improve function calling docs by jackmpcollins in https://github.com/jackmpcollins/magentic/pull/186
* Add vision example: renaming screenshots by jackmpcollins in https://github.com/jackmpcollins/magentic/pull/187
* Improve RAG example notebook using GitHub search by jackmpcollins in https://github.com/jackmpcollins/magentic/pull/188
* Add Mistral backend by jackmpcollins in https://github.com/jackmpcollins/magentic/pull/189


**Full Changelog**: https://github.com/jackmpcollins/magentic/compare/v0.20.1...v0.21.0

---

Mistral API now supported natively 🚀

with full support for `StreamedStr`, `ParallelFunctionCall`, etc. Example:

python
from magentic import prompt
from magentic.chat_model.mistral_chat_model import MistralChatModel
from pydantic import BaseModel


class Superhero(BaseModel):
name: str
age: int
power: str
enemies: list[str]


prompt(
"""Create a Superhero named {name}""",
model=MistralChatModel("mistral-large-latest"),
)
def create_superhero(name: str) -> Superhero: ...


create_superhero("Garden Man")
Superhero(name='Garden Man', age=35, power='Plant control', enemies=['Smog', 'Deforestator'])

0.20.1

What's Changed
* Add support for passing metadata on LitellmChatModel by hspak in https://github.com/jackmpcollins/magentic/pull/185


**Full Changelog**: https://github.com/jackmpcollins/magentic/compare/v0.20.0...v0.20.1

---

Example of passing litellm metadata

python
prompt(
"Create a Superhero named {name}.",
model=LitellmChatModel("gpt-4", metadata={"foo": "bar"})
)
def create_superhero(name: str) -> Superhero: ...

0.20.0

> [!Warning]
> The default model for magentic is now `gpt-4-turbo` instead of `gpt-3.5-turbo`. See [Configuration](https://magentic.dev/configuration/) for how to change this.

What's Changed

* Tidy up docs by jackmpcollins in https://github.com/jackmpcollins/magentic/pull/181
* Set default LLM to gpt-4-turbo. Update vision docs. by jackmpcollins in https://github.com/jackmpcollins/magentic/pull/183
* Bump anthropic from 0.23.1 to 0.25.1 by dependabot in https://github.com/jackmpcollins/magentic/pull/180
* Bump peaceiris/actions-gh-pages from 3 to 4 by dependabot in https://github.com/jackmpcollins/magentic/pull/178
* Bump aiohttp from 3.9.3 to 3.9.4 by dependabot in https://github.com/jackmpcollins/magentic/pull/182
* Bump idna from 3.6 to 3.7 by dependabot in https://github.com/jackmpcollins/magentic/pull/176
* Bump openai from 1.14.2 to 1.17.1 by dependabot in https://github.com/jackmpcollins/magentic/pull/177
* Bump litellm from 1.34.0 to 1.35.5 by dependabot in https://github.com/jackmpcollins/magentic/pull/179
* Included fix for Anthropic responses that contain _both_ content and tool_calls

**Full Changelog**: https://github.com/jackmpcollins/magentic/compare/v0.19.0...v0.20.0

---

Having a default of `gpt-4-turbo` enables using vision with function calling by default

python
from pydantic import BaseModel, Field

from magentic import chatprompt, 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"


class ImageDetails(BaseModel):
description: str = Field(description="A brief description of the image.")
name: str = Field(description="A short name.")


chatprompt(
UserMessage("Describe the following image in one sentence."),
UserImageMessage(IMAGE_URL_WOODEN_BOARDWALK),
)
def describe_image() -> ImageDetails: ...


image_details = describe_image()
print(image_details.name)
'Wooden Boardwalk in Green Wetland'
print(image_details.description)
'A serene wooden boardwalk meanders through a lush green wetland under a blue sky dotted with clouds.'

0.19.0

What's Changed
* Publish docs on release or manually by jackmpcollins in https://github.com/jackmpcollins/magentic/pull/162
* Bump pytest-cov from 4.1.0 to 5.0.0 by dependabot in https://github.com/jackmpcollins/magentic/pull/165
* Add Structured Output docs by jackmpcollins in https://github.com/jackmpcollins/magentic/pull/167
* Remove unneeded wrapper functions for openai and litellm completion by jackmpcollins in https://github.com/jackmpcollins/magentic/pull/171
* Add AnthropicChatModel by jackmpcollins in https://github.com/jackmpcollins/magentic/pull/174


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

---

🎉 Native support for Anthropic using `AnthropicChatModel` 🎉

python
from magentic import prompt
from magentic.chat_model.anthropic_chat_model import AnthropicChatModel


prompt(
"Name three fruits. Be sure to return this in correct JSON format matching the schema.",
model=AnthropicChatModel("claude-3-opus-20240229")
)
def say_fruit() -> list[str]: ...

say_fruit()

Page 4 of 10

© 2024 Safety CLI Cybersecurity Inc. All Rights Reserved.