commit
a808679b76
3 changed files with 28 additions and 6 deletions
|
|
@ -110,7 +110,7 @@ class ChatManager:
|
||||||
start_resp = ChatResponse(message=None, type="start", intermediate_steps="")
|
start_resp = ChatResponse(message=None, type="start", intermediate_steps="")
|
||||||
await self.send_json(client_id, start_resp)
|
await self.send_json(client_id, start_resp)
|
||||||
|
|
||||||
is_first_message = len(self.chat_history.get_history(client_id=client_id)) == 0
|
is_first_message = len(self.chat_history.get_history(client_id=client_id)) <= 1
|
||||||
# Generate result and thought
|
# Generate result and thought
|
||||||
try:
|
try:
|
||||||
logger.debug("Generating result and thought")
|
logger.debug("Generating result and thought")
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ class AgentNode(Node):
|
||||||
#! Cannot deepcopy VectorStore, VectorStoreRouter, or SQL agents
|
#! Cannot deepcopy VectorStore, VectorStoreRouter, or SQL agents
|
||||||
if self.node_type in ["VectorStoreAgent", "VectorStoreRouterAgent", "SQLAgent"]:
|
if self.node_type in ["VectorStoreAgent", "VectorStoreRouterAgent", "SQLAgent"]:
|
||||||
return self._built_object
|
return self._built_object
|
||||||
return deepcopy(self._built_object)
|
return self._built_object
|
||||||
|
|
||||||
|
|
||||||
class ToolNode(Node):
|
class ToolNode(Node):
|
||||||
|
|
@ -81,7 +81,7 @@ class PromptNode(Node):
|
||||||
self.params["input_variables"] = list(set(self.params["input_variables"]))
|
self.params["input_variables"] = list(set(self.params["input_variables"]))
|
||||||
|
|
||||||
self._build()
|
self._build()
|
||||||
return deepcopy(self._built_object)
|
return self._built_object
|
||||||
|
|
||||||
|
|
||||||
class ChainNode(Node):
|
class ChainNode(Node):
|
||||||
|
|
@ -105,13 +105,29 @@ class ChainNode(Node):
|
||||||
#! Cannot deepcopy SQLDatabaseChain
|
#! Cannot deepcopy SQLDatabaseChain
|
||||||
if self.node_type in ["SQLDatabaseChain"]:
|
if self.node_type in ["SQLDatabaseChain"]:
|
||||||
return self._built_object
|
return self._built_object
|
||||||
return deepcopy(self._built_object)
|
return self._built_object
|
||||||
|
|
||||||
|
|
||||||
class LLMNode(Node):
|
class LLMNode(Node):
|
||||||
|
built_node_type = None
|
||||||
|
class_built_object = None
|
||||||
|
|
||||||
def __init__(self, data: Dict):
|
def __init__(self, data: Dict):
|
||||||
super().__init__(data, base_type="llms")
|
super().__init__(data, base_type="llms")
|
||||||
|
|
||||||
|
def build(self, force: bool = False) -> Any:
|
||||||
|
# LLM is different because some models might take up too much memory
|
||||||
|
# or time to load. So we only load them when we need them.ß
|
||||||
|
if self.node_type == self.built_node_type:
|
||||||
|
return self.class_built_object
|
||||||
|
if not self._built or force:
|
||||||
|
self._build()
|
||||||
|
self.built_node_type = self.node_type
|
||||||
|
self.class_built_object = self._built_object
|
||||||
|
# Avoid deepcopying the LLM
|
||||||
|
# that are loaded from a file
|
||||||
|
return self._built_object
|
||||||
|
|
||||||
|
|
||||||
class ToolkitNode(Node):
|
class ToolkitNode(Node):
|
||||||
def __init__(self, data: Dict):
|
def __init__(self, data: Dict):
|
||||||
|
|
@ -132,7 +148,7 @@ class WrapperNode(Node):
|
||||||
if "headers" in self.params:
|
if "headers" in self.params:
|
||||||
self.params["headers"] = eval(self.params["headers"])
|
self.params["headers"] = eval(self.params["headers"])
|
||||||
self._build()
|
self._build()
|
||||||
return deepcopy(self._built_object)
|
return self._built_object
|
||||||
|
|
||||||
|
|
||||||
class DocumentLoaderNode(Node):
|
class DocumentLoaderNode(Node):
|
||||||
|
|
|
||||||
|
|
@ -134,7 +134,13 @@ def instantiate_documentloader(class_object, params):
|
||||||
|
|
||||||
|
|
||||||
def instantiate_textsplitter(class_object, params):
|
def instantiate_textsplitter(class_object, params):
|
||||||
documents = params.pop("documents")
|
try:
|
||||||
|
documents = params.pop("documents")
|
||||||
|
except KeyError as e:
|
||||||
|
raise ValueError(
|
||||||
|
"The source you provided did not load correctly or was empty."
|
||||||
|
"Try changing the chunk_size of the Text Splitter."
|
||||||
|
) from e
|
||||||
text_splitter = class_object(**params)
|
text_splitter = class_object(**params)
|
||||||
return text_splitter.split_documents(documents)
|
return text_splitter.split_documents(documents)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue