Skip to content

Commit 2e232f6

Browse files
authored
Update README.md
1 parent 48bf82f commit 2e232f6

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

README.md

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,27 @@ class Output(BaseLLMResponse):
9595

9696
```
9797

98+
### Example 4
99+
100+
You can nest response types. Note that you need to use `BaseLLMArrayElement` for classes that you want to nest inside a list. To add instructions inside an element of `BaseLLMArrayElement`, you must use `LLMArrayElementOutput` instead of `LLMOutput`.
101+
102+
```python
103+
class Output(BaseLLMResponse):
104+
105+
class Item(BaseLLMArrayElement):
106+
107+
class Description(BaseLLMResponse):
108+
short: str | None
109+
long: str
110+
111+
title: str
112+
description: Description
113+
price: float = LLMArrayElementOutput(instruction=lambda pos: f"The price of the {pos.ordinal} item")
114+
115+
items: list[Item]
116+
count: int
117+
```
118+
98119

99120

100121

@@ -222,9 +243,3 @@ MOUSE 2: <Put the second mouse here>
222243
```
223244
Notice how the plural "mice" is automatically converted to the singular "mouse" to avoid confusing the language model.
224245

225-
226-
227-
228-
## Coming Soon
229-
230-
- Support for output classes within output classes, especially arrays

0 commit comments

Comments
 (0)