版本发布 5
0.6.0 Adds support for recursive types, meaning types can refer to themselves, or other types, in a recursive nature, and it all just works: ```python from dataclasses import dataclass from rich.pretty import pprint from manifest import ai @dataclass class Character: name: str occupation: str social_graph: "SocialGraph" @dataclass class SocialGraph: friends: list[Character] enemies: list[Character] @ai def get_character_social_graph(character_name: str) -> SocialGraph: """For a given fictional character, return their social graph, resolving each friend and enemy's social graph recursively.""" graph = get_character_social_graph("Walter White") pprint(graph) ``` ``` SocialGraph( friends=[ Character( name='Jesse Pinkman', occupation='Meth Manufacturer', social_graph=SocialGraph( friends=[Character(name='Walter White', occupation='Chemistry Teacher', social_graph=SocialGraph(friends=[], enemies=[]))], enemies=[Character(name='Hank Schrader', occupation='DEA Agent', social_graph=SocialGraph(friends=[], enemies=[]))] ) ), Character( name='Saul Goodman', occupation='Lawyer', social_graph=SocialGraph(friends=[Character(name='Walter White', occupation='Chemistry Teacher', social_graph=SocialGraph(friends=[], enemies=[]))], enemies=[]) ) ], enemies=[ Character( name='Hank Schrader', occupation='DEA Agent', social_graph=SocialGraph( friends=[Character(name='Marie Schrader', occupation='Radiologic Technologist', social_graph=SocialGraph(friends=[], enemies=[]))], enemies=[Character(name='Walter White', occupation='Meth Manufacturer', social_graph=SocialGraph(friends=[], enemies=[]))] ) ), Character( name='Gus Fring', occupation='Businessman', social_graph=SocialGraph( friends=[Character(name='Mike Ehrmantraut', occupation='Fixer', social_graph=SocialGraph(friends=[], enemies=[]))], enemies=[Character(name='Walter White', occupation='Meth Manufacturer', social_graph=SocialGraph(friends=[], enemies=[]))] ) ) ] ) ```
OpenAI [now supports jsonschema](https://platform.openai.com/docs/guides/structured-outputs/json-mode), which simplifies how we were guiding jsonschema-conformant output. This release uses that feature, which makes outputs more reliable.
We introduce a `retry` argument on the `@ai` decorator to make LLM execution a little more robust. We also fix a few type checking errors.
Now you'll receive much better errors if manifest runs without required environment variables. For example: ``` manifest.py error: No LLM api keys found, try defining one of the following environment variables in a .env file or in your environment, then re-running the program: - OPENAI_API_KEY For advanced users, you may manually initialize the LLM client in your code by calling `manifest.init(client_maker)`, where `client_maker` is a function that returns an LLM client. Exiting. ```
# Function execution Handles the execution of an arbitrary function on an LLM ```python from manifest import ai @ai def translate(english_text: str, target_lang: str) -> str: """ Translates text from english into a target language """ assert translate("Hello", "fr") == "Bonjour" ``` # Multimodal images Allows seamless image uploads ```python from pathlib import Path from manifest import ai @ai def breed_of_dog(image: Path) -> str: """Determines the breed of dog from a photo""" image = Path("path/to/dog.jpg") print(breed_of_dog(image)) ```