fix: exception locations in component classes (#4087)
* fix exception locations in component classes * print cleanups * remove randomdbs * [autofix.ci] apply automated fixes --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
parent
f74b58f22a
commit
8aeb801d52
2 changed files with 44 additions and 45 deletions
|
|
@ -64,7 +64,7 @@ class AssistantsRun(ComponentWithCache):
|
||||||
|
|
||||||
def process_inputs(self) -> Message:
|
def process_inputs(self) -> Message:
|
||||||
patch(OpenAI())
|
patch(OpenAI())
|
||||||
try:
|
|
||||||
text = ""
|
text = ""
|
||||||
|
|
||||||
if self.thread_id is None:
|
if self.thread_id is None:
|
||||||
|
|
@ -79,7 +79,6 @@ class AssistantsRun(ComponentWithCache):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
def on_exception(self, exception: Exception) -> None:
|
def on_exception(self, exception: Exception) -> None:
|
||||||
print(f"Exception: {exception}")
|
|
||||||
raise exception
|
raise exception
|
||||||
|
|
||||||
event_handler = EventHandler()
|
event_handler = EventHandler()
|
||||||
|
|
@ -88,16 +87,6 @@ class AssistantsRun(ComponentWithCache):
|
||||||
assistant_id=self.assistant_id,
|
assistant_id=self.assistant_id,
|
||||||
event_handler=event_handler,
|
event_handler=event_handler,
|
||||||
) as stream:
|
) as stream:
|
||||||
# return stream.text_deltas
|
|
||||||
for part in stream.text_deltas:
|
for part in stream.text_deltas:
|
||||||
text += part
|
text += part
|
||||||
print(part)
|
|
||||||
return Message(text=text)
|
return Message(text=text)
|
||||||
except Exception as e:
|
|
||||||
print(e)
|
|
||||||
msg = f"Error running assistant: {e}"
|
|
||||||
raise AssistantsRunError(msg) from e
|
|
||||||
|
|
||||||
|
|
||||||
class AssistantsRunError(Exception):
|
|
||||||
"""AssistantsRun error"""
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,15 @@ from spider.spider import Spider
|
||||||
|
|
||||||
from langflow.base.langchain_utilities.spider_constants import MODES
|
from langflow.base.langchain_utilities.spider_constants import MODES
|
||||||
from langflow.custom import Component
|
from langflow.custom import Component
|
||||||
from langflow.io import BoolInput, DictInput, DropdownInput, IntInput, Output, SecretStrInput, StrInput
|
from langflow.io import (
|
||||||
|
BoolInput,
|
||||||
|
DictInput,
|
||||||
|
DropdownInput,
|
||||||
|
IntInput,
|
||||||
|
Output,
|
||||||
|
SecretStrInput,
|
||||||
|
StrInput,
|
||||||
|
)
|
||||||
from langflow.schema import Data
|
from langflow.schema import Data
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -103,7 +111,6 @@ class SpiderTool(Component):
|
||||||
}
|
}
|
||||||
|
|
||||||
app = Spider(api_key=self.spider_api_key)
|
app = Spider(api_key=self.spider_api_key)
|
||||||
try:
|
|
||||||
if self.mode == "scrape":
|
if self.mode == "scrape":
|
||||||
parameters["limit"] = 1
|
parameters["limit"] = 1
|
||||||
result = app.scrape_url(self.url, parameters)
|
result = app.scrape_url(self.url, parameters)
|
||||||
|
|
@ -112,16 +119,19 @@ class SpiderTool(Component):
|
||||||
else:
|
else:
|
||||||
msg = f"Invalid mode: {self.mode}. Must be 'scrape' or 'crawl'."
|
msg = f"Invalid mode: {self.mode}. Must be 'scrape' or 'crawl'."
|
||||||
raise ValueError(msg)
|
raise ValueError(msg)
|
||||||
except Exception as e:
|
|
||||||
msg = f"Error: {e}"
|
|
||||||
raise SpiderToolError(msg) from e
|
|
||||||
|
|
||||||
records = []
|
records = []
|
||||||
|
|
||||||
for record in result:
|
for record in result:
|
||||||
if self.metadata:
|
if self.metadata:
|
||||||
records.append(
|
records.append(
|
||||||
Data(data={"content": record["content"], "url": record["url"], "metadata": record["metadata"]})
|
Data(
|
||||||
|
data={
|
||||||
|
"content": record["content"],
|
||||||
|
"url": record["url"],
|
||||||
|
"metadata": record["metadata"],
|
||||||
|
}
|
||||||
|
)
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
records.append(Data(data={"content": record["content"], "url": record["url"]}))
|
records.append(Data(data={"content": record["content"], "url": record["url"]}))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue