-
Notifications
You must be signed in to change notification settings - Fork 185
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Ability to use Drivers Configs as Context Managers for temporaril…
…y setting the default Drivers.
- Loading branch information
1 parent
5b56867
commit a03617b
Showing
6 changed files
with
83 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
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,12 @@ | ||
from griptape.configs import Defaults | ||
from griptape.configs.drivers import AnthropicDriversConfig, OpenAiDriversConfig | ||
from griptape.drivers.prompt.anthropic_prompt_driver import AnthropicPromptDriver | ||
from griptape.structures import Agent | ||
|
||
Defaults.drivers_config = OpenAiDriversConfig() # Default | ||
openai_agent = Agent() | ||
|
||
Defaults.drivers_config = AnthropicDriversConfig() | ||
anthropic_agent = Agent( | ||
prompt_driver=AnthropicPromptDriver(model="claude-3-5-sonnet-20240620"), # Override the default prompt driver | ||
) |
29 changes: 29 additions & 0 deletions
29
docs/griptape-framework/structures/src/drivers_config_with.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,29 @@ | ||
import schema | ||
|
||
from griptape.configs.drivers import AnthropicDriversConfig, OpenAiDriversConfig | ||
from griptape.drivers import AnthropicPromptDriver, OpenAiChatPromptDriver | ||
from griptape.engines import JsonExtractionEngine | ||
from griptape.structures import Agent | ||
from griptape.tasks import ToolTask | ||
from griptape.tools import ExtractionTool | ||
|
||
with OpenAiDriversConfig(): | ||
openai_agent = Agent() | ||
|
||
with AnthropicDriversConfig(): | ||
anthropic_agent = Agent( | ||
tasks=[ | ||
ToolTask( | ||
"Extract sentiment from this text: {{ args[0] }}", | ||
prompt_driver=OpenAiChatPromptDriver(model="gpt-4o"), | ||
tool=ExtractionTool( | ||
extraction_engine=JsonExtractionEngine( | ||
prompt_driver=AnthropicPromptDriver(model="claude-3-opus-20240229"), | ||
template_schema=schema.Schema({"sentiment": str}).json_schema("Output"), | ||
), | ||
), | ||
) | ||
] | ||
) | ||
|
||
anthropic_agent.run("Hello, I am happy!") |
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