You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: docs/docs/interactive/assistants.md
+2-1
Original file line number
Diff line number
Diff line change
@@ -74,10 +74,11 @@ Each assistant can be given a list of `tools` that it can use when responding to
74
74
75
75
OpenAI provides a small number of built-in tools for assistants. The most useful is the "code interpreter", which lets the assistant write and execute Python code. To use the code interpreter, add it to your assistant's list of tools.
76
76
77
-
!!! example "Using the code interpreter"
78
77
79
78
This assistant uses the code interpreter to generate a plot of sin(x). Note that Marvin's utility for pretty-printing messages to the terminal can't show the plot inline, but will download it and show a link to the file instead.
80
79
80
+
!!! example "Using assistants with the code interpreter"
81
+
81
82
```python
82
83
from marvin.beta import Assistant
83
84
from marvin.beta.assistants import pprint_messages, CodeInterpreter
Copy file name to clipboardexpand all lines: docs/docs/text/functions.md
+111-66
Original file line number
Diff line number
Diff line change
@@ -87,82 +87,127 @@ When this function is called with `n=3`, the LLM will see the string ``"... of 3
87
87
### Parameters
88
88
89
89
The function's parameters, in conjunction with the docstring, provide the LLM with runtime context. The LLM will see the parameter names, types, defaults, and runtime values, and use this information to generate the output. Parameters are important for collecting information, but because the information is ultimately going to an LLM, they can be named anything and take any value that is conducive to generating the right output.
90
-
or example, if you have a function that returns a list of recipes, you might define it like this:
91
90
92
-
```python
93
-
@marvin.fn
94
-
defrecipe(
95
-
ingredients: list[str],
96
-
max_cook_time: int=15,
97
-
cuisine: str="North Italy",
98
-
experience_level="beginner"
99
-
) -> str:
100
-
"""
101
-
Returns a complete recipe that uses all the `ingredients` and
102
-
takes less than `max_cook_time` minutes to prepare. Takes
103
-
`cuisine` style and the chef's `experience_level` into account
104
-
as well. Recipes have a name, list of ingredients, and steps to follow.
105
-
"""
106
-
```
107
-
108
-
Now we can call this function in ways that would be impossible to code in Python:
109
-
110
-
=== "Novice chef"
91
+
For example, if you have a function that returns a list of recipes, you might define it like this:
111
92
93
+
!!! example "Generating recipes"
112
94
```python
113
-
recipe(
114
-
["chicken", "potatoes"],
115
-
experience_level='can barely boil water'
116
-
)
117
-
```
95
+
import marvin
96
+
from pydantic import BaseModel
118
97
119
98
120
-
!!! success "Result"
121
-
Recipe for Simple North Italian Chicken and Potatoes
122
-
123
-
Ingredients:
124
-
125
-
- Chicken
126
-
- Potatoes
127
-
128
-
Instructions:
129
-
130
-
1. Wash the potatoes and cut them into quarters.
131
-
2. Place potatoes in a microwave-safe dish, cover with water, and microwave for 10 minutes until soft.
132
-
...
133
-
99
+
classRecipe(BaseModel):
100
+
name: str
101
+
cook_time_minutes: int
102
+
ingredients: list[str]
103
+
steps: list[str]
134
104
135
-
=== "Expert chef"
136
105
137
-
```python
138
-
recipe(
139
-
["chicken", "potatoes"],
140
-
max_cook_time=60,
141
-
experience_level='born wearing a toque'
142
-
)
106
+
@marvin.fn
107
+
defrecipe(
108
+
ingredients: list[str],
109
+
max_cook_time: int=15,
110
+
cuisine: str="North Italy",
111
+
experience_level:str="beginner"
112
+
) -> Recipe:
113
+
"""
114
+
Returns a complete recipe that uses all the `ingredients` and
115
+
takes less than `max_cook_time` minutes to prepare. Takes
116
+
`cuisine` style and the chef's `experience_level` into account
117
+
as well.
118
+
"""
143
119
```
144
120
121
+
!!! success "Results"
122
+
==="Novice chef"
123
+
124
+
Call the function:
125
+
```python
126
+
result = recipe(
127
+
["chicken", "potatoes"],
128
+
experience_level="can barely boil water",
129
+
)
130
+
```
131
+
132
+
View the result:
133
+
134
+
```python
135
+
Recipe(
136
+
name="Simple Chicken and Potatoes",
137
+
cook_time_minutes=15,
138
+
ingredients=["chicken", "potatoes"],
139
+
steps=[
140
+
"Wash the potatoes and cut them into small cubes.",
141
+
(
142
+
"Heat oil in a pan and cook the chicken over medium heat "
143
+
"until browned."
144
+
),
145
+
"Add the cubed potatoes to the pan with the chicken.",
146
+
(
147
+
"Stir everything together and cook for 10 minutes or until "
148
+
"the potatoes are tender and the chicken is cooked "
149
+
"through."
150
+
),
151
+
"Serve hot.",
152
+
],
153
+
)
154
+
```
155
+
156
+
157
+
==="Expert chef"
158
+
159
+
Call the function:
160
+
```python
161
+
result = recipe(
162
+
["chicken", "potatoes"],
163
+
experience_level="born wearing a toque",
164
+
max_cook_time=60,
165
+
)
166
+
```
167
+
168
+
View the result:
169
+
170
+
```python
171
+
Recipe(
172
+
name="Chicken and Potato Tray Bake",
173
+
cook_time_minutes=45,
174
+
ingredients=[
175
+
"chicken",
176
+
"potatoes",
177
+
"olive oil",
178
+
"rosemary",
179
+
"garlic",
180
+
"salt",
181
+
"black pepper",
182
+
],
183
+
steps=[
184
+
(
185
+
"Preheat your oven to 200 degrees Celsius (400 degrees "
186
+
"Fahrenheit)."
187
+
),
188
+
(
189
+
"Wash and cut the potatoes into halves or quarters, "
190
+
"depending on size, and place in a large baking tray."
191
+
),
192
+
(
193
+
"Drizzle olive oil over the chicken and potatoes, then "
194
+
"season with salt, black pepper, and finely chopped "
195
+
"rosemary and garlic."
196
+
),
197
+
(
198
+
"Place the tray in the oven and bake for about 45 minutes, "
199
+
"or until the chicken is fully cooked and the potatoes are "
200
+
"golden and crispy."
201
+
),
202
+
(
203
+
"Remove from the oven and let it rest for a few minutes "
204
+
"before serving."
205
+
),
206
+
],
207
+
)
208
+
209
+
```
145
210
146
-
!!! success "Result"
147
-
148
-
Recipe Name: Herbed Chicken with Roasted Potatoes
149
-
150
-
Ingredients:
151
-
152
-
- Chicken
153
-
- Potatoes
154
-
- Olive oil
155
-
- Rosemary
156
-
- Salt
157
-
- Black pepper
158
-
- Garlic (optional)
159
-
160
-
Steps:
161
-
162
-
1. Preheat your oven to 200 degrees Celsius (392 degrees Fahrenheit).
163
-
2. Wash and cut the potatoes into chunks, then toss them with olive oil, salt, rosemary, and black pepper. Place them on a baking tray.
164
-
...
165
-
166
211
### Return annotation
167
212
168
213
Marvin will cast the output of your function to the type specified in the return annotation. If you do not provide a return annotation, Marvin will assume that the function returns a string.
0 commit comments