From 415bee73847e66b749ef3d2cb19cfc1720c5591d Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Tue, 27 Jun 2023 07:33:35 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20chore(base.py,=20constants.py,?= =?UTF-8?q?=20llms.py):=20add=20info=20field=20to=20TemplateField=20and=20?= =?UTF-8?q?OPENAI=5FAPI=5FBASE=5FINFO=20constant=20The=20`info`=20field=20?= =?UTF-8?q?is=20added=20to=20the=20`TemplateField`=20class=20to=20provide?= =?UTF-8?q?=20additional=20information=20about=20the=20field.=20The=20`OPE?= =?UTF-8?q?NAI=5FAPI=5FBASE=5FINFO`=20constant=20is=20added=20to=20the=20`?= =?UTF-8?q?constants.py`=20file=20to=20provide=20information=20about=20the?= =?UTF-8?q?=20base=20URL=20of=20the=20OpenAI=20API=20and=20how=20it=20can?= =?UTF-8?q?=20be=20changed=20to=20use=20other=20APIs=20like=20Prem=20and?= =?UTF-8?q?=20LocalAI.=20The=20`info`=20field=20is=20set=20to=20`OPENAI=5F?= =?UTF-8?q?API=5FBASE=5FINFO`=20for=20the=20`openai=5Fapi=5Fbase`=20field?= =?UTF-8?q?=20in=20the=20`LLMFrontendNode`=20class=20in=20`llms.py`.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backend/langflow/template/field/base.py | 1 + .../langflow/template/frontend_node/constants.py | 10 ++++++++++ src/backend/langflow/template/frontend_node/llms.py | 4 ++++ 3 files changed, 15 insertions(+) diff --git a/src/backend/langflow/template/field/base.py b/src/backend/langflow/template/field/base.py index a9c18ff63..fdfdca562 100644 --- a/src/backend/langflow/template/field/base.py +++ b/src/backend/langflow/template/field/base.py @@ -21,6 +21,7 @@ class TemplateFieldCreator(BaseModel, ABC): name: str = "" display_name: Optional[str] = None advanced: bool = False + info: Optional[str] = "" def to_dict(self): result = self.dict() diff --git a/src/backend/langflow/template/frontend_node/constants.py b/src/backend/langflow/template/frontend_node/constants.py index 20b8a0c61..ac2e400b3 100644 --- a/src/backend/langflow/template/frontend_node/constants.py +++ b/src/backend/langflow/template/frontend_node/constants.py @@ -32,3 +32,13 @@ You are a good listener and you can talk about anything. HUMAN_PROMPT = "{input}" QA_CHAIN_TYPES = ["stuff", "map_reduce", "map_rerank", "refine"] + + +# This variable is used to tell the user +# that it can be changed to use other APIs +# like Prem and LocalAI +OPENAI_API_BASE_INFO = """ +The base URL of the OpenAI API. Defaults to https://api.openai.com/v1. + +You can change this to use other APIs like Prem and LocalAI. +""" diff --git a/src/backend/langflow/template/frontend_node/llms.py b/src/backend/langflow/template/frontend_node/llms.py index 272e42c7f..65bffc303 100644 --- a/src/backend/langflow/template/frontend_node/llms.py +++ b/src/backend/langflow/template/frontend_node/llms.py @@ -2,6 +2,7 @@ from typing import Optional from langflow.template.field.base import TemplateField from langflow.template.frontend_node.base import FrontendNode +from langflow.template.frontend_node.constants import OPENAI_API_BASE_INFO class LLMFrontendNode(FrontendNode): @@ -15,6 +16,9 @@ class LLMFrontendNode(FrontendNode): if "key" not in field.name.lower() and "token" not in field.name.lower(): field.password = False + if field.name == "openai_api_base": + field.info = OPENAI_API_BASE_INFO + @staticmethod def format_azure_field(field: TemplateField): if field.name == "model_name":