Remove unused chat and prompt classes (#1474)
This commit is contained in:
parent
43b3b082a5
commit
109b5c8690
2 changed files with 0 additions and 92 deletions
|
|
@ -1,34 +0,0 @@
|
||||||
from typing import Any, Callable, Optional, Union
|
|
||||||
|
|
||||||
from langchain_core.prompts import PromptTemplate as LCPromptTemplate
|
|
||||||
from langflow.utils.prompt import GenericPromptTemplate
|
|
||||||
from llama_index.prompts import PromptTemplate as LIPromptTemplate
|
|
||||||
|
|
||||||
PromptTemplate = Union[LCPromptTemplate, LIPromptTemplate]
|
|
||||||
|
|
||||||
|
|
||||||
class ChatDefinition:
|
|
||||||
def __init__(
|
|
||||||
self,
|
|
||||||
func: Callable,
|
|
||||||
inputs: list[str],
|
|
||||||
output_key: Optional[str] = None,
|
|
||||||
prompt_template: Optional[PromptTemplate] = None,
|
|
||||||
):
|
|
||||||
self.func = func
|
|
||||||
self.input_keys = inputs
|
|
||||||
self.output_key = output_key
|
|
||||||
self.prompt_template = prompt_template
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def from_prompt_template(cls, prompt_template: PromptTemplate, func: Callable, output_key: Optional[str] = None):
|
|
||||||
prompt = GenericPromptTemplate(prompt_template)
|
|
||||||
return cls(
|
|
||||||
func=func,
|
|
||||||
inputs=prompt.input_keys,
|
|
||||||
output_key=output_key,
|
|
||||||
prompt_template=prompt_template,
|
|
||||||
)
|
|
||||||
|
|
||||||
def __call__(self, inputs: dict, callbacks: Optional[Any] = None) -> dict:
|
|
||||||
return self.func(inputs, callbacks)
|
|
||||||
|
|
@ -1,58 +0,0 @@
|
||||||
from typing import Any, Union
|
|
||||||
|
|
||||||
from langchain_core.prompts import PromptTemplate as LCPromptTemplate
|
|
||||||
from llama_index.prompts import PromptTemplate as LIPromptTemplate
|
|
||||||
|
|
||||||
PromptTemplateTypes = Union[LCPromptTemplate, LIPromptTemplate]
|
|
||||||
|
|
||||||
|
|
||||||
class GenericPromptTemplate:
|
|
||||||
def __init__(self, prompt_template: PromptTemplateTypes):
|
|
||||||
object.__setattr__(self, "prompt_template", prompt_template)
|
|
||||||
|
|
||||||
@property
|
|
||||||
def input_keys(self):
|
|
||||||
prompt_template = object.__getattribute__(self, "prompt_template")
|
|
||||||
if isinstance(prompt_template, LCPromptTemplate):
|
|
||||||
return prompt_template.input_variables
|
|
||||||
elif isinstance(prompt_template, LIPromptTemplate):
|
|
||||||
return prompt_template.template_vars
|
|
||||||
else:
|
|
||||||
raise TypeError(f"Unknown prompt template type {type(prompt_template)}")
|
|
||||||
|
|
||||||
def to_lc_prompt(self):
|
|
||||||
prompt_template = object.__getattribute__(self, "prompt_template")
|
|
||||||
if isinstance(prompt_template, LCPromptTemplate):
|
|
||||||
return prompt_template
|
|
||||||
elif isinstance(prompt_template, LIPromptTemplate):
|
|
||||||
return LCPromptTemplate.from_template(prompt_template.get_template())
|
|
||||||
else:
|
|
||||||
raise TypeError(f"Unknown prompt template type {type(prompt_template)}")
|
|
||||||
|
|
||||||
def to_li_prompt(self):
|
|
||||||
prompt_template = object.__getattribute__(self, "prompt_template")
|
|
||||||
if isinstance(prompt_template, LIPromptTemplate):
|
|
||||||
return prompt_template
|
|
||||||
elif isinstance(prompt_template, LCPromptTemplate):
|
|
||||||
return LIPromptTemplate(template=prompt_template.template)
|
|
||||||
else:
|
|
||||||
raise TypeError(f"Unknown prompt template type {type(prompt_template)}")
|
|
||||||
|
|
||||||
def __or__(self, other):
|
|
||||||
prompt_template = object.__getattribute__(self, "prompt_template")
|
|
||||||
if isinstance(prompt_template, LIPromptTemplate):
|
|
||||||
return self.to_lc_prompt() | other
|
|
||||||
else:
|
|
||||||
raise TypeError(f"Unknown prompt template type {type(other)}")
|
|
||||||
|
|
||||||
def __getattribute__(self, name: str) -> Any:
|
|
||||||
if name in {
|
|
||||||
"input_keys",
|
|
||||||
"to_lc_prompt",
|
|
||||||
"to_li_prompt",
|
|
||||||
"__or__",
|
|
||||||
"prompt_template",
|
|
||||||
}:
|
|
||||||
return object.__getattribute__(self, name)
|
|
||||||
prompt_template = object.__getattribute__(self, "prompt_template")
|
|
||||||
return getattr(prompt_template, name)
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue