From 0a2ac9d291f71b4fa7c2d9a8734a9c041191ca69 Mon Sep 17 00:00:00 2001 From: merrygoround-of-life Date: Wed, 15 Nov 2023 16:39:20 +0900 Subject: [PATCH 1/3] Fix: Avoid fix_memory_inputs when langchain_object is instance of AgentExecutor --- src/backend/langflow/processing/process.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/backend/langflow/processing/process.py b/src/backend/langflow/processing/process.py index 4c96e2fde..978c834d0 100644 --- a/src/backend/langflow/processing/process.py +++ b/src/backend/langflow/processing/process.py @@ -1,5 +1,6 @@ import json from pathlib import Path +from langchain.agents import AgentExecutor from langchain.schema import AgentAction from langflow.interface.run import ( build_sorted_vertices, @@ -70,7 +71,11 @@ def get_result_and_thought(langchain_object: Any, inputs: dict): if hasattr(langchain_object, "return_intermediate_steps"): langchain_object.return_intermediate_steps = False - fix_memory_inputs(langchain_object) + try: + if not isinstance(langchain_object, AgentExecutor): + fix_memory_inputs(langchain_object) + except Exception as exc: + logger.error(f"Error fixing memory inputs: {exc}") try: output = langchain_object(inputs, return_only_outputs=True) From b7dc241f5ef623cc6ef7eab6d7f6b9fc7bbe4e20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Muhl?= Date: Tue, 21 Nov 2023 13:51:50 +0100 Subject: [PATCH 2/3] Fix components link in Readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 133f41a6c..3b9367577 100644 --- a/README.md +++ b/README.md @@ -143,7 +143,7 @@ Alternatively, click the **"Open in Cloud Shell"** button below to launch Google # 🎨 Creating Flows -Creating flows with Langflow is easy. Simply drag sidebar components onto the canvas and connect them together to create your pipeline. Langflow provides a range of [LangChain components](https://docs.langchain.com/docs/category/components) to choose from, including LLMs, prompt serializers, agents, and chains. +Creating flows with Langflow is easy. Simply drag sidebar components onto the canvas and connect them together to create your pipeline. Langflow provides a range of [LangChain components](https://python.langchain.com/docs/integrations/components) to choose from, including LLMs, prompt serializers, agents, and chains. Explore by editing prompt parameters, link chains and agents, track an agent's thought process, and export your flow. From 43fa592bdba13e4750167da1c45bf361a707de42 Mon Sep 17 00:00:00 2001 From: Johngdae Date: Thu, 23 Nov 2023 04:48:39 +0000 Subject: [PATCH 3/3] 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