diff --git a/README.md b/README.md index 04c54b5..d81a060 100644 --- a/README.md +++ b/README.md @@ -215,6 +215,72 @@ Now, clicking on the blue chat icon, you can go ahead and test out your first Fl ![Compile](images/rag/chat.png) +## Deploy Your Flow to Kalavai + +When you have built the flow you want, and tested out the Chat function inside the Agent Builder, your next stop is to be able to execute that flow from code, so you can start to put it to good use! + +We can do this, by deploying the Flow out to the Kalavai Network, by following these steps! + +1. Download a copy of your Flow + +1. Get a copy of the Flow API Key from the user interface. + +You can see the key icon on the top right of the Agent Builder, click this to see your key management screen. +![Deploy](images/deploy/d_1.png) + +From here, you can create a new key. These are the keys that people can use to access your flows. This means you do not need to share any other keys with external users. + +![Deploy](images/deploy/d_2.png) + +Give your new key a name, and click create secret key. + +![Deploy](images/deploy/d_3.png) + +This will give you the key you need, copy this to your clip board, and save it somewhere, you will need this in your code, to call your API. If you lose it, you cannot get it back, but you can at least generate new ones as you need. + +![Deploy](images/deploy/d_4.png) +Finally this will take you back to the API keys screen. + +![Deploy](images/deploy/d_5.png) + +From you will want to go back to your flow, by clicking the name in the +top left corner. + +![Deploy](images/deploy/d_6.png) + +From here we will export your Flow, using the download button in the top left corner. Also, take a note of the _code_ icon here. This is where you can find code example to see how to access your flows once you deploy them! + +![Deploy](images/deploy/d_7.png) + +Moving on, name your flow and download it. From this point on we need to go back to using the main Kalavai interface, and we will click on __Deploy__ on the right hand side kalavai menu. + + + +This shows us all our current deployments, you can see your Agent Builder here. We are going to want to create a new deployment, by clicking the Deploy button up at the top right. + +![Deploy](images/deploy/d_9.png) + +From here we will want to Name our new deployment, attach the json flow we previously downloaded, and copy in the API key that we copied from the Agent Builder in an earlier step. + +![Deploy](images/deploy/d_12.png) + +From this, your flow will successfully deploy, and you can see it here in your deployments list. + +You can click the _endpoint_ link on the right to examine the documentation for your deployment! This will take you to the public url of your newly deployed AI Flow. + +You will see a message saying `detail "Not Found"`. This is expected, as the endpoint is the machine-accessable url. To inspect to docs add "/docs" to the url to see what has actually been deployed! + +For example, if your endpoint links to `https://adam.test.test.k8s.mvp.kalavai.net/` update it to `https://adam.test.test.k8s.mvp.kalavai.net/docs/` to see this FastAPI endpoint. + +![Deploy](images/deploy/d_14.png) + +You will not be able to execute here, as the endpoint is API protected, but you can move into the land of code, and see how to call this endpoint in the [Provided Notebook](notebooks/Call_Agent_Flow.ipynb) + +You can inspect the Agent builder Code Tab to see various examples of code usage: + +![Deploy](images/deploy/d_15.png) + + ## Exercised and Next Steps Now that you have the basic structure in place, you can start to think about more complex knowledge-driven applications. A good place to start would be: diff --git a/example_collections/example_collection.json b/example_collections/example_collection.json new file mode 100644 index 0000000..8265412 --- /dev/null +++ b/example_collections/example_collection.json @@ -0,0 +1 @@ +{"flows":[{"name":"Basic RAG Example","description":"Build Retrieval Augmented Question Answering on the Kalavai Network","data":{"nodes":[{"id":"KalavaiLlm-UTSYC","type":"genericNode","position":{"x":725.3194922736798,"y":-35.23333740234375},"data":{"type":"KalavaiLlm","node":{"template":{"code":{"type":"code","required":true,"placeholder":"","list":false,"show":true,"multiline":true,"value":"import os\nimport json\nfrom typing import Optional, Union\n\nfrom langchain.llms import BaseLLM\nfrom langchain_community.chat_models.openai import ChatOpenAI\n\nfrom langflow import CustomComponent\nfrom langflow.field_typing import BaseLanguageModel, NestedDict\n\n\nclass KalavaiLLMComponent(CustomComponent):\n display_name = \"KalavaiLLM\"\n description = \"API for LLM models deployed in Kalavai.\"\n \n def _load_endpoints(self):\n MODEL_ENDPOINTS_FILE = os.getenv(\"MODEL_ENDPOINTS\", \"data/model_endpoints.json\")\n \n with open(MODEL_ENDPOINTS_FILE, \"r\") as f:\n return json.load(f)\n \n\n def build_config(self):\n model_endpoints = self._load_endpoints()\n api_key = os.getenv(\"MODEL_ENDPOINT_API_KEY\", \"N3E9AGVU7IR9E6QLXMIP6YO330M2D005DH5MN4C6\")\n return {\n \"max_tokens\": {\n \"display_name\": \"Max Tokens\",\n \"field_type\": \"int\",\n \"advanced\": False,\n \"required\": False,\n },\n \"model_kwargs\": {\n \"display_name\": \"Model Kwargs\",\n \"field_type\": \"NestedDict\",\n \"advanced\": True,\n \"required\": False,\n },\n \"model_name\": {\n \"display_name\": \"Model Name\",\n \"field_type\": \"str\",\n \"advanced\": False,\n \"required\": False,\n \"options\": list(model_endpoints.keys()),\n },\n \"kalavai_api_key\": {\n \"display_name\": \"Kalavai API Key\",\n \"field_type\": \"str\",\n \"advanced\": True,\n \"required\": False,\n \"password\": True,\n \"value\": api_key\n },\n \"temperature\": {\n \"display_name\": \"Temperature\",\n \"field_type\": \"float\",\n \"advanced\": False,\n \"required\": False,\n \"value\": 0.7,\n },\n }\n\n def build(\n self,\n max_tokens: Optional[int] = 256,\n model_kwargs: NestedDict = {},\n model_name: str = \"Equall/Saul-Instruct-v1\",\n kalavai_api_key: Optional[str] = None,\n temperature: float = 0.7,\n ) -> Union[BaseLanguageModel, BaseLLM]:\n model_endpoints = self._load_endpoints()\n return ChatOpenAI(\n max_tokens=max_tokens,\n model_kwargs=model_kwargs,\n model=model_name,\n base_url=model_endpoints[model_name],\n api_key=kalavai_api_key,\n temperature=temperature,\n )","fileTypes":[],"file_path":"","password":false,"name":"code","advanced":false,"dynamic":true,"info":"","title_case":true},"kalavai_api_key":{"type":"str","required":false,"placeholder":"","list":false,"show":true,"multiline":false,"value":"N3E9AGVU7IR9E6QLXMIP6YO330M2D005DH5MN4C6","fileTypes":[],"file_path":"","password":true,"name":"kalavai_api_key","display_name":"Kalavai API Key","advanced":true,"dynamic":false,"info":"","title_case":true},"max_tokens":{"type":"int","required":false,"placeholder":"","list":false,"show":true,"multiline":false,"value":256,"fileTypes":[],"file_path":"","password":false,"name":"max_tokens","display_name":"Max Tokens","advanced":false,"dynamic":false,"info":"","title_case":true},"model_kwargs":{"type":"NestedDict","required":false,"placeholder":"","list":false,"show":true,"multiline":false,"value":{},"fileTypes":[],"file_path":"","password":false,"name":"model_kwargs","display_name":"Model Kwargs","advanced":true,"dynamic":false,"info":"","title_case":true},"model_name":{"type":"str","required":false,"placeholder":"","list":true,"show":true,"multiline":false,"value":"meta-llama/Meta-Llama-3-8B-Instruct","fileTypes":[],"file_path":"","password":false,"options":["meta-llama/Meta-Llama-3-8B-Instruct","Equall/Saul-Instruct-v1"],"name":"model_name","display_name":"Model Name","advanced":false,"dynamic":false,"info":"","title_case":true},"temperature":{"type":"float","required":false,"placeholder":"","list":false,"show":true,"multiline":false,"value":0.7,"fileTypes":[],"file_path":"","password":false,"name":"temperature","display_name":"Temperature","advanced":false,"dynamic":false,"info":"","rangeSpec":{"min":-1,"max":1,"step":0.1},"title_case":true},"_type":"CustomComponent"},"description":"API for LLM models deployed in Kalavai.","base_classes":["BaseLanguageModel","BaseLLM","BaseLanguageModel"],"display_name":"KalavaiLLM","documentation":"","custom_fields":{"max_tokens":null,"model_kwargs":null,"model_name":null,"kalavai_api_key":null,"temperature":null},"output_types":["BaseLanguageModel","BaseLLM"],"field_formatters":{},"beta":true},"id":"KalavaiLlm-UTSYC"},"selected":false,"width":384,"height":543},{"id":"RetrievalQA-JFfxD","type":"genericNode","position":{"x":1673.8725742931108,"y":523.5984503198706},"data":{"type":"RetrievalQA","node":{"template":{"combine_documents_chain":{"type":"BaseCombineDocumentsChain","required":true,"placeholder":"","list":false,"show":true,"multiline":false,"fileTypes":[],"file_path":"","password":false,"name":"combine_documents_chain","display_name":"Combine Documents Chain","advanced":false,"dynamic":false,"info":"","title_case":true},"memory":{"type":"BaseMemory","required":false,"placeholder":"","list":false,"show":true,"multiline":false,"fileTypes":[],"file_path":"","password":false,"name":"memory","display_name":"Memory","advanced":false,"dynamic":false,"info":"","title_case":true},"retriever":{"type":"BaseRetriever","required":true,"placeholder":"","list":false,"show":true,"multiline":false,"fileTypes":[],"file_path":"","password":false,"name":"retriever","display_name":"Retriever","advanced":false,"dynamic":false,"info":"","title_case":true},"code":{"type":"code","required":true,"placeholder":"","list":false,"show":true,"multiline":true,"value":"from typing import Callable, Optional, Union\n\nfrom langchain.chains.combine_documents.base import BaseCombineDocumentsChain\nfrom langchain.chains.retrieval_qa.base import BaseRetrievalQA, RetrievalQA\nfrom langflow import CustomComponent\nfrom langflow.field_typing import BaseMemory, BaseRetriever\n\n\nclass RetrievalQAComponent(CustomComponent):\n display_name = \"RetrievalQA\"\n description = \"Chain for question-answering against an index.\"\n\n def build_config(self):\n return {\n \"combine_documents_chain\": {\"display_name\": \"Combine Documents Chain\"},\n \"retriever\": {\"display_name\": \"Retriever\"},\n \"memory\": {\"display_name\": \"Memory\", \"required\": False},\n \"input_key\": {\"display_name\": \"Input Key\", \"advanced\": True},\n \"output_key\": {\"display_name\": \"Output Key\", \"advanced\": True},\n \"return_source_documents\": {\"display_name\": \"Return Source Documents\"},\n }\n\n def build(\n self,\n combine_documents_chain: BaseCombineDocumentsChain,\n retriever: BaseRetriever,\n memory: Optional[BaseMemory] = None,\n input_key: str = \"query\",\n output_key: str = \"result\",\n return_source_documents: bool = True,\n ) -> Union[BaseRetrievalQA, Callable]:\n return RetrievalQA(\n combine_documents_chain=combine_documents_chain,\n retriever=retriever,\n memory=memory,\n input_key=input_key,\n output_key=output_key,\n return_source_documents=return_source_documents,\n )\n","fileTypes":[],"file_path":"","password":false,"name":"code","advanced":false,"dynamic":true,"info":"","title_case":true},"input_key":{"type":"str","required":true,"placeholder":"","list":false,"show":true,"multiline":false,"value":"query","fileTypes":[],"file_path":"","password":false,"name":"input_key","display_name":"Input Key","advanced":true,"dynamic":false,"info":"","title_case":true},"output_key":{"type":"str","required":true,"placeholder":"","list":false,"show":true,"multiline":false,"value":"result","fileTypes":[],"file_path":"","password":false,"name":"output_key","display_name":"Output Key","advanced":true,"dynamic":false,"info":"","title_case":true},"return_source_documents":{"type":"bool","required":true,"placeholder":"","list":false,"show":true,"multiline":false,"value":true,"fileTypes":[],"file_path":"","password":false,"name":"return_source_documents","display_name":"Return Source Documents","advanced":false,"dynamic":false,"info":"","title_case":true},"_type":"CustomComponent"},"description":"Chain for question-answering against an index.","base_classes":["BaseRetrievalQA","Chain","Callable"],"display_name":"RetrievalQA","documentation":"","custom_fields":{"combine_documents_chain":null,"retriever":null,"memory":null,"input_key":null,"output_key":null,"return_source_documents":null},"output_types":["BaseRetrievalQA","Callable"],"field_formatters":{},"beta":true},"id":"RetrievalQA-JFfxD"},"selected":false,"width":384,"height":502},{"id":"CombineDocsChain-RoWar","type":"genericNode","position":{"x":1209.875644476401,"y":297.9196358451761},"data":{"type":"CombineDocsChain","node":{"template":{"llm":{"type":"BaseLanguageModel","required":true,"placeholder":"","list":false,"show":true,"multiline":false,"value":"","fileTypes":[],"file_path":"","password":false,"name":"llm","display_name":"LLM","advanced":false,"dynamic":false,"info":"","title_case":true},"chain_type":{"type":"str","required":true,"placeholder":"","list":true,"show":true,"multiline":false,"value":"stuff","fileTypes":[],"file_path":"","password":false,"options":["stuff","map_reduce","map_rerank","refine"],"name":"chain_type","advanced":false,"dynamic":false,"info":"","title_case":true},"_type":"load_qa_chain"},"description":"Load question answering chain.","base_classes":["BaseCombineDocumentsChain","Callable"],"display_name":"CombineDocsChain","documentation":"","custom_fields":{},"output_types":[],"field_formatters":{},"beta":false},"id":"CombineDocsChain-RoWar"},"selected":false,"width":384,"height":333},{"id":"VectorStoreRetriever-HhAfJ","type":"genericNode","position":{"x":1212.0761528831624,"y":782.3173486940761},"data":{"type":"VectorStoreRetriever","node":{"template":{"vectorstore":{"type":"VectorStore","required":true,"placeholder":"","list":false,"show":true,"multiline":false,"fileTypes":[],"file_path":"","password":false,"name":"vectorstore","display_name":"Vector Store","advanced":false,"dynamic":false,"info":"","title_case":true},"code":{"type":"code","required":true,"placeholder":"","list":false,"show":true,"multiline":true,"value":"from langchain_core.vectorstores import VectorStoreRetriever\n\nfrom langflow import CustomComponent\nfrom langflow.field_typing import VectorStore\n\n\nclass VectoStoreRetrieverComponent(CustomComponent):\n display_name = \"VectorStore Retriever\"\n description = \"A vector store retriever\"\n\n def build_config(self):\n return {\n \"vectorstore\": {\"display_name\": \"Vector Store\", \"type\": VectorStore},\n }\n\n def build(self, vectorstore: VectorStore) -> VectorStoreRetriever:\n return vectorstore.as_retriever()\n","fileTypes":[],"file_path":"","password":false,"name":"code","advanced":false,"dynamic":true,"info":"","title_case":true},"_type":"CustomComponent"},"description":"A vector store retriever","base_classes":["VectorStoreRetriever","BaseRetriever"],"display_name":"VectorStore Retriever","documentation":"","custom_fields":{"vectorstore":null},"output_types":["VectorStoreRetriever"],"field_formatters":{},"beta":true},"id":"VectorStoreRetriever-HhAfJ"},"selected":false,"width":384,"height":329},{"id":"KalavaiDB-yi2jj","type":"genericNode","position":{"x":726.2514329243163,"y":583.3451840691723},"data":{"type":"KalavaiDB","node":{"template":{"documents":{"type":"Document","required":false,"placeholder":"","list":true,"show":true,"multiline":false,"fileTypes":[],"file_path":"","password":false,"name":"documents","display_name":"Documents","advanced":false,"dynamic":false,"info":"","title_case":true},"embedding":{"type":"Embeddings","required":true,"placeholder":"","list":false,"show":true,"multiline":false,"fileTypes":[],"file_path":"","password":false,"name":"embedding","display_name":"Embedding","advanced":false,"dynamic":false,"info":"","title_case":true},"chroma_server_cors_allow_origins":{"type":"str","required":false,"placeholder":"","list":false,"show":true,"multiline":false,"fileTypes":[],"file_path":"","password":false,"name":"chroma_server_cors_allow_origins","display_name":"Server CORS Allow Origins","advanced":true,"dynamic":false,"info":"","title_case":true},"chroma_server_grpc_port":{"type":"int","required":false,"placeholder":"","list":false,"show":true,"multiline":false,"fileTypes":[],"file_path":"","password":false,"name":"chroma_server_grpc_port","display_name":"Server gRPC Port","advanced":true,"dynamic":false,"info":"","title_case":true},"chroma_server_host":{"type":"str","required":false,"placeholder":"","list":false,"show":true,"multiline":false,"fileTypes":[],"file_path":"","password":false,"name":"chroma_server_host","display_name":"Server Host","advanced":true,"dynamic":false,"info":"","title_case":true},"chroma_server_port":{"type":"int","required":false,"placeholder":"","list":false,"show":true,"multiline":false,"fileTypes":[],"file_path":"","password":false,"name":"chroma_server_port","display_name":"Server Port","advanced":true,"dynamic":false,"info":"","title_case":true},"chroma_server_ssl_enabled":{"type":"bool","required":true,"placeholder":"","list":false,"show":true,"multiline":false,"value":false,"fileTypes":[],"file_path":"","password":false,"name":"chroma_server_ssl_enabled","display_name":"Server SSL Enabled","advanced":true,"dynamic":false,"info":"","title_case":true},"code":{"type":"code","required":true,"placeholder":"","list":false,"show":true,"multiline":true,"value":"\"\"\"\nReference: https://github.com/langflow-ai/langflow/tree/dev/src/backend/base/langflow/components/vectorstores\n\"\"\"\nfrom typing import List, Optional, Union\n\nimport chromadb # type: ignore\nfrom langchain.embeddings.base import Embeddings\nfrom langchain.schema import BaseRetriever, Document\nfrom langchain_community.vectorstores import VectorStore\nfrom langchain_community.vectorstores.chroma import Chroma\nfrom langflow import CustomComponent\n\n\nclass KalavaiVectorDBComponent(CustomComponent):\n \"\"\"\n A custom component for implementing a Vector Store using Chroma.\n \"\"\"\n\n display_name: str = \"Kalavai VectorDB\"\n description: str = \"Implementation of local Vector Store in Kalavai\"\n documentation = \"https://python.langchain.com/docs/integrations/vectorstores/chroma\"\n beta: bool = True\n\n def build_config(self):\n \"\"\"\n Builds the configuration for the component.\n\n Returns:\n - dict: A dictionary containing the configuration options for the component.\n \"\"\"\n return {\n \"collection_name\": {\"display_name\": \"Collection Name\", \"value\": \"langflow\"},\n \"persist\": {\"display_name\": \"Persist\"},\n \"persist_directory\": {\"display_name\": \"Persist Directory\"},\n \"code\": {\"advanced\": True, \"display_name\": \"Code\"},\n \"documents\": {\"display_name\": \"Documents\", \"is_list\": True},\n \"embedding\": {\"display_name\": \"Embedding\"},\n \"chroma_server_cors_allow_origins\": {\n \"display_name\": \"Server CORS Allow Origins\",\n \"advanced\": True,\n },\n \"chroma_server_host\": {\"display_name\": \"Server Host\", \"advanced\": True},\n \"chroma_server_port\": {\"display_name\": \"Server Port\", \"advanced\": True},\n \"chroma_server_grpc_port\": {\n \"display_name\": \"Server gRPC Port\",\n \"advanced\": True,\n },\n \"chroma_server_ssl_enabled\": {\n \"display_name\": \"Server SSL Enabled\",\n \"advanced\": True,\n },\n }\n\n def build(\n self,\n collection_name: str,\n persist: bool,\n embedding: Embeddings,\n chroma_server_ssl_enabled: bool,\n persist_directory: Optional[str] = None,\n documents: Optional[List[Document]] = None,\n chroma_server_cors_allow_origins: Optional[str] = None,\n chroma_server_host: Optional[str] = None,\n chroma_server_port: Optional[int] = None,\n chroma_server_grpc_port: Optional[int] = None,\n ) -> Union[VectorStore, BaseRetriever]:\n \"\"\"\n Builds the Vector Store or BaseRetriever object.\n\n Args:\n - collection_name (str): The name of the collection.\n - persist_directory (Optional[str]): The directory to persist the Vector Store to.\n - chroma_server_ssl_enabled (bool): Whether to enable SSL for the Chroma server.\n - persist (bool): Whether to persist the Vector Store or not.\n - embedding (Optional[Embeddings]): The embeddings to use for the Vector Store.\n - documents (Optional[Document]): The documents to use for the Vector Store.\n - chroma_server_cors_allow_origins (Optional[str]): The CORS allow origins for the Chroma server.\n - chroma_server_host (Optional[str]): The host for the Chroma server.\n - chroma_server_port (Optional[int]): The port for the Chroma server.\n - chroma_server_grpc_port (Optional[int]): The gRPC port for the Chroma server.\n\n Returns:\n - Union[VectorStore, BaseRetriever]: The Vector Store or BaseRetriever object.\n \"\"\"\n\n # Chroma settings\n chroma_settings = None\n\n if chroma_server_host is not None:\n chroma_settings = chromadb.config.Settings(\n chroma_server_cors_allow_origins=chroma_server_cors_allow_origins or None,\n chroma_server_host=chroma_server_host,\n chroma_server_port=chroma_server_port or None,\n chroma_server_grpc_port=chroma_server_grpc_port or None,\n chroma_server_ssl_enabled=chroma_server_ssl_enabled,\n )\n\n # If documents, then we need to create a Chroma instance using .from_documents\n if documents is not None and embedding is not None:\n if len(documents) == 0:\n raise ValueError(\"If documents are provided, there must be at least one document.\")\n return Chroma.from_documents(\n documents=documents, # type: ignore\n persist_directory=persist_directory if persist else None,\n collection_name=collection_name,\n embedding=embedding,\n client_settings=chroma_settings,\n )\n\n return Chroma(persist_directory=persist_directory, client_settings=chroma_settings)","fileTypes":[],"file_path":"","password":false,"name":"code","advanced":true,"dynamic":true,"info":"","title_case":true},"collection_name":{"type":"str","required":true,"placeholder":"","list":false,"show":true,"multiline":false,"value":"adam","fileTypes":[],"file_path":"","password":false,"name":"collection_name","display_name":"Collection Name","advanced":false,"dynamic":false,"info":"","title_case":true},"persist":{"type":"bool","required":true,"placeholder":"","list":false,"show":true,"multiline":false,"value":false,"fileTypes":[],"file_path":"","password":false,"name":"persist","display_name":"Persist","advanced":false,"dynamic":false,"info":"","title_case":true},"persist_directory":{"type":"str","required":false,"placeholder":"","list":false,"show":true,"multiline":false,"fileTypes":[],"file_path":"","password":false,"name":"persist_directory","display_name":"Persist Directory","advanced":false,"dynamic":false,"info":"","title_case":true},"_type":"CustomComponent"},"description":"Implementation of local Vector Store in Kalavai","base_classes":["VectorStore","BaseRetriever"],"display_name":"Kalavai VectorDB","documentation":"https://python.langchain.com/docs/integrations/vectorstores/chroma","custom_fields":{"collection_name":null,"persist":null,"embedding":null,"chroma_server_ssl_enabled":null,"persist_directory":null,"documents":null,"chroma_server_cors_allow_origins":null,"chroma_server_host":null,"chroma_server_port":null,"chroma_server_grpc_port":null},"output_types":["VectorStore","BaseRetriever"],"field_formatters":{},"beta":true},"id":"KalavaiDB-yi2jj"},"selected":false,"width":384,"height":556},{"id":"KalavaiEmbedding-u7wya","type":"genericNode","position":{"x":226.68559963436383,"y":798.4535027395182},"data":{"type":"KalavaiEmbedding","node":{"template":{"code":{"type":"code","required":true,"placeholder":"","list":false,"show":true,"multiline":true,"value":"import os\n\nimport requests\nfrom langchain_community.embeddings import InfinityEmbeddings\nfrom langflow import CustomComponent\n#from pydantic.v1.types import SecretStr\n\n\n\nclass KalavaiEmbeddingsComponent(CustomComponent):\n display_name = \"Kalavai Embeddings\"\n description = \"Kalavai sentence_transformers embedding models, API version.\"\n documentation = \"https://python.langchain.com/v0.1/docs/integrations/text_embedding/infinity/\"\n \n def load_embeddings_url(self):\n return os.getenv(\"EMBEDDING_API_URL\", \"https://embeddings.test.k8s.mvp.kalavai.net\")\n \n def load_models(self):\n # fetch available models\n EMBEDDING_API_URL = self.load_embeddings_url()\n response = requests.get(\n f\"{EMBEDDING_API_URL}/models\"\n )\n models = []\n for model_specs in response.json()[\"data\"]:\n models.append(model_specs[\"id\"])\n\n def build_config(self):\n models = self.load_models()\n return {\n \"model_name\": {\n \"display_name\": \"Model Name\",\n \"field_type\": \"str\",\n \"advanced\": False,\n \"required\": False,\n \"options\": models\n }\n }\n\n def build(\n self,\n model_name: str,\n ) -> InfinityEmbeddings:\n return InfinityEmbeddings(\n infinity_api_url=self.load_embeddings_url(),\n model=model_name,\n )","fileTypes":[],"file_path":"","password":false,"name":"code","advanced":false,"dynamic":true,"info":"","title_case":true},"model_name":{"type":"str","required":false,"placeholder":"","list":false,"show":true,"multiline":false,"fileTypes":[],"file_path":"","password":false,"name":"model_name","display_name":"Model Name","advanced":false,"dynamic":false,"info":"","title_case":true,"value":"BAAI/bge-large-en-v1.5"},"_type":"CustomComponent"},"description":"Kalavai sentence_transformers embedding models, API version.","base_classes":["InfinityEmbeddings","Embeddings"],"display_name":"Kalavai Embeddings","documentation":"https://python.langchain.com/v0.1/docs/integrations/text_embedding/infinity/","custom_fields":{"model_name":null},"output_types":["InfinityEmbeddings"],"field_formatters":{},"beta":true},"id":"KalavaiEmbedding-u7wya"},"selected":false,"width":384,"height":395},{"id":"CharacterTextSplitter-o2vyX","type":"genericNode","position":{"x":235.89260921562345,"y":105.48653174852348},"data":{"type":"CharacterTextSplitter","node":{"template":{"documents":{"type":"Document","required":true,"placeholder":"","list":true,"show":true,"multiline":false,"fileTypes":[],"file_path":"","password":false,"name":"documents","display_name":"Documents","advanced":false,"dynamic":false,"info":"","title_case":true},"chunk_overlap":{"type":"int","required":true,"placeholder":"","list":false,"show":true,"multiline":false,"value":200,"fileTypes":[],"file_path":"","password":false,"name":"chunk_overlap","display_name":"Chunk Overlap","advanced":false,"dynamic":false,"info":"","title_case":true},"chunk_size":{"type":"int","required":true,"placeholder":"","list":false,"show":true,"multiline":false,"value":1000,"fileTypes":[],"file_path":"","password":false,"name":"chunk_size","display_name":"Chunk Size","advanced":false,"dynamic":false,"info":"","title_case":true},"code":{"type":"code","required":true,"placeholder":"","list":false,"show":true,"multiline":true,"value":"from typing import List\n\nfrom langchain.text_splitter import CharacterTextSplitter\nfrom langchain_core.documents.base import Document\nfrom langflow import CustomComponent\n\n\nclass CharacterTextSplitterComponent(CustomComponent):\n display_name = \"CharacterTextSplitter\"\n description = \"Splitting text that looks at characters.\"\n\n def build_config(self):\n return {\n \"documents\": {\"display_name\": \"Documents\"},\n \"chunk_overlap\": {\"display_name\": \"Chunk Overlap\", \"default\": 200},\n \"chunk_size\": {\"display_name\": \"Chunk Size\", \"default\": 1000},\n \"separator\": {\"display_name\": \"Separator\", \"default\": \"\\n\"},\n }\n\n def build(\n self,\n documents: List[Document],\n chunk_overlap: int = 200,\n chunk_size: int = 1000,\n separator: str = \"\\n\",\n ) -> List[Document]:\n docs = CharacterTextSplitter(\n chunk_overlap=chunk_overlap,\n chunk_size=chunk_size,\n separator=separator,\n ).split_documents(documents)\n self.status = docs\n return docs\n","fileTypes":[],"file_path":"","password":false,"name":"code","advanced":false,"dynamic":true,"info":"","title_case":true},"separator":{"type":"str","required":true,"placeholder":"","list":false,"show":true,"multiline":false,"value":"\\n","fileTypes":[],"file_path":"","password":false,"name":"separator","display_name":"Separator","advanced":false,"dynamic":false,"info":"","title_case":true},"_type":"CustomComponent"},"description":"Splitting text that looks at characters.","base_classes":["Document"],"display_name":"CharacterTextSplitter","documentation":"","custom_fields":{"documents":null,"chunk_overlap":null,"chunk_size":null,"separator":null},"output_types":["Document"],"field_formatters":{},"beta":true},"id":"CharacterTextSplitter-o2vyX"},"selected":false,"width":384,"height":595},{"id":"UnstructuredMarkdownLoader-r2MFX","type":"genericNode","position":{"x":-274.0246636208216,"y":189.2475113934605},"data":{"type":"UnstructuredMarkdownLoader","node":{"template":{"file_path":{"type":"file","required":true,"placeholder":"","list":false,"show":true,"multiline":false,"value":"README.md","fileTypes":[".md"],"file_path":"/root/.cache/langflow/24073dfd-c66a-441c-8951-78588f0bd2d7/96343922219aa7616370332ffd5a7613b01ca842dd12107eb62fd2e05e8ccdee.md","password":false,"name":"file_path","advanced":false,"dynamic":false,"info":"","title_case":true},"metadata":{"type":"dict","required":false,"placeholder":"","list":false,"show":true,"multiline":false,"value":[{"":""}],"fileTypes":[],"file_path":"","password":false,"name":"metadata","display_name":"Metadata","advanced":false,"dynamic":false,"info":"","title_case":true},"_type":"UnstructuredMarkdownLoader"},"description":"Load `Markdown` files using `Unstructured`.","base_classes":["Document"],"display_name":"UnstructuredMarkdownLoader","documentation":"https://python.langchain.com/docs/modules/data_connection/document_loaders/how_to/markdown","custom_fields":{},"output_types":["Document"],"field_formatters":{},"beta":false},"id":"UnstructuredMarkdownLoader-r2MFX"},"selected":true,"width":384,"height":367,"positionAbsolute":{"x":-274.0246636208216,"y":189.2475113934605},"dragging":false}],"edges":[{"source":"KalavaiLlm-UTSYC","target":"CombineDocsChain-RoWar","sourceHandle":"{œbaseClassesœ:[œBaseLanguageModelœ,œBaseLLMœ,œBaseLanguageModelœ],œdataTypeœ:œKalavaiLlmœ,œidœ:œKalavaiLlm-UTSYCœ}","targetHandle":"{œfieldNameœ:œllmœ,œidœ:œCombineDocsChain-RoWarœ,œinputTypesœ:null,œtypeœ:œBaseLanguageModelœ}","id":"reactflow__edge-KalavaiLlm-UTSYC{œbaseClassesœ:[œBaseLanguageModelœ,œBaseLLMœ,œBaseLanguageModelœ],œdataTypeœ:œKalavaiLlmœ,œidœ:œKalavaiLlm-UTSYCœ}-CombineDocsChain-RoWar{œfieldNameœ:œllmœ,œidœ:œCombineDocsChain-RoWarœ,œinputTypesœ:null,œtypeœ:œBaseLanguageModelœ}","data":{"targetHandle":{"fieldName":"llm","id":"CombineDocsChain-RoWar","inputTypes":null,"type":"BaseLanguageModel"},"sourceHandle":{"baseClasses":["BaseLanguageModel","BaseLLM","BaseLanguageModel"],"dataType":"KalavaiLlm","id":"KalavaiLlm-UTSYC"}},"style":{"stroke":"#555"},"className":"stroke-gray-900 stroke-connection","animated":false,"selected":false},{"source":"VectorStoreRetriever-HhAfJ","target":"RetrievalQA-JFfxD","sourceHandle":"{œbaseClassesœ:[œVectorStoreRetrieverœ,œBaseRetrieverœ],œdataTypeœ:œVectorStoreRetrieverœ,œidœ:œVectorStoreRetriever-HhAfJœ}","targetHandle":"{œfieldNameœ:œretrieverœ,œidœ:œRetrievalQA-JFfxDœ,œinputTypesœ:null,œtypeœ:œBaseRetrieverœ}","id":"reactflow__edge-VectorStoreRetriever-HhAfJ{œbaseClassesœ:[œVectorStoreRetrieverœ,œBaseRetrieverœ],œdataTypeœ:œVectorStoreRetrieverœ,œidœ:œVectorStoreRetriever-HhAfJœ}-RetrievalQA-JFfxD{œfieldNameœ:œretrieverœ,œidœ:œRetrievalQA-JFfxDœ,œinputTypesœ:null,œtypeœ:œBaseRetrieverœ}","data":{"targetHandle":{"fieldName":"retriever","id":"RetrievalQA-JFfxD","inputTypes":null,"type":"BaseRetriever"},"sourceHandle":{"baseClasses":["VectorStoreRetriever","BaseRetriever"],"dataType":"VectorStoreRetriever","id":"VectorStoreRetriever-HhAfJ"}},"style":{"stroke":"#555"},"className":"stroke-gray-900 stroke-connection","animated":false,"selected":false},{"source":"KalavaiDB-yi2jj","target":"VectorStoreRetriever-HhAfJ","sourceHandle":"{œbaseClassesœ:[œVectorStoreœ,œBaseRetrieverœ],œdataTypeœ:œKalavaiDBœ,œidœ:œKalavaiDB-yi2jjœ}","targetHandle":"{œfieldNameœ:œvectorstoreœ,œidœ:œVectorStoreRetriever-HhAfJœ,œinputTypesœ:null,œtypeœ:œVectorStoreœ}","id":"reactflow__edge-KalavaiDB-yi2jj{œbaseClassesœ:[œVectorStoreœ,œBaseRetrieverœ],œdataTypeœ:œKalavaiDBœ,œidœ:œKalavaiDB-yi2jjœ}-VectorStoreRetriever-HhAfJ{œfieldNameœ:œvectorstoreœ,œidœ:œVectorStoreRetriever-HhAfJœ,œinputTypesœ:null,œtypeœ:œVectorStoreœ}","data":{"targetHandle":{"fieldName":"vectorstore","id":"VectorStoreRetriever-HhAfJ","inputTypes":null,"type":"VectorStore"},"sourceHandle":{"baseClasses":["VectorStore","BaseRetriever"],"dataType":"KalavaiDB","id":"KalavaiDB-yi2jj"}},"style":{"stroke":"#555"},"className":"stroke-gray-900 stroke-connection","animated":false,"selected":false},{"source":"KalavaiEmbedding-u7wya","target":"KalavaiDB-yi2jj","sourceHandle":"{œbaseClassesœ:[œInfinityEmbeddingsœ,œEmbeddingsœ],œdataTypeœ:œKalavaiEmbeddingœ,œidœ:œKalavaiEmbedding-u7wyaœ}","targetHandle":"{œfieldNameœ:œembeddingœ,œidœ:œKalavaiDB-yi2jjœ,œinputTypesœ:null,œtypeœ:œEmbeddingsœ}","id":"reactflow__edge-KalavaiEmbedding-u7wya{œbaseClassesœ:[œInfinityEmbeddingsœ,œEmbeddingsœ],œdataTypeœ:œKalavaiEmbeddingœ,œidœ:œKalavaiEmbedding-u7wyaœ}-KalavaiDB-yi2jj{œfieldNameœ:œembeddingœ,œidœ:œKalavaiDB-yi2jjœ,œinputTypesœ:null,œtypeœ:œEmbeddingsœ}","data":{"targetHandle":{"fieldName":"embedding","id":"KalavaiDB-yi2jj","inputTypes":null,"type":"Embeddings"},"sourceHandle":{"baseClasses":["InfinityEmbeddings","Embeddings"],"dataType":"KalavaiEmbedding","id":"KalavaiEmbedding-u7wya"}},"style":{"stroke":"#555"},"className":"stroke-gray-900 stroke-connection","animated":false,"selected":false},{"source":"CombineDocsChain-RoWar","target":"RetrievalQA-JFfxD","sourceHandle":"{œbaseClassesœ:[œBaseCombineDocumentsChainœ,œCallableœ],œdataTypeœ:œCombineDocsChainœ,œidœ:œCombineDocsChain-RoWarœ}","targetHandle":"{œfieldNameœ:œcombine_documents_chainœ,œidœ:œRetrievalQA-JFfxDœ,œinputTypesœ:null,œtypeœ:œBaseCombineDocumentsChainœ}","id":"reactflow__edge-CombineDocsChain-RoWar{œbaseClassesœ:[œBaseCombineDocumentsChainœ,œCallableœ],œdataTypeœ:œCombineDocsChainœ,œidœ:œCombineDocsChain-RoWarœ}-RetrievalQA-JFfxD{œfieldNameœ:œcombine_documents_chainœ,œidœ:œRetrievalQA-JFfxDœ,œinputTypesœ:null,œtypeœ:œBaseCombineDocumentsChainœ}","data":{"targetHandle":{"fieldName":"combine_documents_chain","id":"RetrievalQA-JFfxD","inputTypes":null,"type":"BaseCombineDocumentsChain"},"sourceHandle":{"baseClasses":["BaseCombineDocumentsChain","Callable"],"dataType":"CombineDocsChain","id":"CombineDocsChain-RoWar"}},"style":{"stroke":"#555"},"className":"stroke-gray-900 stroke-connection","animated":false,"selected":false},{"source":"CharacterTextSplitter-o2vyX","target":"KalavaiDB-yi2jj","sourceHandle":"{œbaseClassesœ:[œDocumentœ],œdataTypeœ:œCharacterTextSplitterœ,œidœ:œCharacterTextSplitter-o2vyXœ}","targetHandle":"{œfieldNameœ:œdocumentsœ,œidœ:œKalavaiDB-yi2jjœ,œinputTypesœ:null,œtypeœ:œDocumentœ}","id":"reactflow__edge-CharacterTextSplitter-o2vyX{œbaseClassesœ:[œDocumentœ],œdataTypeœ:œCharacterTextSplitterœ,œidœ:œCharacterTextSplitter-o2vyXœ}-KalavaiDB-yi2jj{œfieldNameœ:œdocumentsœ,œidœ:œKalavaiDB-yi2jjœ,œinputTypesœ:null,œtypeœ:œDocumentœ}","data":{"targetHandle":{"fieldName":"documents","id":"KalavaiDB-yi2jj","inputTypes":null,"type":"Document"},"sourceHandle":{"baseClasses":["Document"],"dataType":"CharacterTextSplitter","id":"CharacterTextSplitter-o2vyX"}},"style":{"stroke":"#555"},"className":"stroke-gray-900 stroke-connection","animated":false,"selected":false},{"source":"UnstructuredMarkdownLoader-r2MFX","sourceHandle":"{œbaseClassesœ:[œDocumentœ],œdataTypeœ:œUnstructuredMarkdownLoaderœ,œidœ:œUnstructuredMarkdownLoader-r2MFXœ}","target":"CharacterTextSplitter-o2vyX","targetHandle":"{œfieldNameœ:œdocumentsœ,œidœ:œCharacterTextSplitter-o2vyXœ,œinputTypesœ:null,œtypeœ:œDocumentœ}","data":{"targetHandle":{"fieldName":"documents","id":"CharacterTextSplitter-o2vyX","inputTypes":null,"type":"Document"},"sourceHandle":{"baseClasses":["Document"],"dataType":"UnstructuredMarkdownLoader","id":"UnstructuredMarkdownLoader-r2MFX"}},"style":{"stroke":"#555"},"className":"stroke-foreground stroke-connection","animated":false,"id":"reactflow__edge-UnstructuredMarkdownLoader-r2MFX{œbaseClassesœ:[œDocumentœ],œdataTypeœ:œUnstructuredMarkdownLoaderœ,œidœ:œUnstructuredMarkdownLoader-r2MFXœ}-CharacterTextSplitter-o2vyX{œfieldNameœ:œdocumentsœ,œidœ:œCharacterTextSplitter-o2vyXœ,œinputTypesœ:null,œtypeœ:œDocumentœ}"}],"viewport":{"x":318.3413156326185,"y":66.89379175482227,"zoom":0.4537595776585801}},"is_component":false,"updated_at":"2024-05-22T15:05:17.380548","folder":null,"id":"24073dfd-c66a-441c-8951-78588f0bd2d7","user_id":"c016ec20-7852-4f5e-b776-72f16afb9a37"}]} \ No newline at end of file diff --git a/example_flows/Basic RAG Example.json b/example_flows/Basic RAG Example.json new file mode 100644 index 0000000..318254d --- /dev/null +++ b/example_flows/Basic RAG Example.json @@ -0,0 +1 @@ +{"id":"24073dfd-c66a-441c-8951-78588f0bd2d7","data":{"nodes":[{"id":"KalavaiLlm-UTSYC","type":"genericNode","position":{"x":725.3194922736798,"y":-35.23333740234375},"data":{"type":"KalavaiLlm","node":{"template":{"code":{"type":"code","required":true,"placeholder":"","list":false,"show":true,"multiline":true,"value":"import os\nimport json\nfrom typing import Optional, Union\n\nfrom langchain.llms import BaseLLM\nfrom langchain_community.chat_models.openai import ChatOpenAI\n\nfrom langflow import CustomComponent\nfrom langflow.field_typing import BaseLanguageModel, NestedDict\n\n\nclass KalavaiLLMComponent(CustomComponent):\n display_name = \"KalavaiLLM\"\n description = \"API for LLM models deployed in Kalavai.\"\n \n def _load_endpoints(self):\n MODEL_ENDPOINTS_FILE = os.getenv(\"MODEL_ENDPOINTS\", \"data/model_endpoints.json\")\n \n with open(MODEL_ENDPOINTS_FILE, \"r\") as f:\n return json.load(f)\n \n\n def build_config(self):\n model_endpoints = self._load_endpoints()\n api_key = os.getenv(\"MODEL_ENDPOINT_API_KEY\", \"N3E9AGVU7IR9E6QLXMIP6YO330M2D005DH5MN4C6\")\n return {\n \"max_tokens\": {\n \"display_name\": \"Max Tokens\",\n \"field_type\": \"int\",\n \"advanced\": False,\n \"required\": False,\n },\n \"model_kwargs\": {\n \"display_name\": \"Model Kwargs\",\n \"field_type\": \"NestedDict\",\n \"advanced\": True,\n \"required\": False,\n },\n \"model_name\": {\n \"display_name\": \"Model Name\",\n \"field_type\": \"str\",\n \"advanced\": False,\n \"required\": False,\n \"options\": list(model_endpoints.keys()),\n },\n \"kalavai_api_key\": {\n \"display_name\": \"Kalavai API Key\",\n \"field_type\": \"str\",\n \"advanced\": True,\n \"required\": False,\n \"password\": True,\n \"value\": api_key\n },\n \"temperature\": {\n \"display_name\": \"Temperature\",\n \"field_type\": \"float\",\n \"advanced\": False,\n \"required\": False,\n \"value\": 0.7,\n },\n }\n\n def build(\n self,\n max_tokens: Optional[int] = 256,\n model_kwargs: NestedDict = {},\n model_name: str = \"Equall/Saul-Instruct-v1\",\n kalavai_api_key: Optional[str] = None,\n temperature: float = 0.7,\n ) -> Union[BaseLanguageModel, BaseLLM]:\n model_endpoints = self._load_endpoints()\n return ChatOpenAI(\n max_tokens=max_tokens,\n model_kwargs=model_kwargs,\n model=model_name,\n base_url=model_endpoints[model_name],\n api_key=kalavai_api_key,\n temperature=temperature,\n )","fileTypes":[],"file_path":"","password":false,"name":"code","advanced":false,"dynamic":true,"info":"","title_case":true},"kalavai_api_key":{"type":"str","required":false,"placeholder":"","list":false,"show":true,"multiline":false,"value":"N3E9AGVU7IR9E6QLXMIP6YO330M2D005DH5MN4C6","fileTypes":[],"file_path":"","password":true,"name":"kalavai_api_key","display_name":"Kalavai API Key","advanced":true,"dynamic":false,"info":"","title_case":true},"max_tokens":{"type":"int","required":false,"placeholder":"","list":false,"show":true,"multiline":false,"value":256,"fileTypes":[],"file_path":"","password":false,"name":"max_tokens","display_name":"Max Tokens","advanced":false,"dynamic":false,"info":"","title_case":true},"model_kwargs":{"type":"NestedDict","required":false,"placeholder":"","list":false,"show":true,"multiline":false,"value":{},"fileTypes":[],"file_path":"","password":false,"name":"model_kwargs","display_name":"Model Kwargs","advanced":true,"dynamic":false,"info":"","title_case":true},"model_name":{"type":"str","required":false,"placeholder":"","list":true,"show":true,"multiline":false,"value":"meta-llama/Meta-Llama-3-8B-Instruct","fileTypes":[],"file_path":"","password":false,"options":["meta-llama/Meta-Llama-3-8B-Instruct","Equall/Saul-Instruct-v1"],"name":"model_name","display_name":"Model Name","advanced":false,"dynamic":false,"info":"","title_case":true},"temperature":{"type":"float","required":false,"placeholder":"","list":false,"show":true,"multiline":false,"value":0.7,"fileTypes":[],"file_path":"","password":false,"name":"temperature","display_name":"Temperature","advanced":false,"dynamic":false,"info":"","rangeSpec":{"min":-1,"max":1,"step":0.1},"title_case":true},"_type":"CustomComponent"},"description":"API for LLM models deployed in Kalavai.","base_classes":["BaseLanguageModel","BaseLLM","BaseLanguageModel"],"display_name":"KalavaiLLM","documentation":"","custom_fields":{"max_tokens":null,"model_kwargs":null,"model_name":null,"kalavai_api_key":null,"temperature":null},"output_types":["BaseLanguageModel","BaseLLM"],"field_formatters":{},"beta":true},"id":"KalavaiLlm-UTSYC"},"selected":false,"width":384,"height":543},{"id":"RetrievalQA-JFfxD","type":"genericNode","position":{"x":1673.8725742931108,"y":523.5984503198706},"data":{"type":"RetrievalQA","node":{"template":{"combine_documents_chain":{"type":"BaseCombineDocumentsChain","required":true,"placeholder":"","list":false,"show":true,"multiline":false,"fileTypes":[],"file_path":"","password":false,"name":"combine_documents_chain","display_name":"Combine Documents Chain","advanced":false,"dynamic":false,"info":"","title_case":true},"memory":{"type":"BaseMemory","required":false,"placeholder":"","list":false,"show":true,"multiline":false,"fileTypes":[],"file_path":"","password":false,"name":"memory","display_name":"Memory","advanced":false,"dynamic":false,"info":"","title_case":true},"retriever":{"type":"BaseRetriever","required":true,"placeholder":"","list":false,"show":true,"multiline":false,"fileTypes":[],"file_path":"","password":false,"name":"retriever","display_name":"Retriever","advanced":false,"dynamic":false,"info":"","title_case":true},"code":{"type":"code","required":true,"placeholder":"","list":false,"show":true,"multiline":true,"value":"from typing import Callable, Optional, Union\n\nfrom langchain.chains.combine_documents.base import BaseCombineDocumentsChain\nfrom langchain.chains.retrieval_qa.base import BaseRetrievalQA, RetrievalQA\nfrom langflow import CustomComponent\nfrom langflow.field_typing import BaseMemory, BaseRetriever\n\n\nclass RetrievalQAComponent(CustomComponent):\n display_name = \"RetrievalQA\"\n description = \"Chain for question-answering against an index.\"\n\n def build_config(self):\n return {\n \"combine_documents_chain\": {\"display_name\": \"Combine Documents Chain\"},\n \"retriever\": {\"display_name\": \"Retriever\"},\n \"memory\": {\"display_name\": \"Memory\", \"required\": False},\n \"input_key\": {\"display_name\": \"Input Key\", \"advanced\": True},\n \"output_key\": {\"display_name\": \"Output Key\", \"advanced\": True},\n \"return_source_documents\": {\"display_name\": \"Return Source Documents\"},\n }\n\n def build(\n self,\n combine_documents_chain: BaseCombineDocumentsChain,\n retriever: BaseRetriever,\n memory: Optional[BaseMemory] = None,\n input_key: str = \"query\",\n output_key: str = \"result\",\n return_source_documents: bool = True,\n ) -> Union[BaseRetrievalQA, Callable]:\n return RetrievalQA(\n combine_documents_chain=combine_documents_chain,\n retriever=retriever,\n memory=memory,\n input_key=input_key,\n output_key=output_key,\n return_source_documents=return_source_documents,\n )\n","fileTypes":[],"file_path":"","password":false,"name":"code","advanced":false,"dynamic":true,"info":"","title_case":true},"input_key":{"type":"str","required":true,"placeholder":"","list":false,"show":true,"multiline":false,"value":"query","fileTypes":[],"file_path":"","password":false,"name":"input_key","display_name":"Input Key","advanced":true,"dynamic":false,"info":"","title_case":true},"output_key":{"type":"str","required":true,"placeholder":"","list":false,"show":true,"multiline":false,"value":"result","fileTypes":[],"file_path":"","password":false,"name":"output_key","display_name":"Output Key","advanced":true,"dynamic":false,"info":"","title_case":true},"return_source_documents":{"type":"bool","required":true,"placeholder":"","list":false,"show":true,"multiline":false,"value":true,"fileTypes":[],"file_path":"","password":false,"name":"return_source_documents","display_name":"Return Source Documents","advanced":false,"dynamic":false,"info":"","title_case":true},"_type":"CustomComponent"},"description":"Chain for question-answering against an index.","base_classes":["BaseRetrievalQA","Chain","Callable"],"display_name":"RetrievalQA","documentation":"","custom_fields":{"combine_documents_chain":null,"retriever":null,"memory":null,"input_key":null,"output_key":null,"return_source_documents":null},"output_types":["BaseRetrievalQA","Callable"],"field_formatters":{},"beta":true},"id":"RetrievalQA-JFfxD"},"selected":false,"width":384,"height":502},{"id":"CombineDocsChain-RoWar","type":"genericNode","position":{"x":1209.875644476401,"y":297.9196358451761},"data":{"type":"CombineDocsChain","node":{"template":{"llm":{"type":"BaseLanguageModel","required":true,"placeholder":"","list":false,"show":true,"multiline":false,"value":"","fileTypes":[],"file_path":"","password":false,"name":"llm","display_name":"LLM","advanced":false,"dynamic":false,"info":"","title_case":true},"chain_type":{"type":"str","required":true,"placeholder":"","list":true,"show":true,"multiline":false,"value":"stuff","fileTypes":[],"file_path":"","password":false,"options":["stuff","map_reduce","map_rerank","refine"],"name":"chain_type","advanced":false,"dynamic":false,"info":"","title_case":true},"_type":"load_qa_chain"},"description":"Load question answering chain.","base_classes":["BaseCombineDocumentsChain","Callable"],"display_name":"CombineDocsChain","documentation":"","custom_fields":{},"output_types":[],"field_formatters":{},"beta":false},"id":"CombineDocsChain-RoWar"},"selected":false,"width":384,"height":333},{"id":"VectorStoreRetriever-HhAfJ","type":"genericNode","position":{"x":1212.0761528831624,"y":782.3173486940761},"data":{"type":"VectorStoreRetriever","node":{"template":{"vectorstore":{"type":"VectorStore","required":true,"placeholder":"","list":false,"show":true,"multiline":false,"fileTypes":[],"file_path":"","password":false,"name":"vectorstore","display_name":"Vector Store","advanced":false,"dynamic":false,"info":"","title_case":true},"code":{"type":"code","required":true,"placeholder":"","list":false,"show":true,"multiline":true,"value":"from langchain_core.vectorstores import VectorStoreRetriever\n\nfrom langflow import CustomComponent\nfrom langflow.field_typing import VectorStore\n\n\nclass VectoStoreRetrieverComponent(CustomComponent):\n display_name = \"VectorStore Retriever\"\n description = \"A vector store retriever\"\n\n def build_config(self):\n return {\n \"vectorstore\": {\"display_name\": \"Vector Store\", \"type\": VectorStore},\n }\n\n def build(self, vectorstore: VectorStore) -> VectorStoreRetriever:\n return vectorstore.as_retriever()\n","fileTypes":[],"file_path":"","password":false,"name":"code","advanced":false,"dynamic":true,"info":"","title_case":true},"_type":"CustomComponent"},"description":"A vector store retriever","base_classes":["VectorStoreRetriever","BaseRetriever"],"display_name":"VectorStore Retriever","documentation":"","custom_fields":{"vectorstore":null},"output_types":["VectorStoreRetriever"],"field_formatters":{},"beta":true},"id":"VectorStoreRetriever-HhAfJ"},"selected":false,"width":384,"height":329},{"id":"KalavaiDB-yi2jj","type":"genericNode","position":{"x":726.2514329243163,"y":583.3451840691723},"data":{"type":"KalavaiDB","node":{"template":{"documents":{"type":"Document","required":false,"placeholder":"","list":true,"show":true,"multiline":false,"fileTypes":[],"file_path":"","password":false,"name":"documents","display_name":"Documents","advanced":false,"dynamic":false,"info":"","title_case":true},"embedding":{"type":"Embeddings","required":true,"placeholder":"","list":false,"show":true,"multiline":false,"fileTypes":[],"file_path":"","password":false,"name":"embedding","display_name":"Embedding","advanced":false,"dynamic":false,"info":"","title_case":true},"chroma_server_cors_allow_origins":{"type":"str","required":false,"placeholder":"","list":false,"show":true,"multiline":false,"fileTypes":[],"file_path":"","password":false,"name":"chroma_server_cors_allow_origins","display_name":"Server CORS Allow Origins","advanced":true,"dynamic":false,"info":"","title_case":true},"chroma_server_grpc_port":{"type":"int","required":false,"placeholder":"","list":false,"show":true,"multiline":false,"fileTypes":[],"file_path":"","password":false,"name":"chroma_server_grpc_port","display_name":"Server gRPC Port","advanced":true,"dynamic":false,"info":"","title_case":true},"chroma_server_host":{"type":"str","required":false,"placeholder":"","list":false,"show":true,"multiline":false,"fileTypes":[],"file_path":"","password":false,"name":"chroma_server_host","display_name":"Server Host","advanced":true,"dynamic":false,"info":"","title_case":true},"chroma_server_port":{"type":"int","required":false,"placeholder":"","list":false,"show":true,"multiline":false,"fileTypes":[],"file_path":"","password":false,"name":"chroma_server_port","display_name":"Server Port","advanced":true,"dynamic":false,"info":"","title_case":true},"chroma_server_ssl_enabled":{"type":"bool","required":true,"placeholder":"","list":false,"show":true,"multiline":false,"value":false,"fileTypes":[],"file_path":"","password":false,"name":"chroma_server_ssl_enabled","display_name":"Server SSL Enabled","advanced":true,"dynamic":false,"info":"","title_case":true},"code":{"type":"code","required":true,"placeholder":"","list":false,"show":true,"multiline":true,"value":"\"\"\"\nReference: https://github.com/langflow-ai/langflow/tree/dev/src/backend/base/langflow/components/vectorstores\n\"\"\"\nfrom typing import List, Optional, Union\n\nimport chromadb # type: ignore\nfrom langchain.embeddings.base import Embeddings\nfrom langchain.schema import BaseRetriever, Document\nfrom langchain_community.vectorstores import VectorStore\nfrom langchain_community.vectorstores.chroma import Chroma\nfrom langflow import CustomComponent\n\n\nclass KalavaiVectorDBComponent(CustomComponent):\n \"\"\"\n A custom component for implementing a Vector Store using Chroma.\n \"\"\"\n\n display_name: str = \"Kalavai VectorDB\"\n description: str = \"Implementation of local Vector Store in Kalavai\"\n documentation = \"https://python.langchain.com/docs/integrations/vectorstores/chroma\"\n beta: bool = True\n\n def build_config(self):\n \"\"\"\n Builds the configuration for the component.\n\n Returns:\n - dict: A dictionary containing the configuration options for the component.\n \"\"\"\n return {\n \"collection_name\": {\"display_name\": \"Collection Name\", \"value\": \"langflow\"},\n \"persist\": {\"display_name\": \"Persist\"},\n \"persist_directory\": {\"display_name\": \"Persist Directory\"},\n \"code\": {\"advanced\": True, \"display_name\": \"Code\"},\n \"documents\": {\"display_name\": \"Documents\", \"is_list\": True},\n \"embedding\": {\"display_name\": \"Embedding\"},\n \"chroma_server_cors_allow_origins\": {\n \"display_name\": \"Server CORS Allow Origins\",\n \"advanced\": True,\n },\n \"chroma_server_host\": {\"display_name\": \"Server Host\", \"advanced\": True},\n \"chroma_server_port\": {\"display_name\": \"Server Port\", \"advanced\": True},\n \"chroma_server_grpc_port\": {\n \"display_name\": \"Server gRPC Port\",\n \"advanced\": True,\n },\n \"chroma_server_ssl_enabled\": {\n \"display_name\": \"Server SSL Enabled\",\n \"advanced\": True,\n },\n }\n\n def build(\n self,\n collection_name: str,\n persist: bool,\n embedding: Embeddings,\n chroma_server_ssl_enabled: bool,\n persist_directory: Optional[str] = None,\n documents: Optional[List[Document]] = None,\n chroma_server_cors_allow_origins: Optional[str] = None,\n chroma_server_host: Optional[str] = None,\n chroma_server_port: Optional[int] = None,\n chroma_server_grpc_port: Optional[int] = None,\n ) -> Union[VectorStore, BaseRetriever]:\n \"\"\"\n Builds the Vector Store or BaseRetriever object.\n\n Args:\n - collection_name (str): The name of the collection.\n - persist_directory (Optional[str]): The directory to persist the Vector Store to.\n - chroma_server_ssl_enabled (bool): Whether to enable SSL for the Chroma server.\n - persist (bool): Whether to persist the Vector Store or not.\n - embedding (Optional[Embeddings]): The embeddings to use for the Vector Store.\n - documents (Optional[Document]): The documents to use for the Vector Store.\n - chroma_server_cors_allow_origins (Optional[str]): The CORS allow origins for the Chroma server.\n - chroma_server_host (Optional[str]): The host for the Chroma server.\n - chroma_server_port (Optional[int]): The port for the Chroma server.\n - chroma_server_grpc_port (Optional[int]): The gRPC port for the Chroma server.\n\n Returns:\n - Union[VectorStore, BaseRetriever]: The Vector Store or BaseRetriever object.\n \"\"\"\n\n # Chroma settings\n chroma_settings = None\n\n if chroma_server_host is not None:\n chroma_settings = chromadb.config.Settings(\n chroma_server_cors_allow_origins=chroma_server_cors_allow_origins or None,\n chroma_server_host=chroma_server_host,\n chroma_server_port=chroma_server_port or None,\n chroma_server_grpc_port=chroma_server_grpc_port or None,\n chroma_server_ssl_enabled=chroma_server_ssl_enabled,\n )\n\n # If documents, then we need to create a Chroma instance using .from_documents\n if documents is not None and embedding is not None:\n if len(documents) == 0:\n raise ValueError(\"If documents are provided, there must be at least one document.\")\n return Chroma.from_documents(\n documents=documents, # type: ignore\n persist_directory=persist_directory if persist else None,\n collection_name=collection_name,\n embedding=embedding,\n client_settings=chroma_settings,\n )\n\n return Chroma(persist_directory=persist_directory, client_settings=chroma_settings)","fileTypes":[],"file_path":"","password":false,"name":"code","advanced":true,"dynamic":true,"info":"","title_case":true},"collection_name":{"type":"str","required":true,"placeholder":"","list":false,"show":true,"multiline":false,"value":"adam","fileTypes":[],"file_path":"","password":false,"name":"collection_name","display_name":"Collection Name","advanced":false,"dynamic":false,"info":"","title_case":true},"persist":{"type":"bool","required":true,"placeholder":"","list":false,"show":true,"multiline":false,"value":false,"fileTypes":[],"file_path":"","password":false,"name":"persist","display_name":"Persist","advanced":false,"dynamic":false,"info":"","title_case":true},"persist_directory":{"type":"str","required":false,"placeholder":"","list":false,"show":true,"multiline":false,"fileTypes":[],"file_path":"","password":false,"name":"persist_directory","display_name":"Persist Directory","advanced":false,"dynamic":false,"info":"","title_case":true},"_type":"CustomComponent"},"description":"Implementation of local Vector Store in Kalavai","base_classes":["VectorStore","BaseRetriever"],"display_name":"Kalavai VectorDB","documentation":"https://python.langchain.com/docs/integrations/vectorstores/chroma","custom_fields":{"collection_name":null,"persist":null,"embedding":null,"chroma_server_ssl_enabled":null,"persist_directory":null,"documents":null,"chroma_server_cors_allow_origins":null,"chroma_server_host":null,"chroma_server_port":null,"chroma_server_grpc_port":null},"output_types":["VectorStore","BaseRetriever"],"field_formatters":{},"beta":true},"id":"KalavaiDB-yi2jj"},"selected":false,"width":384,"height":556},{"id":"KalavaiEmbedding-u7wya","type":"genericNode","position":{"x":226.68559963436383,"y":798.4535027395182},"data":{"type":"KalavaiEmbedding","node":{"template":{"code":{"type":"code","required":true,"placeholder":"","list":false,"show":true,"multiline":true,"value":"import os\n\nimport requests\nfrom langchain_community.embeddings import InfinityEmbeddings\nfrom langflow import CustomComponent\n#from pydantic.v1.types import SecretStr\n\n\n\nclass KalavaiEmbeddingsComponent(CustomComponent):\n display_name = \"Kalavai Embeddings\"\n description = \"Kalavai sentence_transformers embedding models, API version.\"\n documentation = \"https://python.langchain.com/v0.1/docs/integrations/text_embedding/infinity/\"\n \n def load_embeddings_url(self):\n return os.getenv(\"EMBEDDING_API_URL\", \"https://embeddings.test.k8s.mvp.kalavai.net\")\n \n def load_models(self):\n # fetch available models\n EMBEDDING_API_URL = self.load_embeddings_url()\n response = requests.get(\n f\"{EMBEDDING_API_URL}/models\"\n )\n models = []\n for model_specs in response.json()[\"data\"]:\n models.append(model_specs[\"id\"])\n\n def build_config(self):\n models = self.load_models()\n return {\n \"model_name\": {\n \"display_name\": \"Model Name\",\n \"field_type\": \"str\",\n \"advanced\": False,\n \"required\": False,\n \"options\": models\n }\n }\n\n def build(\n self,\n model_name: str,\n ) -> InfinityEmbeddings:\n return InfinityEmbeddings(\n infinity_api_url=self.load_embeddings_url(),\n model=model_name,\n )","fileTypes":[],"file_path":"","password":false,"name":"code","advanced":false,"dynamic":true,"info":"","title_case":true},"model_name":{"type":"str","required":false,"placeholder":"","list":false,"show":true,"multiline":false,"fileTypes":[],"file_path":"","password":false,"name":"model_name","display_name":"Model Name","advanced":false,"dynamic":false,"info":"","title_case":true,"value":"BAAI/bge-large-en-v1.5"},"_type":"CustomComponent"},"description":"Kalavai sentence_transformers embedding models, API version.","base_classes":["InfinityEmbeddings","Embeddings"],"display_name":"Kalavai Embeddings","documentation":"https://python.langchain.com/v0.1/docs/integrations/text_embedding/infinity/","custom_fields":{"model_name":null},"output_types":["InfinityEmbeddings"],"field_formatters":{},"beta":true},"id":"KalavaiEmbedding-u7wya"},"selected":false,"width":384,"height":395},{"id":"CharacterTextSplitter-o2vyX","type":"genericNode","position":{"x":235.89260921562345,"y":105.48653174852348},"data":{"type":"CharacterTextSplitter","node":{"template":{"documents":{"type":"Document","required":true,"placeholder":"","list":true,"show":true,"multiline":false,"fileTypes":[],"file_path":"","password":false,"name":"documents","display_name":"Documents","advanced":false,"dynamic":false,"info":"","title_case":true},"chunk_overlap":{"type":"int","required":true,"placeholder":"","list":false,"show":true,"multiline":false,"value":200,"fileTypes":[],"file_path":"","password":false,"name":"chunk_overlap","display_name":"Chunk Overlap","advanced":false,"dynamic":false,"info":"","title_case":true},"chunk_size":{"type":"int","required":true,"placeholder":"","list":false,"show":true,"multiline":false,"value":1000,"fileTypes":[],"file_path":"","password":false,"name":"chunk_size","display_name":"Chunk Size","advanced":false,"dynamic":false,"info":"","title_case":true},"code":{"type":"code","required":true,"placeholder":"","list":false,"show":true,"multiline":true,"value":"from typing import List\n\nfrom langchain.text_splitter import CharacterTextSplitter\nfrom langchain_core.documents.base import Document\nfrom langflow import CustomComponent\n\n\nclass CharacterTextSplitterComponent(CustomComponent):\n display_name = \"CharacterTextSplitter\"\n description = \"Splitting text that looks at characters.\"\n\n def build_config(self):\n return {\n \"documents\": {\"display_name\": \"Documents\"},\n \"chunk_overlap\": {\"display_name\": \"Chunk Overlap\", \"default\": 200},\n \"chunk_size\": {\"display_name\": \"Chunk Size\", \"default\": 1000},\n \"separator\": {\"display_name\": \"Separator\", \"default\": \"\\n\"},\n }\n\n def build(\n self,\n documents: List[Document],\n chunk_overlap: int = 200,\n chunk_size: int = 1000,\n separator: str = \"\\n\",\n ) -> List[Document]:\n docs = CharacterTextSplitter(\n chunk_overlap=chunk_overlap,\n chunk_size=chunk_size,\n separator=separator,\n ).split_documents(documents)\n self.status = docs\n return docs\n","fileTypes":[],"file_path":"","password":false,"name":"code","advanced":false,"dynamic":true,"info":"","title_case":true},"separator":{"type":"str","required":true,"placeholder":"","list":false,"show":true,"multiline":false,"value":"\\n","fileTypes":[],"file_path":"","password":false,"name":"separator","display_name":"Separator","advanced":false,"dynamic":false,"info":"","title_case":true},"_type":"CustomComponent"},"description":"Splitting text that looks at characters.","base_classes":["Document"],"display_name":"CharacterTextSplitter","documentation":"","custom_fields":{"documents":null,"chunk_overlap":null,"chunk_size":null,"separator":null},"output_types":["Document"],"field_formatters":{},"beta":true},"id":"CharacterTextSplitter-o2vyX"},"selected":false,"width":384,"height":595},{"id":"UnstructuredMarkdownLoader-r2MFX","type":"genericNode","position":{"x":-274.0246636208216,"y":189.2475113934605},"data":{"type":"UnstructuredMarkdownLoader","node":{"template":{"file_path":{"type":"file","required":true,"placeholder":"","list":false,"show":true,"multiline":false,"value":"","fileTypes":[".md"],"file_path":"/root/.cache/langflow/24073dfd-c66a-441c-8951-78588f0bd2d7/96343922219aa7616370332ffd5a7613b01ca842dd12107eb62fd2e05e8ccdee.md","password":false,"name":"file_path","advanced":false,"dynamic":false,"info":"","title_case":true},"metadata":{"type":"dict","required":false,"placeholder":"","list":false,"show":true,"multiline":false,"value":[{"":""}],"fileTypes":[],"file_path":"","password":false,"name":"metadata","display_name":"Metadata","advanced":false,"dynamic":false,"info":"","title_case":true},"_type":"UnstructuredMarkdownLoader"},"description":"Load `Markdown` files using `Unstructured`.","base_classes":["Document"],"display_name":"UnstructuredMarkdownLoader","documentation":"https://python.langchain.com/docs/modules/data_connection/document_loaders/how_to/markdown","custom_fields":{},"output_types":["Document"],"field_formatters":{},"beta":false},"id":"UnstructuredMarkdownLoader-r2MFX"},"selected":true,"width":384,"height":367,"positionAbsolute":{"x":-274.0246636208216,"y":189.2475113934605},"dragging":false}],"edges":[{"source":"KalavaiLlm-UTSYC","target":"CombineDocsChain-RoWar","sourceHandle":"{œbaseClassesœ:[œBaseLanguageModelœ,œBaseLLMœ,œBaseLanguageModelœ],œdataTypeœ:œKalavaiLlmœ,œidœ:œKalavaiLlm-UTSYCœ}","targetHandle":"{œfieldNameœ:œllmœ,œidœ:œCombineDocsChain-RoWarœ,œinputTypesœ:null,œtypeœ:œBaseLanguageModelœ}","id":"reactflow__edge-KalavaiLlm-UTSYC{œbaseClassesœ:[œBaseLanguageModelœ,œBaseLLMœ,œBaseLanguageModelœ],œdataTypeœ:œKalavaiLlmœ,œidœ:œKalavaiLlm-UTSYCœ}-CombineDocsChain-RoWar{œfieldNameœ:œllmœ,œidœ:œCombineDocsChain-RoWarœ,œinputTypesœ:null,œtypeœ:œBaseLanguageModelœ}","data":{"targetHandle":{"fieldName":"llm","id":"CombineDocsChain-RoWar","inputTypes":null,"type":"BaseLanguageModel"},"sourceHandle":{"baseClasses":["BaseLanguageModel","BaseLLM","BaseLanguageModel"],"dataType":"KalavaiLlm","id":"KalavaiLlm-UTSYC"}},"style":{"stroke":"#555"},"className":"stroke-gray-900 stroke-connection","animated":false,"selected":false},{"source":"VectorStoreRetriever-HhAfJ","target":"RetrievalQA-JFfxD","sourceHandle":"{œbaseClassesœ:[œVectorStoreRetrieverœ,œBaseRetrieverœ],œdataTypeœ:œVectorStoreRetrieverœ,œidœ:œVectorStoreRetriever-HhAfJœ}","targetHandle":"{œfieldNameœ:œretrieverœ,œidœ:œRetrievalQA-JFfxDœ,œinputTypesœ:null,œtypeœ:œBaseRetrieverœ}","id":"reactflow__edge-VectorStoreRetriever-HhAfJ{œbaseClassesœ:[œVectorStoreRetrieverœ,œBaseRetrieverœ],œdataTypeœ:œVectorStoreRetrieverœ,œidœ:œVectorStoreRetriever-HhAfJœ}-RetrievalQA-JFfxD{œfieldNameœ:œretrieverœ,œidœ:œRetrievalQA-JFfxDœ,œinputTypesœ:null,œtypeœ:œBaseRetrieverœ}","data":{"targetHandle":{"fieldName":"retriever","id":"RetrievalQA-JFfxD","inputTypes":null,"type":"BaseRetriever"},"sourceHandle":{"baseClasses":["VectorStoreRetriever","BaseRetriever"],"dataType":"VectorStoreRetriever","id":"VectorStoreRetriever-HhAfJ"}},"style":{"stroke":"#555"},"className":"stroke-gray-900 stroke-connection","animated":false,"selected":false},{"source":"KalavaiDB-yi2jj","target":"VectorStoreRetriever-HhAfJ","sourceHandle":"{œbaseClassesœ:[œVectorStoreœ,œBaseRetrieverœ],œdataTypeœ:œKalavaiDBœ,œidœ:œKalavaiDB-yi2jjœ}","targetHandle":"{œfieldNameœ:œvectorstoreœ,œidœ:œVectorStoreRetriever-HhAfJœ,œinputTypesœ:null,œtypeœ:œVectorStoreœ}","id":"reactflow__edge-KalavaiDB-yi2jj{œbaseClassesœ:[œVectorStoreœ,œBaseRetrieverœ],œdataTypeœ:œKalavaiDBœ,œidœ:œKalavaiDB-yi2jjœ}-VectorStoreRetriever-HhAfJ{œfieldNameœ:œvectorstoreœ,œidœ:œVectorStoreRetriever-HhAfJœ,œinputTypesœ:null,œtypeœ:œVectorStoreœ}","data":{"targetHandle":{"fieldName":"vectorstore","id":"VectorStoreRetriever-HhAfJ","inputTypes":null,"type":"VectorStore"},"sourceHandle":{"baseClasses":["VectorStore","BaseRetriever"],"dataType":"KalavaiDB","id":"KalavaiDB-yi2jj"}},"style":{"stroke":"#555"},"className":"stroke-gray-900 stroke-connection","animated":false,"selected":false},{"source":"KalavaiEmbedding-u7wya","target":"KalavaiDB-yi2jj","sourceHandle":"{œbaseClassesœ:[œInfinityEmbeddingsœ,œEmbeddingsœ],œdataTypeœ:œKalavaiEmbeddingœ,œidœ:œKalavaiEmbedding-u7wyaœ}","targetHandle":"{œfieldNameœ:œembeddingœ,œidœ:œKalavaiDB-yi2jjœ,œinputTypesœ:null,œtypeœ:œEmbeddingsœ}","id":"reactflow__edge-KalavaiEmbedding-u7wya{œbaseClassesœ:[œInfinityEmbeddingsœ,œEmbeddingsœ],œdataTypeœ:œKalavaiEmbeddingœ,œidœ:œKalavaiEmbedding-u7wyaœ}-KalavaiDB-yi2jj{œfieldNameœ:œembeddingœ,œidœ:œKalavaiDB-yi2jjœ,œinputTypesœ:null,œtypeœ:œEmbeddingsœ}","data":{"targetHandle":{"fieldName":"embedding","id":"KalavaiDB-yi2jj","inputTypes":null,"type":"Embeddings"},"sourceHandle":{"baseClasses":["InfinityEmbeddings","Embeddings"],"dataType":"KalavaiEmbedding","id":"KalavaiEmbedding-u7wya"}},"style":{"stroke":"#555"},"className":"stroke-gray-900 stroke-connection","animated":false,"selected":false},{"source":"CombineDocsChain-RoWar","target":"RetrievalQA-JFfxD","sourceHandle":"{œbaseClassesœ:[œBaseCombineDocumentsChainœ,œCallableœ],œdataTypeœ:œCombineDocsChainœ,œidœ:œCombineDocsChain-RoWarœ}","targetHandle":"{œfieldNameœ:œcombine_documents_chainœ,œidœ:œRetrievalQA-JFfxDœ,œinputTypesœ:null,œtypeœ:œBaseCombineDocumentsChainœ}","id":"reactflow__edge-CombineDocsChain-RoWar{œbaseClassesœ:[œBaseCombineDocumentsChainœ,œCallableœ],œdataTypeœ:œCombineDocsChainœ,œidœ:œCombineDocsChain-RoWarœ}-RetrievalQA-JFfxD{œfieldNameœ:œcombine_documents_chainœ,œidœ:œRetrievalQA-JFfxDœ,œinputTypesœ:null,œtypeœ:œBaseCombineDocumentsChainœ}","data":{"targetHandle":{"fieldName":"combine_documents_chain","id":"RetrievalQA-JFfxD","inputTypes":null,"type":"BaseCombineDocumentsChain"},"sourceHandle":{"baseClasses":["BaseCombineDocumentsChain","Callable"],"dataType":"CombineDocsChain","id":"CombineDocsChain-RoWar"}},"style":{"stroke":"#555"},"className":"stroke-gray-900 stroke-connection","animated":false,"selected":false},{"source":"CharacterTextSplitter-o2vyX","target":"KalavaiDB-yi2jj","sourceHandle":"{œbaseClassesœ:[œDocumentœ],œdataTypeœ:œCharacterTextSplitterœ,œidœ:œCharacterTextSplitter-o2vyXœ}","targetHandle":"{œfieldNameœ:œdocumentsœ,œidœ:œKalavaiDB-yi2jjœ,œinputTypesœ:null,œtypeœ:œDocumentœ}","id":"reactflow__edge-CharacterTextSplitter-o2vyX{œbaseClassesœ:[œDocumentœ],œdataTypeœ:œCharacterTextSplitterœ,œidœ:œCharacterTextSplitter-o2vyXœ}-KalavaiDB-yi2jj{œfieldNameœ:œdocumentsœ,œidœ:œKalavaiDB-yi2jjœ,œinputTypesœ:null,œtypeœ:œDocumentœ}","data":{"targetHandle":{"fieldName":"documents","id":"KalavaiDB-yi2jj","inputTypes":null,"type":"Document"},"sourceHandle":{"baseClasses":["Document"],"dataType":"CharacterTextSplitter","id":"CharacterTextSplitter-o2vyX"}},"style":{"stroke":"#555"},"className":"stroke-gray-900 stroke-connection","animated":false,"selected":false},{"source":"UnstructuredMarkdownLoader-r2MFX","sourceHandle":"{œbaseClassesœ:[œDocumentœ],œdataTypeœ:œUnstructuredMarkdownLoaderœ,œidœ:œUnstructuredMarkdownLoader-r2MFXœ}","target":"CharacterTextSplitter-o2vyX","targetHandle":"{œfieldNameœ:œdocumentsœ,œidœ:œCharacterTextSplitter-o2vyXœ,œinputTypesœ:null,œtypeœ:œDocumentœ}","data":{"targetHandle":{"fieldName":"documents","id":"CharacterTextSplitter-o2vyX","inputTypes":null,"type":"Document"},"sourceHandle":{"baseClasses":["Document"],"dataType":"UnstructuredMarkdownLoader","id":"UnstructuredMarkdownLoader-r2MFX"}},"style":{"stroke":"#555"},"className":"stroke-foreground stroke-connection","animated":false,"id":"reactflow__edge-UnstructuredMarkdownLoader-r2MFX{œbaseClassesœ:[œDocumentœ],œdataTypeœ:œUnstructuredMarkdownLoaderœ,œidœ:œUnstructuredMarkdownLoader-r2MFXœ}-CharacterTextSplitter-o2vyX{œfieldNameœ:œdocumentsœ,œidœ:œCharacterTextSplitter-o2vyXœ,œinputTypesœ:null,œtypeœ:œDocumentœ}"}],"viewport":{"x":318.3413156326185,"y":66.89379175482227,"zoom":0.4537595776585801}},"description":"Build Retrieval Augmented Question Answering on the Kalavai Network","name":"Basic RAG Example","last_tested_version":"0.6.19","is_component":false} \ No newline at end of file diff --git a/images/deploy/d_1.png b/images/deploy/d_1.png new file mode 100644 index 0000000..1d628af Binary files /dev/null and b/images/deploy/d_1.png differ diff --git a/images/deploy/d_11.png b/images/deploy/d_11.png new file mode 100644 index 0000000..9cbc3ee Binary files /dev/null and b/images/deploy/d_11.png differ diff --git a/images/deploy/d_12.png b/images/deploy/d_12.png new file mode 100644 index 0000000..fa5bdbd Binary files /dev/null and b/images/deploy/d_12.png differ diff --git a/images/deploy/d_13.png b/images/deploy/d_13.png new file mode 100644 index 0000000..7abc141 Binary files /dev/null and b/images/deploy/d_13.png differ diff --git a/images/deploy/d_14.png b/images/deploy/d_14.png new file mode 100644 index 0000000..87c8995 Binary files /dev/null and b/images/deploy/d_14.png differ diff --git a/images/deploy/d_15.png b/images/deploy/d_15.png new file mode 100644 index 0000000..ea7f668 Binary files /dev/null and b/images/deploy/d_15.png differ diff --git a/images/deploy/d_2.png b/images/deploy/d_2.png new file mode 100644 index 0000000..3ffba3c Binary files /dev/null and b/images/deploy/d_2.png differ diff --git a/images/deploy/d_3.png b/images/deploy/d_3.png new file mode 100644 index 0000000..fed5a59 Binary files /dev/null and b/images/deploy/d_3.png differ diff --git a/images/deploy/d_4.png b/images/deploy/d_4.png new file mode 100644 index 0000000..9a7e4e1 Binary files /dev/null and b/images/deploy/d_4.png differ diff --git a/images/deploy/d_5.png b/images/deploy/d_5.png new file mode 100644 index 0000000..a2e23a4 Binary files /dev/null and b/images/deploy/d_5.png differ diff --git a/images/deploy/d_6.png b/images/deploy/d_6.png new file mode 100644 index 0000000..4fd7cb7 Binary files /dev/null and b/images/deploy/d_6.png differ diff --git a/images/deploy/d_7.png b/images/deploy/d_7.png new file mode 100644 index 0000000..016ec12 Binary files /dev/null and b/images/deploy/d_7.png differ diff --git a/images/deploy/d_8.png b/images/deploy/d_8.png new file mode 100644 index 0000000..99c84a1 Binary files /dev/null and b/images/deploy/d_8.png differ diff --git a/images/deploy/d_9.png b/images/deploy/d_9.png new file mode 100644 index 0000000..33f9004 Binary files /dev/null and b/images/deploy/d_9.png differ diff --git a/notebooks/Call_Agent_Flow.ipynb b/notebooks/Call_Agent_Flow.ipynb new file mode 100644 index 0000000..a24cbde --- /dev/null +++ b/notebooks/Call_Agent_Flow.ipynb @@ -0,0 +1,97 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Call your Deployed Flows\n", + "\n", + "This is a notebook to show how to call your deployed flows using the `requests` library in raw python.\n" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [], + "source": [ + "import requests\n", + "from typing import Optional\n", + "\n", + "# Update this to the base URL of your endpoint, available in the Kalavai dashboard\n", + "BASE_API_URL = \"https://adam.playground.test.k8s.mvp.kalavai.net/api/v1/process\"\n", + "\n", + "# Update this to the flow ID you want to run\n", + "FLOW_ID = \"24073dfd-c66a-441c-8951-78588f0bd2d7\"\n", + "\n", + "# You can tweak the flow by adding a tweaks dictionary\n", + "# e.g {\"OpenAI-XXXXX\": {\"model_name\": \"gpt-4\"}}\n", + "TWEAKS = {\n", + " \"KalavaiLlm-UTSYC\": {},\n", + " \"RetrievalQA-JFfxD\": {},\n", + " \"CombineDocsChain-RoWar\": {},\n", + " \"VectorStoreRetriever-HhAfJ\": {},\n", + " \"KalavaiDB-yi2jj\": {},\n", + " \"KalavaiEmbedding-u7wya\": {},\n", + " \"CharacterTextSplitter-o2vyX\": {},\n", + " \"TextLoader-QZBao\": {}\n", + "}\n", + "\n", + "def run_flow(inputs: dict, flow_id: str, tweaks: Optional[dict] = None, api_key: Optional[str] = None) -> dict:\n", + " \"\"\"\n", + " Run a flow with a given message and optional tweaks.\n", + "\n", + " :param message: The message to send to the flow\n", + " :param flow_id: The ID of the flow to run\n", + " :param tweaks: Optional tweaks to customize the flow\n", + " :return: The JSON response from the flow\n", + " \"\"\"\n", + " api_url = f\"{BASE_API_URL}/{flow_id}\"\n", + "\n", + " payload = {\"inputs\": inputs}\n", + " headers = None\n", + " if tweaks:\n", + " payload[\"tweaks\"] = tweaks\n", + " if api_key:\n", + " headers = {\"x-api-key\": api_key}\n", + " response = requests.post(api_url, json=payload, headers=headers)\n", + " return response.json()\n", + "\n", + "# Setup any tweaks you want to apply to the flow\n", + "inputs = {\"query\":\"Hello\"}\n", + "\n", + "# Get this from the LANGFLOW repository, as shown in the Documentatuin\n", + "api_key = \"sk-...\"\n", + "r = run_flow(inputs, flow_id=FLOW_ID, tweaks=TWEAKS, api_key=api_key)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "agent", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.11.9" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +}