Skip to content

Commit

Permalink
fix: Refactor file reading and async task creation, fix return type i…
Browse files Browse the repository at this point in the history
…n vertex_builds model (langflow-ai#4273)
  • Loading branch information
ogabrielluiz authored Oct 31, 2024
1 parent 80db2b9 commit fab2d9a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
6 changes: 3 additions & 3 deletions src/backend/base/langflow/api/v1/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ async def build_vertices(
client_consumed_queue: asyncio.Queue,
event_manager: EventManager,
) -> None:
build_task = asyncio.create_task(asyncio.to_thread(asyncio.run, _build_vertex(vertex_id, graph, event_manager)))
build_task = asyncio.create_task(_build_vertex(vertex_id, graph, event_manager))
try:
await build_task
except asyncio.CancelledError as exc:
Expand Down Expand Up @@ -361,8 +361,8 @@ async def build_vertices(

async def event_generator(event_manager: EventManager, client_consumed_queue: asyncio.Queue) -> None:
if not data:
# using another thread since the DB query is I/O bound
vertices_task = asyncio.create_task(asyncio.to_thread(asyncio.run, build_graph_and_get_order()))
# using another task since the build_graph_and_get_order is now an async function
vertices_task = asyncio.create_task(build_graph_and_get_order())
try:
await vertices_task
except asyncio.CancelledError:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,16 @@ def read_file_content(self, file_path):
_file_path = Path(file_path)
if not _file_path.is_file():
return None
with _file_path.open(encoding="utf-8") as file:
# UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 3069: character maps to <undefined>
try:
try:
with _file_path.open(encoding="utf-8") as file:
# UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 3069:
# character maps to <undefined>
return file.read()
except UnicodeDecodeError:
# This is happening in Windows, so we need to open the file in binary mode
# The file is always just a python file, so we can safely read it as utf-8
with _file_path.open("rb") as f:
return f.read().decode("utf-8")
except UnicodeDecodeError:
# This is happening in Windows, so we need to open the file in binary mode
# The file is always just a python file, so we can safely read it as utf-8
with _file_path.open("rb") as f:
return f.read().decode("utf-8")

def get_files(self):
"""Walk through the directory path and return a list of all .py files."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def serialize_artifacts(self, data) -> dict:
return truncate_long_strings(data)

@field_serializer("params")
def serialize_params(self, data) -> dict:
def serialize_params(self, data) -> str:
return truncate_long_strings(data)


Expand Down

0 comments on commit fab2d9a

Please sign in to comment.