-
Notifications
You must be signed in to change notification settings - Fork 175
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
af1e5eb
commit 896e534
Showing
46 changed files
with
1,237 additions
and
178 deletions.
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
38 changes: 38 additions & 0 deletions
38
docs/griptape-framework/drivers/src/prompt_drivers_structured_output.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,38 @@ | ||
import json | ||
|
||
import schema | ||
from rich.pretty import pprint | ||
|
||
from griptape.drivers import OpenAiChatPromptDriver | ||
from griptape.rules import JsonSchemaRule, Rule | ||
from griptape.structures import Pipeline | ||
from griptape.tasks import PromptTask | ||
|
||
pipeline = Pipeline( | ||
tasks=[ | ||
PromptTask( | ||
prompt_driver=OpenAiChatPromptDriver( | ||
model="gpt-4o", | ||
use_native_structured_output=True, | ||
native_structured_output_strategy="native", | ||
), | ||
rules=[ | ||
Rule("You are a helpful math tutor. Guide the user through the solution step by step."), | ||
JsonSchemaRule( | ||
schema.Schema( | ||
{ | ||
"steps": [schema.Schema({"explanation": str, "output": str})], | ||
"final_answer": str, | ||
} | ||
) | ||
), | ||
], | ||
) | ||
] | ||
) | ||
|
||
output = pipeline.run("How can I solve 8x + 7 = -23").output.value | ||
parsed_output = json.loads(output) | ||
|
||
|
||
pprint(parsed_output) |
28 changes: 28 additions & 0 deletions
28
docs/griptape-framework/drivers/src/prompt_drivers_structured_output_multi.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,28 @@ | ||
import schema | ||
from rich.pretty import pprint | ||
|
||
from griptape.drivers import OpenAiChatPromptDriver | ||
from griptape.rules import JsonSchemaRule | ||
from griptape.structures import Pipeline | ||
from griptape.tasks import PromptTask | ||
|
||
pipeline = Pipeline( | ||
tasks=[ | ||
PromptTask( | ||
prompt_driver=OpenAiChatPromptDriver( | ||
model="gpt-4o", | ||
use_native_structured_output=True, | ||
native_structured_output_strategy="tool", | ||
), | ||
rules=[ | ||
JsonSchemaRule(schema.Schema({"color": "red"})), | ||
JsonSchemaRule(schema.Schema({"color": "blue"})), | ||
], | ||
) | ||
] | ||
) | ||
|
||
output = pipeline.run("Pick a color").output.value | ||
|
||
|
||
pprint(output) |
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
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
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
Oops, something went wrong.