Bases: BaseWebSearchDriver
Source code in griptape/drivers/web_search/exa_web_search_driver.py
| @define
class ExaWebSearchDriver(BaseWebSearchDriver):
api_key: str = field(kw_only=True, default=None)
highlights: bool = field(default=False, kw_only=True)
use_autoprompt: bool = field(default=False, kw_only=True)
params: dict[str, Any] = field(factory=dict, kw_only=True, metadata={"serializable": True})
_client: Exa = field(default=None, kw_only=True, alias="client")
@lazy_property()
def client(self) -> Exa:
return import_optional_dependency("exa_py").Exa(api_key=self.api_key)
def search(self, query: str, **kwargs) -> ListArtifact[JsonArtifact]:
response = self.client.search_and_contents(
highlights=self.highlights,
use_autoprompt=self.use_autoprompt,
query=query,
num_results=self.results_count,
text=True,
**self.params,
**kwargs,
)
results = [
{"title": result.title, "url": result.url, "highlights": result.highlights, "text": result.text}
for result in response.results
]
return ListArtifact([JsonArtifact(result) for result in results])
|
api_key: str = field(kw_only=True, default=None)
class-attribute
instance-attribute
highlights: bool = field(default=False, kw_only=True)
class-attribute
instance-attribute
params: dict[str, Any] = field(factory=dict, kw_only=True, metadata={'serializable': True})
class-attribute
instance-attribute
use_autoprompt: bool = field(default=False, kw_only=True)
class-attribute
instance-attribute
client()
Source code in griptape/drivers/web_search/exa_web_search_driver.py
| @lazy_property()
def client(self) -> Exa:
return import_optional_dependency("exa_py").Exa(api_key=self.api_key)
|
search(query, **kwargs)
Source code in griptape/drivers/web_search/exa_web_search_driver.py
| def search(self, query: str, **kwargs) -> ListArtifact[JsonArtifact]:
response = self.client.search_and_contents(
highlights=self.highlights,
use_autoprompt=self.use_autoprompt,
query=query,
num_results=self.results_count,
text=True,
**self.params,
**kwargs,
)
results = [
{"title": result.title, "url": result.url, "highlights": result.highlights, "text": result.text}
for result in response.results
]
return ListArtifact([JsonArtifact(result) for result in results])
|