From ece26b49c7bf8c54f86ebcca7a7e3b1e4fc50277 Mon Sep 17 00:00:00 2001 From: anovazzi1 Date: Fri, 16 Feb 2024 16:16:36 -0300 Subject: [PATCH] Add Cohere component to the project --- .../langflow/components/models/Cohere.py | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/backend/langflow/components/models/Cohere.py diff --git a/src/backend/langflow/components/models/Cohere.py b/src/backend/langflow/components/models/Cohere.py new file mode 100644 index 000000000..a232bb626 --- /dev/null +++ b/src/backend/langflow/components/models/Cohere.py @@ -0,0 +1,30 @@ +from langchain_community.chat_models.cohere import ChatCohere +from langflow import CustomComponent +from langflow.field_typing import Text + + +class CohereComponent(CustomComponent): + display_name = "Cohere" + description = "Cohere large language models." + documentation = "https://python.langchain.com/docs/modules/model_io/models/llms/integrations/cohere" + + def build_config(self): + return { + "cohere_api_key": {"display_name": "Cohere API Key", "type": "password", "password": True}, + "max_tokens": {"display_name": "Max Tokens", "default": 256, "type": "int", "show": True}, + "temperature": {"display_name": "Temperature", "default": 0.75, "type": "float", "show": True}, + "inputs": {"display_name": "Input"}, + } + + def build( + self, + cohere_api_key: str, + inputs: str, + max_tokens: int = 256, + temperature: float = 0.75, + ) -> Text: + output = ChatCohere(cohere_api_key=cohere_api_key, max_tokens=max_tokens, temperature=temperature) + message = output.invoke(inputs) + result = message.content if hasattr(message, "content") else message + self.status = result + return result