From a443d0aa835cd9e986c6745b2bce05a446443074 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Thu, 8 Jun 2023 18:14:03 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A8=20refactor(llms.py):=20extract=20f?= =?UTF-8?q?ormatting=20methods=20for=20Azure=20and=20Llama=20fields=20This?= =?UTF-8?q?=20commit=20extracts=20the=20formatting=20methods=20for=20Azure?= =?UTF-8?q?=20and=20Llama=20fields=20from=20the=20`format=5Ffield`=20metho?= =?UTF-8?q?d=20to=20improve=20readability=20and=20maintainability=20of=20t?= =?UTF-8?q?he=20code.=20The=20`format=5Fazure=5Ffield`=20method=20formats?= =?UTF-8?q?=20the=20fields=20for=20Azure,=20while=20the=20`format=5Fllama?= =?UTF-8?q?=5Ffield`=20method=20formats=20the=20fields=20for=20Llama.=20Th?= =?UTF-8?q?ese=20methods=20are=20called=20conditionally=20based=20on=20the?= =?UTF-8?q?=20name=20of=20the=20field.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../langflow/template/frontend_node/llms.py | 32 +++++++++++++++++-- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/src/backend/langflow/template/frontend_node/llms.py b/src/backend/langflow/template/frontend_node/llms.py index e2602d2d6..ac17cf8ed 100644 --- a/src/backend/langflow/template/frontend_node/llms.py +++ b/src/backend/langflow/template/frontend_node/llms.py @@ -12,12 +12,34 @@ class LLMFrontendNode(FrontendNode): field.name.title().replace("Openai", "OpenAI").replace("_", " ") ).replace("Api", "API") + @staticmethod + def format_azure_field(field: TemplateField): + if field.name == "model_name": + field.show = False # Azure uses deployment_name instead of model_name. + elif field.name == "openai_api_type": + field.show = False + field.password = False + field.value = "azure" + elif field.name == "openai_api_version": + field.password = False + field.value = "2023-03-15-preview" + + @staticmethod + def format_llama_field(field: TemplateField): + field.show = True + field.advanced = not field.required + @staticmethod def format_field(field: TemplateField, name: Optional[str] = None) -> None: display_names_dict = { "huggingfacehub_api_token": "HuggingFace Hub API Token", } FrontendNode.format_field(field, name) + LLMFrontendNode.format_openai_field(field) + if name and "azure" in name.lower(): + LLMFrontendNode.format_azure_field(field) + if name and "llama" in name.lower(): + LLMFrontendNode.format_llama_field(field) SHOW_FIELDS = ["repo_id"] if field.name in SHOW_FIELDS: field.show = True @@ -44,8 +66,12 @@ class LLMFrontendNode(FrontendNode): field.field_type = "code" field.advanced = True field.show = True - elif field.name in ["model_name", "temperature", "model_file", "model_type"]: + elif field.name in [ + "model_name", + "temperature", + "model_file", + "model_type", + "deployment_name", + ]: field.advanced = False field.show = True - - LLMFrontendNode.format_openai_field(field)