-
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
37d5582
commit 6246696
Showing
11 changed files
with
242 additions
and
96 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import os | ||
|
||
from griptape.drivers import TavilyWebSearchDriver | ||
|
||
driver = TavilyWebSearchDriver(api_key=os.environ["TAVILY_API_KEY"]) | ||
|
||
driver.search("griptape ai") |
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,9 @@ | ||
from griptape.drivers import DuckDuckGoWebSearchDriver | ||
from griptape.structures import Agent | ||
from griptape.tools import PromptSummaryTool, WebSearchTool | ||
|
||
agent = Agent( | ||
tools=[WebSearchTool(web_search_driver=DuckDuckGoWebSearchDriver()), PromptSummaryTool(off_prompt=False)], | ||
) | ||
|
||
agent.run("Give me some websites with information about AI frameworks.") |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from __future__ import annotations | ||
|
||
import json | ||
from typing import TYPE_CHECKING | ||
|
||
from attrs import Factory, define, field | ||
|
||
from griptape.artifacts import ListArtifact, TextArtifact | ||
from griptape.drivers import BaseWebSearchDriver | ||
from griptape.utils import import_optional_dependency | ||
|
||
if TYPE_CHECKING: | ||
from tavily import TavilyClient | ||
|
||
|
||
@define | ||
class TavilyWebSearchDriver(BaseWebSearchDriver): | ||
api_key: str = field(kw_only=True) | ||
client: TavilyClient = field( | ||
default=Factory(lambda self: import_optional_dependency("tavily").TavilyClient(self.api_key), takes_self=True), | ||
kw_only=True, | ||
) | ||
|
||
def search(self, query: str, **kwargs) -> ListArtifact: | ||
try: | ||
response = self.client.search(query, max_results=self.results_count, **kwargs) | ||
results = response["results"] | ||
return ListArtifact( | ||
[ | ||
TextArtifact( | ||
json.dumps({"title": result["title"], "url": result["url"], "content": result["content"]}) | ||
) | ||
for result in results | ||
] | ||
) | ||
except Exception as e: | ||
raise Exception(f"Error searching '{query}' with Tavily: {e}") from e |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.