From 0b2bc40862263ba83ed5e51f3d52b27a17813966 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Tue, 5 Dec 2023 11:48:40 -0300 Subject: [PATCH 1/4] The Anthropic component, did not work properly, so it was developed additionally. --- .../langflow/components/llms/AnthropicLLM.py | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 src/backend/langflow/components/llms/AnthropicLLM.py diff --git a/src/backend/langflow/components/llms/AnthropicLLM.py b/src/backend/langflow/components/llms/AnthropicLLM.py new file mode 100644 index 000000000..1f75ba39f --- /dev/null +++ b/src/backend/langflow/components/llms/AnthropicLLM.py @@ -0,0 +1,71 @@ +from typing import Optional +from langflow import CustomComponent +from langchain.chat_models.anthropic import ChatAnthropic +from langchain.llms.base import BaseLLM + + +class AnthropicLLM(CustomComponent): + display_name: str = "AnthropicLLM" + description: str = "Anthropic Chat&Completion large language models." + + def build_config(self): + return { + "model": { + "display_name": "Model Name", + "options": [ + "claude-2.1", + "claude-2.0", + "claude-instant-1.2", + "claude-instant-1" + # Add more models as needed + ], + "info": "https://python.langchain.com/docs/integrations/chat/anthropic", + "required": True, + "value": "claude-2.1", + }, + "anthropic_api_key": { + "display_name": "Anthropic API Key", + "required": True, + "password": True, + "info": "Your Anthropic API key.", + }, + "max_tokens": { + "display_name": "Max Tokens", + "field_type": "int", + "value": 256, + }, + "temperature": { + "display_name": "Temperature", + "field_type": "float", + "value": 0.7, + }, + "api_endpoint": { + "display_name": "API Endpoint", + "info": "Endpoint of the Anthropic API. Defaults to 'https://api.anthropic.com' if not specified.", + }, + "code": {"show": False}, + } + + def build( + self, + model: str, + anthropic_api_key: Optional[str] = None, + max_tokens: Optional[int] = None, + temperature: Optional[float] = None, + api_endpoint: Optional[str] = None, + ) -> BaseLLM: + # Set default API endpoint if not provided + if not api_endpoint: + api_endpoint = "https://api.anthropic.com" + + try: + output = ChatAnthropic( + model=model, + anthropic_api_key=anthropic_api_key, + max_tokens_to_sample=max_tokens, + temperature=temperature, + anthropic_api_url=api_endpoint, + ) + except Exception as e: + raise ValueError("Could not connect to Anthropic API.") from e + return output From 7fab127bb6f3a5861be14f7697a471d0f3eda45c Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Tue, 5 Dec 2023 11:49:46 -0300 Subject: [PATCH 2/4] Refactor import statements in process.py --- src/backend/langflow/processing/process.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/backend/langflow/processing/process.py b/src/backend/langflow/processing/process.py index c60b12fb0..ab3b7eca2 100644 --- a/src/backend/langflow/processing/process.py +++ b/src/backend/langflow/processing/process.py @@ -6,8 +6,11 @@ from langchain.chains.base import Chain from langchain.schema import AgentAction, Document from langchain.vectorstores.base import VectorStore from langflow.graph import Graph -from langflow.interface.run import (build_sorted_vertices, get_memory_key, - update_memory_keys) +from langflow.interface.run import ( + build_sorted_vertices, + get_memory_key, + update_memory_keys, +) from langflow.services.getters import get_session_service from loguru import logger from pydantic import BaseModel From 08582f234ca609ceb7df9620014f99cdd308961a Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Tue, 5 Dec 2023 11:50:07 -0300 Subject: [PATCH 3/4] Update version to 0.5.12 --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 14ecdd307..0e33e3f68 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "langflow" -version = "0.5.11" +version = "0.5.12" description = "A Python package with a built-in web application" authors = ["Logspace "] maintainers = [ From 79a20f3740bbd13f62b459cafc4e09a321b93b31 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Tue, 5 Dec 2023 11:59:06 -0300 Subject: [PATCH 4/4] Remove commented out code in config.yaml --- src/backend/langflow/config.yaml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/backend/langflow/config.yaml b/src/backend/langflow/config.yaml index 994c1621f..0f18d01a4 100644 --- a/src/backend/langflow/config.yaml +++ b/src/backend/langflow/config.yaml @@ -117,10 +117,10 @@ llms: documentation: "https://python.langchain.com/docs/modules/model_io/models/llms/integrations/ctransformers" Cohere: documentation: "https://python.langchain.com/docs/modules/model_io/models/llms/integrations/cohere" - Anthropic: - documentation: "" - ChatAnthropic: - documentation: "https://python.langchain.com/docs/modules/model_io/models/chat/integrations/anthropic" + # Anthropic: + # documentation: "" + # ChatAnthropic: + # documentation: "https://python.langchain.com/docs/modules/model_io/models/chat/integrations/anthropic" HuggingFaceHub: documentation: "https://python.langchain.com/docs/modules/model_io/models/llms/integrations/huggingface_hub" VertexAI: @@ -271,8 +271,8 @@ vectorstores: documentation: "https://python.langchain.com/docs/modules/data_connection/vectorstores/integrations/qdrant" Weaviate: documentation: "https://python.langchain.com/docs/modules/data_connection/vectorstores/integrations/weaviate" -# FAISS: -# documentation: "https://python.langchain.com/docs/modules/data_connection/vectorstores/integrations/faiss" + # FAISS: + # documentation: "https://python.langchain.com/docs/modules/data_connection/vectorstores/integrations/faiss" Pinecone: documentation: "https://python.langchain.com/docs/modules/data_connection/vectorstores/integrations/pinecone" SupabaseVectorStore: