-
Notifications
You must be signed in to change notification settings - Fork 176
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
2ae50b3
commit 99e3b99
Showing
6 changed files
with
89 additions
and
2 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
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 | ||
) |
31 changes: 31 additions & 0 deletions
31
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,31 @@ | ||
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(): # Agent will be created with OpenAi Drivers | ||
openai_agent = Agent() | ||
|
||
with AnthropicDriversConfig(): # Agent will be created with Anthropic Drivers | ||
anthropic_agent = Agent( | ||
tasks=[ | ||
ToolTask( | ||
"Extract sentiment from this text: {{ args[0] }}", | ||
prompt_driver=OpenAiChatPromptDriver(model="gpt-4o"), # Override this particular Task's prompt driver | ||
tool=ExtractionTool( | ||
extraction_engine=JsonExtractionEngine( | ||
prompt_driver=AnthropicPromptDriver( # Override this particular Engine's prompt driver | ||
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