Skip to content
This repository has been archived by the owner on Mar 1, 2024. It is now read-only.

Commit

Permalink
cr
Browse files Browse the repository at this point in the history
  • Loading branch information
jerryjliu committed Aug 21, 2023
1 parent f7d53c2 commit 1cc0f80
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 42 deletions.
7 changes: 6 additions & 1 deletion llama_hub/tools/metaphor/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ class MetaphorToolSpec(BaseToolSpec):
"current_date"
]

def __init__(self, api_key: str) -> None:
def __init__(self, api_key: str, verbose: bool = True) -> None:
"""Initialize with parameters."""
from metaphor_python import Metaphor

self.client = Metaphor(api_key=api_key)
self._verbose = verbose

def search(
self,
Expand Down Expand Up @@ -54,6 +55,8 @@ def search(
end_published_date=end_published_date,
use_autoprompt=True
)
if self._verbose:
print(f"[Metaphor Tool] Autoprompt: {response.autoprompt_string}")
return [
{"title": result.title, "url": result.url, "id": result.id}
for result in response.results
Expand Down Expand Up @@ -126,6 +129,8 @@ def search_and_retrieve_documents(
end_published_date=end_published_date,
use_autoprompt=True
)
if self._verbose:
print(f"[Metaphor Tool] Autoprompt: {response.autoprompt_string}")
ids = [result.id for result in response.results]
documents = self.client.get_contents(ids)
return [Document(text=document.extract) for document in documents.contents]
Expand Down
Loading

0 comments on commit 1cc0f80

Please sign in to comment.