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: README.md
+27
Original file line number
Diff line number
Diff line change
@@ -300,6 +300,33 @@ print(add(**result))
300
300
301
301
A great advantage of passing functions directly to specify the structure is that the structure of the LLM will change with the function's definition. No need to change the code at several places!
302
302
303
+
You can also embed various functions into an enum to generate params:
304
+
305
+
```python
306
+
from enum import Enum
307
+
from functools import partial
308
+
309
+
import outlines
310
+
311
+
312
+
defadd(a: int, b: int) -> int:
313
+
return a + b
314
+
315
+
defmul(c: float, d: float) -> float:
316
+
return c * d
317
+
318
+
classOperation(Enum):
319
+
add = partial(add)
320
+
mul = partial(mul)
321
+
322
+
model = outlines.models.transformers("WizardLM/WizardMath-7B-V1.1")
323
+
generator = outlines.generate.json(model, add)
324
+
result = generator("Return json with two float named c and d respectively. c is negative and d greater than 1.0.")
325
+
326
+
print(result)
327
+
# {'c': -3.14, 'd': 1.5}
328
+
```
329
+
303
330
## Prompting
304
331
305
332
Building prompts can get messy. **Outlines** makes it easier to write and manage
This recipe demonstrates how to use the `outlines` library to extract structured event details from a text message.
2
+
We will extract the title, location, and start date and time from messages like the following:
3
+
4
+
```plaintext
5
+
Hello Kitty, my grandmother will be here, I think it's better to postpone
6
+
our appointment to review math lessons to next Monday at 2pm at the same
7
+
place, 3 avenue des tanneurs, one hour will be enough see you 😘
8
+
```
9
+
10
+
Let see how to extract the event details from the message with the MLX
11
+
library dedicated to Apple Silicon processor (M series).
12
+
13
+
```python
14
+
--8<--"docs/cookbook/extract_event_details.py"
15
+
```
16
+
17
+
The output will be:
18
+
19
+
```plaintext
20
+
Today: Saturday 16 November 2024 and it's 10:55
21
+
```
22
+
23
+
and the extracted event information will be:
24
+
25
+
```json
26
+
{
27
+
"title":"Math Review",
28
+
"location":"3 avenue des tanneurs",
29
+
"start":"2024-11-22T14:00:00Z"
30
+
}
31
+
```
32
+
33
+
34
+
To find out more about this use case, we recommend the project developped by [Joseph Rudoler](https://x.com/JRudoler) the [ICS Generator](https://github.com/jrudoler/ics-generator)
f"Your enum class {myenum.__name__} has 0 members. If you are working with an enum of functions, do not forget to register them as callable (using `partial` for instance)"
0 commit comments