feat: Update SQLModel dependency and improve UUID handling (#4891)

* Update sqlmodel dependency to version 0.0.20 in pyproject.toml

* Handle UUID conversion for message IDs in memory update logic

* Refactor Alembic migrations to use `sa.inspect` and update GUID to Uuid type

* refactor: Change flow_id parameter type from str to uuid.UUID in graph building functions

* refactor: Ensure UUID handling for flow_id and user_id across various services and models

* refactor: improve UUID handling and graph caching for compatibility with sqlmodel 0.0.20

* fix: update message assertion in component events test

* chore: update sqlmodel dependency to version 0.0.22 in uv.lock and pyproject.toml

* fix: enhance flow_id validation to ensure valid UUID format in MessageBase model

* fix: add error handling for cache directory cleanup

* refactor: improve flow_id type handling in message storage

* refactor: enhance flow_id handling in message functions to support UUID type

* refactor: integrate Properties into message creation in component event tests

* update test durations

* fix: correct flow_id parameter in database query

* refactor: update session_id and flow_id parameters to support UUID type across message handling functions and models

* fix: handle message data update in SQLModel update method

* refactor: improve flow_id assignment in message update method to enhance UUID handling
This commit is contained in:
Gabriel Luiz Freitas Almeida 2024-12-12 09:58:27 -03:00 • committed by GitHub
commit 3de42f4575
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
55 changed files with 1035 additions and 898 deletions

File diff suppressed because it is too large Load diff

View file

@ -8,17 +8,9 @@ from langflow.components.outputs import ChatOutput
from langflow.components.tools.calculator import CalculatorToolComponent
from langflow.graph import Graph
from langflow.schema.data import Data
from langflow.services.settings.feature_flags import FEATURE_FLAGS
from pydantic import BaseModel
@pytest.fixture
def _add_toolkit_output():
FEATURE_FLAGS.add_toolkit_output = True
yield
FEATURE_FLAGS.add_toolkit_output = False
async def test_component_tool():
calculator_component = CalculatorToolComponent()
component_toolkit = ComponentToolkit(component=calculator_component)
@ -43,7 +35,6 @@ async def test_component_tool():
@pytest.mark.api_key_required
@pytest.mark.usefixtures("_add_toolkit_output")
def test_component_tool_with_api_key():
chat_output = ChatOutput()
openai_llm = OpenAIModelComponent()

View file

@ -2,6 +2,7 @@ import asyncio
import time
from typing import Any
from unittest.mock import MagicMock
from uuid import uuid4
import pytest
from langflow.custom.custom_component.component import Component
@ -9,7 +10,7 @@ from langflow.events.event_manager import EventManager
from langflow.schema.content_block import ContentBlock
from langflow.schema.content_types import TextContent, ToolContent
from langflow.schema.message import Message
from langflow.schema.properties import Source
from langflow.schema.properties import Properties, Source
from langflow.template.field.base import Output
@ -52,11 +53,13 @@ async def test_component_message_sending():
component.set_event_manager(event_manager)
# Create a message
properties = Properties()
message = Message(
sender="test_sender",
session_id="test_session",
sender_name="test_sender_name",
content_blocks=[ContentBlock(title="Test Block", contents=[TextContent(type="text", text="Test message")])],
properties=properties,
)
# Send the message
@ -80,6 +83,7 @@ async def test_component_tool_output():
component.set_event_manager(event_manager)
# Create a message with tool content
properties = Properties()
message = Message(
sender="test_sender",
session_id="test_session",
@ -90,6 +94,7 @@ async def test_component_tool_output():
contents=[ToolContent(type="tool_use", name="test_tool", tool_input={"query": "test input"})],
)
],
properties=properties,
)
# Send the message
@ -210,7 +215,7 @@ async def test_component_streaming_message():
# Create a proper mock vertex with graph and flow_id
vertex = MagicMock()
mock_graph = MagicMock()
mock_graph.flow_id = "12345678-1234-5678-1234-567812345678" # Valid UUID string
mock_graph.flow_id = str(uuid4())
vertex.graph = mock_graph
component = ComponentForTesting(_vertex=vertex)
@ -227,11 +232,13 @@ async def test_component_streaming_message():
yield StreamChunk(chunk)
# Create a streaming message
properties = Properties()
message = Message(
sender="test_sender",
session_id="test_session",
sender_name="test_sender_name",
text=text_generator(),
properties=properties,
)
# Send the streaming message

View file

@ -6,6 +6,7 @@ from langchain_core.messages import AIMessage, HumanMessage
from langchain_core.prompts.chat import ChatPromptTemplate
from langflow.schema.message import Message
from langflow.utils.constants import MESSAGE_SENDER_AI, MESSAGE_SENDER_USER
from loguru import logger
from platformdirs import user_cache_dir
@ -176,4 +177,7 @@ def cleanup():
# Clean up the real cache directory after tests
cache_dir = Path(user_cache_dir("langflow"))
if cache_dir.exists():
shutil.rmtree(str(cache_dir))
try:
shutil.rmtree(str(cache_dir))
except OSError as exc:
logger.error(f"Error cleaning up cache directory: {exc}")