Skip to content

Commit

Permalink
update README to show CleanFormatter rather than JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
SlapDrone committed Aug 12, 2023
1 parent bf23cf6 commit 701b907
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Person(BaseModel):
((Person(name="alice", age=22, cars=[Car(model="mini", speed = 180)]),), [Car(model='inim', speed=180.0)]),
((Person(name="bob", age=53, cars=[Car(model="ford", speed=200), Car(model="renault", speed=210)]),), [Car(model='drof', speed=200.0), Car(model='tluaner', speed=210.0)]),
],
example_formatter=JsonFormatter()
example_formatter=CleanFormatter() # or JsonFormatter
)
def generate_backwards_car_names(person: Person, **kwargs) -> list[Car]:
"""
Expand All @@ -44,8 +44,10 @@ print(generate_backwards_car_names.description)
Given a person, return a list of their cars with the model names backwards.

Examples:
{"person": {"name": "alice", "age": 22, "cars": [{"model": "mini", "speed": 180.0}]}} -> [{"model": "inim", "speed": 180.0}]
{"person": {"name": "bob", "age": 53, "cars": [{"model": "ford", "speed": 200.0}, {"model": "renault", "speed": 210.0}]}} -> [{"model": "drof", "speed": 200.0}, {"model": "tluaner", "speed": 210.0}]
generate_backwards_car_names(person=Person(name='alice', age=22, cars=[Car(model='mini', speed=180.0)])) -> [Car(model='inim', speed=180.0)]

generate_backwards_car_names(person=Person(name='bob', age=53, cars=[Car(model='ford', speed=200.0), Car(model='renault', speed=210.0)])) -> [Car(model='drof', speed=200.0), Car(model='tluaner', speed=210.0)]


In the example above, the `generate_backwards_car_names` function is an AI function defined using Marvin's `ai_fn` decorator. The function's body is empty, as the actual implementation is provided by the AI. The `few_shot` decorator enriches the function's docstring with examples of its usage, formatted as JSON.

Expand Down Expand Up @@ -83,7 +85,7 @@ poetry add few-shot
The main feature of Few_Shot is the `few_shot` decorator. This decorator takes a function and a set of examples, and generates a docstring for the function that includes these examples. The examples are validated against the function's signature and return type, ensuring that they are correct. The decorator has several optional arguments that allow you to customize how the examples are formatted and included in the docstring:

- `examples`: A list of examples, where each example is a tuple containing arguments, keyword arguments, and the expected output of the function.
- `example_formatter`: An instance of a class implementing the FormatterProtocol (just the `format` method, taking an `Example`). Default is `ReprFormatter()`.
- `example_formatter`: An instance of a class implementing the FormatterProtocol (just the `format` method, taking an `Example`). Default is `CleanFormatter()`.
- `docstring_template`: A string template for the docstring. The string "{examples}" in the template will be replaced with the formatted examples. Default is "{examples}".
- `join_str`: A string used to join multiple example strings in the docstring. Default is "\n".
- `default_format`: A string that is prepended to the examples in the docstring. Default is "\nExamples:\n".
Expand Down

0 comments on commit 701b907

Please sign in to comment.