🔨 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:
parent
790d8b5669
commit
ae59104b3a
2 changed files with 2 additions and 21 deletions
|
|
@ -2,9 +2,10 @@ from abc import ABC, abstractmethod
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
from langflow.template.field.base import TemplateField
|
from langflow.template.field.base import TemplateField
|
||||||
|
from pydantic import BaseModel
|
||||||
|
|
||||||
|
|
||||||
class FieldFormatter(ABC):
|
class FieldFormatter(BaseModel, ABC):
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def format(self, field: TemplateField, name: Optional[str]) -> None:
|
def format(self, field: TemplateField, name: Optional[str]) -> None:
|
||||||
pass
|
pass
|
||||||
|
|
|
||||||
|
|
@ -48,24 +48,4 @@ def python_function(text: str) -> str:
|
||||||
return text
|
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"]
|
DIRECT_TYPES = ["str", "bool", "code", "int", "float", "Any", "prompt"]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue