Skip to content

Commit 80c3970

Browse files
authored
docs(core): improve style for refs (#34227)
1 parent 4a42158 commit 80c3970

File tree

1 file changed

+56
-56
lines changed

1 file changed

+56
-56
lines changed

libs/core/langchain_core/language_models/chat_models.py

Lines changed: 56 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1578,86 +1578,86 @@ def with_structured_output(
15781578
depends on the `schema` as described above.
15791579
- `'parsing_error'`: `BaseException | None`
15801580
1581-
Example: Pydantic schema (`include_raw=False`):
1581+
???+ example "Pydantic schema (`include_raw=False`)"
15821582
1583-
```python
1584-
from pydantic import BaseModel
1583+
```python
1584+
from pydantic import BaseModel
15851585
15861586
1587-
class AnswerWithJustification(BaseModel):
1588-
'''An answer to the user question along with justification for the answer.'''
1587+
class AnswerWithJustification(BaseModel):
1588+
'''An answer to the user question along with justification for the answer.'''
15891589
1590-
answer: str
1591-
justification: str
1590+
answer: str
1591+
justification: str
15921592
15931593
1594-
model = ChatModel(model="model-name", temperature=0)
1595-
structured_model = model.with_structured_output(AnswerWithJustification)
1594+
model = ChatModel(model="model-name", temperature=0)
1595+
structured_model = model.with_structured_output(AnswerWithJustification)
15961596
1597-
structured_model.invoke(
1598-
"What weighs more a pound of bricks or a pound of feathers"
1599-
)
1597+
structured_model.invoke(
1598+
"What weighs more a pound of bricks or a pound of feathers"
1599+
)
16001600
1601-
# -> AnswerWithJustification(
1602-
# answer='They weigh the same',
1603-
# justification='Both a pound of bricks and a pound of feathers weigh one pound. The weight is the same, but the volume or density of the objects may differ.'
1604-
# )
1605-
```
1601+
# -> AnswerWithJustification(
1602+
# answer='They weigh the same',
1603+
# justification='Both a pound of bricks and a pound of feathers weigh one pound. The weight is the same, but the volume or density of the objects may differ.'
1604+
# )
1605+
```
16061606
1607-
Example: Pydantic schema (`include_raw=True`):
1607+
??? example "Pydantic schema (`include_raw=True`)"
16081608
1609-
```python
1610-
from pydantic import BaseModel
1609+
```python
1610+
from pydantic import BaseModel
16111611
16121612
1613-
class AnswerWithJustification(BaseModel):
1614-
'''An answer to the user question along with justification for the answer.'''
1613+
class AnswerWithJustification(BaseModel):
1614+
'''An answer to the user question along with justification for the answer.'''
16151615
1616-
answer: str
1617-
justification: str
1616+
answer: str
1617+
justification: str
16181618
16191619
1620-
model = ChatModel(model="model-name", temperature=0)
1621-
structured_model = model.with_structured_output(
1622-
AnswerWithJustification, include_raw=True
1623-
)
1620+
model = ChatModel(model="model-name", temperature=0)
1621+
structured_model = model.with_structured_output(
1622+
AnswerWithJustification, include_raw=True
1623+
)
16241624
1625-
structured_model.invoke(
1626-
"What weighs more a pound of bricks or a pound of feathers"
1627-
)
1628-
# -> {
1629-
# 'raw': AIMessage(content='', additional_kwargs={'tool_calls': [{'id': 'call_Ao02pnFYXD6GN1yzc0uXPsvF', 'function': {'arguments': '{"answer":"They weigh the same.","justification":"Both a pound of bricks and a pound of feathers weigh one pound. The weight is the same, but the volume or density of the objects may differ."}', 'name': 'AnswerWithJustification'}, 'type': 'function'}]}),
1630-
# 'parsed': AnswerWithJustification(answer='They weigh the same.', justification='Both a pound of bricks and a pound of feathers weigh one pound. The weight is the same, but the volume or density of the objects may differ.'),
1631-
# 'parsing_error': None
1632-
# }
1633-
```
1625+
structured_model.invoke(
1626+
"What weighs more a pound of bricks or a pound of feathers"
1627+
)
1628+
# -> {
1629+
# 'raw': AIMessage(content='', additional_kwargs={'tool_calls': [{'id': 'call_Ao02pnFYXD6GN1yzc0uXPsvF', 'function': {'arguments': '{"answer":"They weigh the same.","justification":"Both a pound of bricks and a pound of feathers weigh one pound. The weight is the same, but the volume or density of the objects may differ."}', 'name': 'AnswerWithJustification'}, 'type': 'function'}]}),
1630+
# 'parsed': AnswerWithJustification(answer='They weigh the same.', justification='Both a pound of bricks and a pound of feathers weigh one pound. The weight is the same, but the volume or density of the objects may differ.'),
1631+
# 'parsing_error': None
1632+
# }
1633+
```
16341634
1635-
Example: Dictionary schema (`include_raw=False`):
1635+
??? example "Dictionary schema (`include_raw=False`)"
16361636
1637-
```python
1638-
from pydantic import BaseModel
1639-
from langchain_core.utils.function_calling import convert_to_openai_tool
1637+
```python
1638+
from pydantic import BaseModel
1639+
from langchain_core.utils.function_calling import convert_to_openai_tool
16401640
16411641
1642-
class AnswerWithJustification(BaseModel):
1643-
'''An answer to the user question along with justification for the answer.'''
1642+
class AnswerWithJustification(BaseModel):
1643+
'''An answer to the user question along with justification for the answer.'''
16441644
1645-
answer: str
1646-
justification: str
1645+
answer: str
1646+
justification: str
16471647
16481648
1649-
dict_schema = convert_to_openai_tool(AnswerWithJustification)
1650-
model = ChatModel(model="model-name", temperature=0)
1651-
structured_model = model.with_structured_output(dict_schema)
1649+
dict_schema = convert_to_openai_tool(AnswerWithJustification)
1650+
model = ChatModel(model="model-name", temperature=0)
1651+
structured_model = model.with_structured_output(dict_schema)
16521652
1653-
structured_model.invoke(
1654-
"What weighs more a pound of bricks or a pound of feathers"
1655-
)
1656-
# -> {
1657-
# 'answer': 'They weigh the same',
1658-
# 'justification': 'Both a pound of bricks and a pound of feathers weigh one pound. The weight is the same, but the volume and density of the two substances differ.'
1659-
# }
1660-
```
1653+
structured_model.invoke(
1654+
"What weighs more a pound of bricks or a pound of feathers"
1655+
)
1656+
# -> {
1657+
# 'answer': 'They weigh the same',
1658+
# 'justification': 'Both a pound of bricks and a pound of feathers weigh one pound. The weight is the same, but the volume and density of the two substances differ.'
1659+
# }
1660+
```
16611661
16621662
!!! warning "Behavior changed in `langchain-core` 0.2.26"
16631663

0 commit comments

Comments
 (0)