🔧 chore(Metaphor.py): refactor build method to accept additional parameters for improved configurability
🔧 chore(Metaphor.py): update search method to use the provided parameters for use_autoprompt and search_num_results 🔧 chore(Metaphor.py): update find_similar method to use the provided parameter for similar_num_results
This commit is contained in:
parent
89c3306512
commit
e1407d0595
1 changed files with 7 additions and 2 deletions
|
|
@ -23,6 +23,9 @@ class MetaphorToolkit(CustomComponent):
|
|||
def build(
|
||||
self,
|
||||
metaphor_api_key: str,
|
||||
use_autoprompt: bool = True,
|
||||
search_num_results: int = 5,
|
||||
similar_num_results: int = 5,
|
||||
) -> Union[Tool, BaseToolkit]:
|
||||
# If documents, then we need to create a Vectara instance using .from_documents
|
||||
client = Metaphor(api_key=metaphor_api_key)
|
||||
|
|
@ -30,7 +33,9 @@ class MetaphorToolkit(CustomComponent):
|
|||
@tool
|
||||
def search(query: str):
|
||||
"""Call search engine with a query."""
|
||||
return client.search(query, use_autoprompt=True, num_results=5)
|
||||
return client.search(
|
||||
query, use_autoprompt=use_autoprompt, num_results=search_num_results
|
||||
)
|
||||
|
||||
@tool
|
||||
def get_contents(ids: List[str]):
|
||||
|
|
@ -46,6 +51,6 @@ class MetaphorToolkit(CustomComponent):
|
|||
|
||||
The url passed in should be a URL returned from `search`
|
||||
"""
|
||||
return client.find_similar(url, num_results=5)
|
||||
return client.find_similar(url, num_results=similar_num_results)
|
||||
|
||||
return [search, get_contents, find_similar] # type: ignore
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue