🔨 refactor(formatter/base.py): make FieldFormatter inherit from pydantic.BaseModel for improved type checking

🔥 chore(constants.py): remove unused DEFAULT_CUSTOM_COMPONENT_CODE constant
The FieldFormatter class now inherits from pydantic.BaseModel, which allows for improved type checking and validation of the format method arguments. The unused DEFAULT_CUSTOM_COMPONENT_CODE constant has been removed to clean up the codebase.
This commit is contained in:
Gabriel Luiz Freitas Almeida 2023-07-07 00:41:35 -03:00
commit ae59104b3a
2 changed files with 2 additions and 21 deletions

View file

@ -2,9 +2,10 @@ from abc import ABC, abstractmethod
from typing import Optional
from langflow.template.field.base import TemplateField
from pydantic import BaseModel
class FieldFormatter(ABC):
class FieldFormatter(BaseModel, ABC):
@abstractmethod
def format(self, field: TemplateField, name: Optional[str]) -> None:
pass

View file

@ -48,24 +48,4 @@ def python_function(text: str) -> str:
return text
"""
DEFAULT_CUSTOM_COMPONENT_CODE = """
from langchain.llms import OpenAI
from langchain.chains import ConversationChain
from langchain.memory import ConversationBufferMemory
class MyPythonClass:
def my_conversation(self, openai_api_key):
llm = OpenAI(
openai_api_key=openai_api_key,
temperature=0
)
return ConversationChain(
llm=llm, verbose=True, memory=ConversationBufferMemory()
)
def build(self, openai_api_key: str) -> ConversationChain:
return self.my_conversation(openai_api_key)
"""
DIRECT_TYPES = ["str", "bool", "code", "int", "float", "Any", "prompt"]