-
Notifications
You must be signed in to change notification settings - Fork 184
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
674a61a
commit 297d864
Showing
3 changed files
with
45 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
21 changes: 21 additions & 0 deletions
21
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,21 @@ | ||
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) | ||
|
||
print(sentiment_analysis.answer) | ||
print(sentiment_analysis.relevant_emojis) |