-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
18 changed files
with
472 additions
and
287 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
Large diffs are not rendered by default.
Oops, something went wrong.
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
File renamed without changes.
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,56 @@ | ||
from typing import List, Union | ||
from langflow import CustomComponent | ||
|
||
from metaphor_python import Metaphor # type: ignore | ||
from langchain.tools import Tool | ||
from langchain.agents import tool | ||
from langchain.agents.agent_toolkits.base import BaseToolkit | ||
|
||
|
||
class MetaphorToolkit(CustomComponent): | ||
display_name: str = "Metaphor" | ||
description: str = "Metaphor Toolkit" | ||
documentation = ( | ||
"https://python.langchain.com/docs/integrations/tools/metaphor_search" | ||
) | ||
beta = True | ||
# api key should be password = True | ||
field_config = { | ||
"metaphor_api_key": {"display_name": "Metaphor API Key", "password": True}, | ||
"code": {"advanced": True}, | ||
} | ||
|
||
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) | ||
|
||
@tool | ||
def search(query: str): | ||
"""Call search engine with a query.""" | ||
return client.search( | ||
query, use_autoprompt=use_autoprompt, num_results=search_num_results | ||
) | ||
|
||
@tool | ||
def get_contents(ids: List[str]): | ||
"""Get contents of a webpage. | ||
The ids passed in should be a list of ids as fetched from `search`. | ||
""" | ||
return client.get_contents(ids) | ||
|
||
@tool | ||
def find_similar(url: str): | ||
"""Get search results similar to a given URL. | ||
The url passed in should be a URL returned from `search` | ||
""" | ||
return client.find_similar(url, num_results=similar_num_results) | ||
|
||
return [search, get_contents, find_similar] # type: ignore |
Empty file.
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,50 @@ | ||
from typing import Optional, Union | ||
from langflow import CustomComponent | ||
|
||
from langchain.vectorstores import Vectara | ||
from langchain.schema import Document | ||
from langchain.vectorstores.base import VectorStore | ||
from langchain.schema import BaseRetriever | ||
from langchain.embeddings.base import Embeddings | ||
|
||
|
||
class VectaraComponent(CustomComponent): | ||
display_name: str = "Vectara" | ||
description: str = "Implementation of Vector Store using Vectara" | ||
documentation = ( | ||
"https://python.langchain.com/docs/integrations/vectorstores/vectara" | ||
) | ||
beta = True | ||
# api key should be password = True | ||
field_config = { | ||
"vectara_customer_id": {"display_name": "Vectara Customer ID"}, | ||
"vectara_corpus_id": {"display_name": "Vectara Corpus ID"}, | ||
"vectara_api_key": {"display_name": "Vectara API Key", "password": True}, | ||
"code": {"show": False}, | ||
"documents": {"display_name": "Documents"}, | ||
"embedding": {"display_name": "Embedding"}, | ||
} | ||
|
||
def build( | ||
self, | ||
vectara_customer_id: str, | ||
vectara_corpus_id: str, | ||
vectara_api_key: str, | ||
embedding: Optional[Embeddings] = None, | ||
documents: Optional[Document] = None, | ||
) -> Union[VectorStore, BaseRetriever]: | ||
# If documents, then we need to create a Vectara instance using .from_documents | ||
if documents is not None and embedding is not None: | ||
return Vectara.from_documents( | ||
documents=documents, # type: ignore | ||
vectara_customer_id=vectara_customer_id, | ||
vectara_corpus_id=vectara_corpus_id, | ||
vectara_api_key=vectara_api_key, | ||
embedding=embedding, | ||
) | ||
|
||
return Vectara( | ||
vectara_customer_id=vectara_customer_id, | ||
vectara_corpus_id=vectara_corpus_id, | ||
vectara_api_key=vectara_api_key, | ||
) |
Empty file.
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
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
Oops, something went wrong.