-
Notifications
You must be signed in to change notification settings - Fork 186
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a5d4ed6
commit 2805494
Showing
3 changed files
with
46 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
docs/griptape-framework/structures/src/json_schema_rule_pydantic.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from __future__ import annotations | ||
|
||
import pydantic | ||
|
||
from griptape.rules.json_schema_rule import JsonSchemaRule | ||
from griptape.structures import Agent | ||
|
||
|
||
class SentimentModel(pydantic.BaseModel): | ||
answer: str | ||
relevant_emojis: list[str] | ||
|
||
|
||
agent = Agent(rules=[JsonSchemaRule(SentimentModel.model_json_schema())]) | ||
|
||
output = agent.run("What is the sentiment of this message?: 'I am so happy!'").output | ||
|
||
sentiment_analysis = SentimentModel.model_validate_json(output.value) | ||
|
||
# Autocomplete via dot notation 🤩 | ||
print(sentiment_analysis.answer) | ||
print(sentiment_analysis.relevant_emojis) |