ref: Add ruff rules for naming (N) (#4187)
Add ruff rules for naming (N)
This commit is contained in:
parent
f430f98c5c
commit
bdb4106ac0
35 changed files with 159 additions and 162 deletions
|
|
@ -34,7 +34,7 @@ from langflow.api.v1.schemas import (
|
||||||
VerticesOrderResponse,
|
VerticesOrderResponse,
|
||||||
)
|
)
|
||||||
from langflow.events.event_manager import EventManager, create_default_event_manager
|
from langflow.events.event_manager import EventManager, create_default_event_manager
|
||||||
from langflow.exceptions.component import ComponentBuildException
|
from langflow.exceptions.component import ComponentBuildError
|
||||||
from langflow.graph.graph.base import Graph
|
from langflow.graph.graph.base import Graph
|
||||||
from langflow.graph.utils import log_vertex_build
|
from langflow.graph.utils import log_vertex_build
|
||||||
from langflow.schema.schema import OutputValue
|
from langflow.schema.schema import OutputValue
|
||||||
|
|
@ -117,9 +117,9 @@ async def retrieve_vertices_order(
|
||||||
background_tasks.add_task(
|
background_tasks.add_task(
|
||||||
telemetry_service.log_package_playground,
|
telemetry_service.log_package_playground,
|
||||||
PlaygroundPayload(
|
PlaygroundPayload(
|
||||||
playgroundSeconds=int(time.perf_counter() - start_time),
|
playground_seconds=int(time.perf_counter() - start_time),
|
||||||
playgroundComponentCount=components_count,
|
playground_component_count=components_count,
|
||||||
playgroundSuccess=True,
|
playground_success=True,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
return VerticesOrderResponse(ids=graph.first_layer, run_id=graph.run_id, vertices_to_run=vertices_to_run)
|
return VerticesOrderResponse(ids=graph.first_layer, run_id=graph.run_id, vertices_to_run=vertices_to_run)
|
||||||
|
|
@ -127,10 +127,10 @@ async def retrieve_vertices_order(
|
||||||
background_tasks.add_task(
|
background_tasks.add_task(
|
||||||
telemetry_service.log_package_playground,
|
telemetry_service.log_package_playground,
|
||||||
PlaygroundPayload(
|
PlaygroundPayload(
|
||||||
playgroundSeconds=int(time.perf_counter() - start_time),
|
playground_seconds=int(time.perf_counter() - start_time),
|
||||||
playgroundComponentCount=components_count,
|
playground_component_count=components_count,
|
||||||
playgroundSuccess=False,
|
playground_success=False,
|
||||||
playgroundErrorMessage=str(exc),
|
playground_error_message=str(exc),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
if "stream or streaming set to True" in str(exc):
|
if "stream or streaming set to True" in str(exc):
|
||||||
|
|
@ -188,19 +188,19 @@ async def build_flow(
|
||||||
background_tasks.add_task(
|
background_tasks.add_task(
|
||||||
telemetry_service.log_package_playground,
|
telemetry_service.log_package_playground,
|
||||||
PlaygroundPayload(
|
PlaygroundPayload(
|
||||||
playgroundSeconds=int(time.perf_counter() - start_time),
|
playground_seconds=int(time.perf_counter() - start_time),
|
||||||
playgroundComponentCount=components_count,
|
playground_component_count=components_count,
|
||||||
playgroundSuccess=True,
|
playground_success=True,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
background_tasks.add_task(
|
background_tasks.add_task(
|
||||||
telemetry_service.log_package_playground,
|
telemetry_service.log_package_playground,
|
||||||
PlaygroundPayload(
|
PlaygroundPayload(
|
||||||
playgroundSeconds=int(time.perf_counter() - start_time),
|
playground_seconds=int(time.perf_counter() - start_time),
|
||||||
playgroundComponentCount=components_count,
|
playground_component_count=components_count,
|
||||||
playgroundSuccess=False,
|
playground_success=False,
|
||||||
playgroundErrorMessage=str(exc),
|
playground_error_message=str(exc),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
if "stream or streaming set to True" in str(exc):
|
if "stream or streaming set to True" in str(exc):
|
||||||
|
|
@ -239,7 +239,7 @@ async def build_flow(
|
||||||
|
|
||||||
result_data_response = ResultDataResponse.model_validate(result_dict, from_attributes=True)
|
result_data_response = ResultDataResponse.model_validate(result_dict, from_attributes=True)
|
||||||
except Exception as exc: # noqa: BLE001
|
except Exception as exc: # noqa: BLE001
|
||||||
if isinstance(exc, ComponentBuildException):
|
if isinstance(exc, ComponentBuildError):
|
||||||
params = exc.message
|
params = exc.message
|
||||||
tb = exc.formatted_traceback
|
tb = exc.formatted_traceback
|
||||||
else:
|
else:
|
||||||
|
|
@ -301,20 +301,20 @@ async def build_flow(
|
||||||
background_tasks.add_task(
|
background_tasks.add_task(
|
||||||
telemetry_service.log_package_component,
|
telemetry_service.log_package_component,
|
||||||
ComponentPayload(
|
ComponentPayload(
|
||||||
componentName=vertex_id.split("-")[0],
|
component_name=vertex_id.split("-")[0],
|
||||||
componentSeconds=int(time.perf_counter() - start_time),
|
component_seconds=int(time.perf_counter() - start_time),
|
||||||
componentSuccess=valid,
|
component_success=valid,
|
||||||
componentErrorMessage=error_message,
|
component_error_message=error_message,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
background_tasks.add_task(
|
background_tasks.add_task(
|
||||||
telemetry_service.log_package_component,
|
telemetry_service.log_package_component,
|
||||||
ComponentPayload(
|
ComponentPayload(
|
||||||
componentName=vertex_id.split("-")[0],
|
component_name=vertex_id.split("-")[0],
|
||||||
componentSeconds=int(time.perf_counter() - start_time),
|
component_seconds=int(time.perf_counter() - start_time),
|
||||||
componentSuccess=False,
|
component_success=False,
|
||||||
componentErrorMessage=str(exc),
|
component_error_message=str(exc),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
logger.exception("Error building Component")
|
logger.exception("Error building Component")
|
||||||
|
|
@ -524,7 +524,7 @@ async def build_vertex(
|
||||||
top_level_vertices = graph.get_top_level_vertices(next_runnable_vertices)
|
top_level_vertices = graph.get_top_level_vertices(next_runnable_vertices)
|
||||||
result_data_response = ResultDataResponse.model_validate(result_dict, from_attributes=True)
|
result_data_response = ResultDataResponse.model_validate(result_dict, from_attributes=True)
|
||||||
except Exception as exc: # noqa: BLE001
|
except Exception as exc: # noqa: BLE001
|
||||||
if isinstance(exc, ComponentBuildException):
|
if isinstance(exc, ComponentBuildError):
|
||||||
params = exc.message
|
params = exc.message
|
||||||
tb = exc.formatted_traceback
|
tb = exc.formatted_traceback
|
||||||
else:
|
else:
|
||||||
|
|
@ -590,20 +590,20 @@ async def build_vertex(
|
||||||
background_tasks.add_task(
|
background_tasks.add_task(
|
||||||
telemetry_service.log_package_component,
|
telemetry_service.log_package_component,
|
||||||
ComponentPayload(
|
ComponentPayload(
|
||||||
componentName=vertex_id.split("-")[0],
|
component_name=vertex_id.split("-")[0],
|
||||||
componentSeconds=int(time.perf_counter() - start_time),
|
component_seconds=int(time.perf_counter() - start_time),
|
||||||
componentSuccess=valid,
|
component_success=valid,
|
||||||
componentErrorMessage=error_message,
|
component_error_message=error_message,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
background_tasks.add_task(
|
background_tasks.add_task(
|
||||||
telemetry_service.log_package_component,
|
telemetry_service.log_package_component,
|
||||||
ComponentPayload(
|
ComponentPayload(
|
||||||
componentName=vertex_id.split("-")[0],
|
component_name=vertex_id.split("-")[0],
|
||||||
componentSeconds=int(time.perf_counter() - start_time),
|
component_seconds=int(time.perf_counter() - start_time),
|
||||||
componentSuccess=False,
|
component_success=False,
|
||||||
componentErrorMessage=str(exc),
|
component_error_message=str(exc),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
logger.exception("Error building Component")
|
logger.exception("Error building Component")
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ from langflow.api.v1.schemas import (
|
||||||
)
|
)
|
||||||
from langflow.custom.custom_component.component import Component
|
from langflow.custom.custom_component.component import Component
|
||||||
from langflow.custom.utils import build_custom_component_template, get_instance_name
|
from langflow.custom.utils import build_custom_component_template, get_instance_name
|
||||||
from langflow.exceptions.api import APIException, InvalidChatInputException
|
from langflow.exceptions.api import APIException, InvalidChatInputError
|
||||||
from langflow.graph.graph.base import Graph
|
from langflow.graph.graph.base import Graph
|
||||||
from langflow.graph.schema import RunOutputs
|
from langflow.graph.schema import RunOutputs
|
||||||
from langflow.helpers.flow import get_flow_by_id_or_endpoint_name
|
from langflow.helpers.flow import get_flow_by_id_or_endpoint_name
|
||||||
|
|
@ -87,13 +87,13 @@ def validate_input_and_tweaks(input_request: SimplifiedAPIRequest):
|
||||||
input_value_is_chat = input_request.input_value is not None and input_request.input_type == "chat"
|
input_value_is_chat = input_request.input_value is not None and input_request.input_type == "chat"
|
||||||
if has_input_value and input_value_is_chat:
|
if has_input_value and input_value_is_chat:
|
||||||
msg = "If you pass an input_value to the chat input, you cannot pass a tweak with the same name."
|
msg = "If you pass an input_value to the chat input, you cannot pass a tweak with the same name."
|
||||||
raise InvalidChatInputException(msg)
|
raise InvalidChatInputError(msg)
|
||||||
elif ("Text Input" in key or "TextInput" in key) and isinstance(value, dict):
|
elif ("Text Input" in key or "TextInput" in key) and isinstance(value, dict):
|
||||||
has_input_value = value.get("input_value") is not None
|
has_input_value = value.get("input_value") is not None
|
||||||
input_value_is_text = input_request.input_value is not None and input_request.input_type == "text"
|
input_value_is_text = input_request.input_value is not None and input_request.input_type == "text"
|
||||||
if has_input_value and input_value_is_text:
|
if has_input_value and input_value_is_text:
|
||||||
msg = "If you pass an input_value to the text input, you cannot pass a tweak with the same name."
|
msg = "If you pass an input_value to the text input, you cannot pass a tweak with the same name."
|
||||||
raise InvalidChatInputException(msg)
|
raise InvalidChatInputError(msg)
|
||||||
|
|
||||||
|
|
||||||
async def simple_run_flow(
|
async def simple_run_flow(
|
||||||
|
|
@ -253,17 +253,19 @@ async def simplified_run_flow(
|
||||||
end_time = time.perf_counter()
|
end_time = time.perf_counter()
|
||||||
background_tasks.add_task(
|
background_tasks.add_task(
|
||||||
telemetry_service.log_package_run,
|
telemetry_service.log_package_run,
|
||||||
RunPayload(runIsWebhook=False, runSeconds=int(end_time - start_time), runSuccess=True, runErrorMessage=""),
|
RunPayload(
|
||||||
|
run_is_webhook=False, run_seconds=int(end_time - start_time), run_success=True, run_error_message=""
|
||||||
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
except ValueError as exc:
|
except ValueError as exc:
|
||||||
background_tasks.add_task(
|
background_tasks.add_task(
|
||||||
telemetry_service.log_package_run,
|
telemetry_service.log_package_run,
|
||||||
RunPayload(
|
RunPayload(
|
||||||
runIsWebhook=False,
|
run_is_webhook=False,
|
||||||
runSeconds=int(time.perf_counter() - start_time),
|
run_seconds=int(time.perf_counter() - start_time),
|
||||||
runSuccess=False,
|
run_success=False,
|
||||||
runErrorMessage=str(exc),
|
run_error_message=str(exc),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
if "badly formed hexadecimal UUID string" in str(exc):
|
if "badly formed hexadecimal UUID string" in str(exc):
|
||||||
|
|
@ -272,16 +274,16 @@ async def simplified_run_flow(
|
||||||
if "not found" in str(exc):
|
if "not found" in str(exc):
|
||||||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail=str(exc)) from exc
|
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail=str(exc)) from exc
|
||||||
raise APIException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, exception=exc, flow=flow) from exc
|
raise APIException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, exception=exc, flow=flow) from exc
|
||||||
except InvalidChatInputException as exc:
|
except InvalidChatInputError as exc:
|
||||||
raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail=str(exc)) from exc
|
raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail=str(exc)) from exc
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
background_tasks.add_task(
|
background_tasks.add_task(
|
||||||
telemetry_service.log_package_run,
|
telemetry_service.log_package_run,
|
||||||
RunPayload(
|
RunPayload(
|
||||||
runIsWebhook=False,
|
run_is_webhook=False,
|
||||||
runSeconds=int(time.perf_counter() - start_time),
|
run_seconds=int(time.perf_counter() - start_time),
|
||||||
runSuccess=False,
|
run_success=False,
|
||||||
runErrorMessage=str(exc),
|
run_error_message=str(exc),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
raise APIException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, exception=exc, flow=flow) from exc
|
raise APIException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, exception=exc, flow=flow) from exc
|
||||||
|
|
@ -355,10 +357,10 @@ async def webhook_run_flow(
|
||||||
background_tasks.add_task(
|
background_tasks.add_task(
|
||||||
telemetry_service.log_package_run,
|
telemetry_service.log_package_run,
|
||||||
RunPayload(
|
RunPayload(
|
||||||
runIsWebhook=True,
|
run_is_webhook=True,
|
||||||
runSeconds=int(time.perf_counter() - start_time),
|
run_seconds=int(time.perf_counter() - start_time),
|
||||||
runSuccess=error_msg == "",
|
run_success=error_msg == "",
|
||||||
runErrorMessage=error_msg,
|
run_error_message=error_msg,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -548,7 +550,7 @@ async def create_upload_file(
|
||||||
file_path = save_uploaded_file(file, folder_name=flow_id_str)
|
file_path = save_uploaded_file(file, folder_name=flow_id_str)
|
||||||
|
|
||||||
return UploadFileResponse(
|
return UploadFileResponse(
|
||||||
flowId=flow_id_str,
|
flow_id=flow_id_str,
|
||||||
file_path=file_path,
|
file_path=file_path,
|
||||||
)
|
)
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
|
|
|
||||||
|
|
@ -71,7 +71,7 @@ async def upload_file(
|
||||||
full_file_name = f"{timestamp}_{file_name}"
|
full_file_name = f"{timestamp}_{file_name}"
|
||||||
folder = flow_id_str
|
folder = flow_id_str
|
||||||
await storage_service.save_file(flow_id=folder, file_name=full_file_name, data=file_content)
|
await storage_service.save_file(flow_id=folder, file_name=full_file_name, data=file_content)
|
||||||
return UploadFileResponse(flowId=flow_id_str, file_path=f"{folder}/{full_file_name}")
|
return UploadFileResponse(flow_id=flow_id_str, file_path=f"{folder}/{full_file_name}")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise HTTPException(status_code=500, detail=str(e)) from e
|
raise HTTPException(status_code=500, detail=str(e)) from e
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -93,7 +93,7 @@ class ChatMessage(BaseModel):
|
||||||
|
|
||||||
is_bot: bool = False
|
is_bot: bool = False
|
||||||
message: str | None | dict = None
|
message: str | None | dict = None
|
||||||
chatKey: str | None = None
|
chat_key: str | None = Field(None, serialization_alias="chatKey")
|
||||||
type: str = "human"
|
type: str = "human"
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -159,7 +159,7 @@ class FlowListReadWithFolderName(BaseModel):
|
||||||
|
|
||||||
|
|
||||||
class InitResponse(BaseModel):
|
class InitResponse(BaseModel):
|
||||||
flowId: str
|
flow_id: str = Field(serialization_alias="flowId")
|
||||||
|
|
||||||
|
|
||||||
class BuiltResponse(BaseModel):
|
class BuiltResponse(BaseModel):
|
||||||
|
|
@ -169,7 +169,7 @@ class BuiltResponse(BaseModel):
|
||||||
class UploadFileResponse(BaseModel):
|
class UploadFileResponse(BaseModel):
|
||||||
"""Upload file response schema."""
|
"""Upload file response schema."""
|
||||||
|
|
||||||
flowId: str
|
flow_id: str = Field(serialization_alias="flowId")
|
||||||
file_path: Path
|
file_path: Path
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ from langflow.api.utils import check_langflow_version
|
||||||
from langflow.services.auth import utils as auth_utils
|
from langflow.services.auth import utils as auth_utils
|
||||||
from langflow.services.database.models.user.model import User
|
from langflow.services.database.models.user.model import User
|
||||||
from langflow.services.deps import get_settings_service, get_store_service
|
from langflow.services.deps import get_settings_service, get_store_service
|
||||||
from langflow.services.store.exceptions import CustomException
|
from langflow.services.store.exceptions import CustomError
|
||||||
from langflow.services.store.schema import (
|
from langflow.services.store.schema import (
|
||||||
CreateComponentResponse,
|
CreateComponentResponse,
|
||||||
DownloadComponentResponse,
|
DownloadComponentResponse,
|
||||||
|
|
@ -131,7 +131,7 @@ async def get_components(
|
||||||
limit=limit,
|
limit=limit,
|
||||||
store_api_key=store_api_key,
|
store_api_key=store_api_key,
|
||||||
)
|
)
|
||||||
except CustomException as exc:
|
except CustomError as exc:
|
||||||
raise HTTPException(status_code=exc.status_code, detail=str(exc)) from exc
|
raise HTTPException(status_code=exc.status_code, detail=str(exc)) from exc
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
raise HTTPException(status_code=500, detail=str(exc)) from exc
|
raise HTTPException(status_code=500, detail=str(exc)) from exc
|
||||||
|
|
@ -145,7 +145,7 @@ async def download_component(
|
||||||
):
|
):
|
||||||
try:
|
try:
|
||||||
component = await store_service.download(store_api_key, component_id)
|
component = await store_service.download(store_api_key, component_id)
|
||||||
except CustomException as exc:
|
except CustomError as exc:
|
||||||
raise HTTPException(status_code=400, detail=str(exc)) from exc
|
raise HTTPException(status_code=400, detail=str(exc)) from exc
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
raise HTTPException(status_code=500, detail=str(exc)) from exc
|
raise HTTPException(status_code=500, detail=str(exc)) from exc
|
||||||
|
|
@ -162,7 +162,7 @@ async def get_tags(
|
||||||
):
|
):
|
||||||
try:
|
try:
|
||||||
return await store_service.get_tags()
|
return await store_service.get_tags()
|
||||||
except CustomException as exc:
|
except CustomError as exc:
|
||||||
raise HTTPException(status_code=400, detail=str(exc)) from exc
|
raise HTTPException(status_code=400, detail=str(exc)) from exc
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
raise HTTPException(status_code=500, detail=str(exc)) from exc
|
raise HTTPException(status_code=500, detail=str(exc)) from exc
|
||||||
|
|
@ -175,7 +175,7 @@ async def get_list_of_components_liked_by_user(
|
||||||
):
|
):
|
||||||
try:
|
try:
|
||||||
return await store_service.get_user_likes(store_api_key)
|
return await store_service.get_user_likes(store_api_key)
|
||||||
except CustomException as exc:
|
except CustomError as exc:
|
||||||
raise HTTPException(status_code=400, detail=str(exc)) from exc
|
raise HTTPException(status_code=400, detail=str(exc)) from exc
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
raise HTTPException(status_code=500, detail=str(exc)) from exc
|
raise HTTPException(status_code=500, detail=str(exc)) from exc
|
||||||
|
|
@ -192,7 +192,7 @@ async def like_component(
|
||||||
likes_count = await store_service.get_component_likes_count(str(component_id), store_api_key)
|
likes_count = await store_service.get_component_likes_count(str(component_id), store_api_key)
|
||||||
|
|
||||||
return UsersLikesResponse(likes_count=likes_count, liked_by_user=result)
|
return UsersLikesResponse(likes_count=likes_count, liked_by_user=result)
|
||||||
except CustomException as exc:
|
except CustomError as exc:
|
||||||
raise HTTPException(status_code=exc.status_code, detail=str(exc)) from exc
|
raise HTTPException(status_code=exc.status_code, detail=str(exc)) from exc
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
raise HTTPException(status_code=500, detail=str(exc)) from exc
|
raise HTTPException(status_code=500, detail=str(exc)) from exc
|
||||||
|
|
|
||||||
|
|
@ -50,8 +50,8 @@ class FirecrawlCrawlApi(CustomComponent):
|
||||||
api_key: str,
|
api_key: str,
|
||||||
url: str,
|
url: str,
|
||||||
timeout: int = 30000,
|
timeout: int = 30000,
|
||||||
crawlerOptions: Data | None = None,
|
crawlerOptions: Data | None = None, # noqa: N803
|
||||||
pageOptions: Data | None = None,
|
pageOptions: Data | None = None, # noqa: N803
|
||||||
idempotency_key: str | None = None,
|
idempotency_key: str | None = None,
|
||||||
) -> Data:
|
) -> Data:
|
||||||
try:
|
try:
|
||||||
|
|
|
||||||
|
|
@ -44,8 +44,8 @@ class FirecrawlScrapeApi(CustomComponent):
|
||||||
api_key: str,
|
api_key: str,
|
||||||
url: str,
|
url: str,
|
||||||
timeout: int = 10000,
|
timeout: int = 10000,
|
||||||
pageOptions: Data | None = None,
|
pageOptions: Data | None = None, # noqa: N803
|
||||||
extractorOptions: Data | None = None,
|
extractorOptions: Data | None = None, # noqa: N803
|
||||||
) -> Data:
|
) -> Data:
|
||||||
try:
|
try:
|
||||||
from firecrawl.firecrawl import FirecrawlApp
|
from firecrawl.firecrawl import FirecrawlApp
|
||||||
|
|
|
||||||
|
|
@ -89,7 +89,7 @@ class AstraDBCQLToolComponent(LCToolComponent):
|
||||||
|
|
||||||
def astra_rest(self, args):
|
def astra_rest(self, args):
|
||||||
headers = {"Accept": "application/json", "X-Cassandra-Token": f"{self.token}"}
|
headers = {"Accept": "application/json", "X-Cassandra-Token": f"{self.token}"}
|
||||||
ASTRA_URL = f"{self.api_endpoint}/api/rest/v2/keyspaces/{self.keyspace}/{self.table_name}/"
|
astra_url = f"{self.api_endpoint}/api/rest/v2/keyspaces/{self.keyspace}/{self.table_name}/"
|
||||||
key = []
|
key = []
|
||||||
# Partition keys are mandatory
|
# Partition keys are mandatory
|
||||||
for k in self.partition_keys:
|
for k in self.partition_keys:
|
||||||
|
|
@ -108,7 +108,7 @@ class AstraDBCQLToolComponent(LCToolComponent):
|
||||||
elif self.static_filters[k] is not None:
|
elif self.static_filters[k] is not None:
|
||||||
key.append(self.static_filters[k])
|
key.append(self.static_filters[k])
|
||||||
|
|
||||||
url = f'{ASTRA_URL}{"/".join(key)}?page-size={self.number_of_results}'
|
url = f'{astra_url}{"/".join(key)}?page-size={self.number_of_results}'
|
||||||
|
|
||||||
if self.projection_fields != "*":
|
if self.projection_fields != "*":
|
||||||
url += f'&fields={urllib.parse.quote(self.projection_fields.replace(" ","")) }'
|
url += f'&fields={urllib.parse.quote(self.projection_fields.replace(" ","")) }'
|
||||||
|
|
|
||||||
|
|
@ -198,13 +198,13 @@ class PythonCodeStructuredTool(LCToolComponent):
|
||||||
if "temp_annotation_type" in _globals:
|
if "temp_annotation_type" in _globals:
|
||||||
_globals.pop("temp_annotation_type")
|
_globals.pop("temp_annotation_type")
|
||||||
|
|
||||||
PythonCodeToolSchema = None
|
python_code_tool_schema = None
|
||||||
if schema_fields:
|
if schema_fields:
|
||||||
PythonCodeToolSchema = create_model("PythonCodeToolSchema", **schema_fields)
|
python_code_tool_schema = create_model("PythonCodeToolSchema", **schema_fields)
|
||||||
|
|
||||||
return StructuredTool.from_function(
|
return StructuredTool.from_function(
|
||||||
func=_local[self.tool_function].run,
|
func=_local[self.tool_function].run,
|
||||||
args_schema=PythonCodeToolSchema,
|
args_schema=python_code_tool_schema,
|
||||||
name=self.tool_name,
|
name=self.tool_name,
|
||||||
description=self.tool_description,
|
description=self.tool_description,
|
||||||
return_direct=self.return_direct,
|
return_direct=self.return_direct,
|
||||||
|
|
|
||||||
|
|
@ -129,11 +129,11 @@ class SearXNGToolComponent(LCToolComponent):
|
||||||
"categories": (list[str], Field(default=[], description="The categories to search in.")),
|
"categories": (list[str], Field(default=[], description="The categories to search in.")),
|
||||||
}
|
}
|
||||||
|
|
||||||
SearxSearchSchema = create_model("SearxSearchSchema", **schema_fields)
|
searx_search_schema = create_model("SearxSearchSchema", **schema_fields)
|
||||||
|
|
||||||
return StructuredTool.from_function(
|
return StructuredTool.from_function(
|
||||||
func=_local["SearxSearch"].search,
|
func=_local["SearxSearch"].search,
|
||||||
args_schema=SearxSearchSchema,
|
args_schema=searx_search_schema,
|
||||||
name="searxng_search_tool",
|
name="searxng_search_tool",
|
||||||
description="A tool that searches for tools using SearXNG.\nThe available categories are: "
|
description="A tool that searches for tools using SearXNG.\nThe available categories are: "
|
||||||
+ ", ".join(self.categories),
|
+ ", ".join(self.categories),
|
||||||
|
|
|
||||||
|
|
@ -801,8 +801,8 @@ class Component(CustomComponent):
|
||||||
return Input(**kwargs)
|
return Input(**kwargs)
|
||||||
|
|
||||||
def to_toolkit(self) -> list[Tool]:
|
def to_toolkit(self) -> list[Tool]:
|
||||||
ComponentToolkit = _get_component_toolkit()
|
component_toolkit = _get_component_toolkit()
|
||||||
return ComponentToolkit(component=self).get_tools()
|
return component_toolkit(component=self).get_tools()
|
||||||
|
|
||||||
def get_project_name(self):
|
def get_project_name(self):
|
||||||
if hasattr(self, "_tracing_service") and self._tracing_service:
|
if hasattr(self, "_tracing_service") and self._tracing_service:
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,14 @@
|
||||||
import ast
|
import ast
|
||||||
|
|
||||||
|
from typing_extensions import override
|
||||||
|
|
||||||
|
|
||||||
class RequiredInputsVisitor(ast.NodeVisitor):
|
class RequiredInputsVisitor(ast.NodeVisitor):
|
||||||
def __init__(self, inputs):
|
def __init__(self, inputs):
|
||||||
self.inputs = inputs
|
self.inputs = inputs
|
||||||
self.required_inputs = set()
|
self.required_inputs = set()
|
||||||
|
|
||||||
|
@override
|
||||||
def visit_Attribute(self, node):
|
def visit_Attribute(self, node):
|
||||||
if isinstance(node.value, ast.Name) and node.value.id == "self" and node.attr in self.inputs:
|
if isinstance(node.value, ast.Name) and node.value.id == "self" and node.attr in self.inputs:
|
||||||
self.required_inputs.add(node.attr)
|
self.required_inputs.add(node.attr)
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ from langflow.services.database.models.flow.model import Flow
|
||||||
from langflow.services.database.models.flow.utils import get_outdated_components
|
from langflow.services.database.models.flow.utils import get_outdated_components
|
||||||
|
|
||||||
|
|
||||||
class InvalidChatInputException(Exception):
|
class InvalidChatInputError(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
# Create an exception class that receives the message and the formatted traceback
|
# Create an exception class that receives the message and the formatted traceback
|
||||||
class ComponentBuildException(Exception):
|
class ComponentBuildError(Exception):
|
||||||
def __init__(self, message: str, formatted_traceback: str):
|
def __init__(self, message: str, formatted_traceback: str):
|
||||||
self.message = message
|
self.message = message
|
||||||
self.formatted_traceback = formatted_traceback
|
self.formatted_traceback = formatted_traceback
|
||||||
|
|
|
||||||
|
|
@ -138,22 +138,22 @@ def draw_graph(vertexes, edges, *, return_ascii=True):
|
||||||
"""Build a DAG and draw it in ASCII."""
|
"""Build a DAG and draw it in ASCII."""
|
||||||
sug = build_sugiyama_layout(vertexes, edges)
|
sug = build_sugiyama_layout(vertexes, edges)
|
||||||
|
|
||||||
Xs = []
|
xlist = []
|
||||||
Ys = []
|
ylist = []
|
||||||
|
|
||||||
for vertex in sug.g.sV:
|
for vertex in sug.g.sV:
|
||||||
Xs.extend([vertex.view.xy[0] - vertex.view.w / 2.0, vertex.view.xy[0] + vertex.view.w / 2.0])
|
xlist.extend([vertex.view.xy[0] - vertex.view.w / 2.0, vertex.view.xy[0] + vertex.view.w / 2.0])
|
||||||
Ys.extend([vertex.view.xy[1], vertex.view.xy[1] + vertex.view.h])
|
ylist.extend([vertex.view.xy[1], vertex.view.xy[1] + vertex.view.h])
|
||||||
|
|
||||||
for edge in sug.g.sE:
|
for edge in sug.g.sE:
|
||||||
for x, y in edge.view._pts:
|
for x, y in edge.view._pts:
|
||||||
Xs.append(x)
|
xlist.append(x)
|
||||||
Ys.append(y)
|
ylist.append(y)
|
||||||
|
|
||||||
minx = min(Xs)
|
minx = min(xlist)
|
||||||
miny = min(Ys)
|
miny = min(ylist)
|
||||||
maxx = max(Xs)
|
maxx = max(xlist)
|
||||||
maxy = max(Ys)
|
maxy = max(ylist)
|
||||||
|
|
||||||
canvas_cols = int(math.ceil(maxx - minx)) + 1
|
canvas_cols = int(math.ceil(maxx - minx)) + 1
|
||||||
canvas_lines = int(round(maxy - miny))
|
canvas_lines = int(round(maxy - miny))
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ from typing import TYPE_CHECKING, Any, cast
|
||||||
import nest_asyncio
|
import nest_asyncio
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
|
|
||||||
from langflow.exceptions.component import ComponentBuildException
|
from langflow.exceptions.component import ComponentBuildError
|
||||||
from langflow.graph.edge.base import CycleEdge, Edge
|
from langflow.graph.edge.base import CycleEdge, Edge
|
||||||
from langflow.graph.graph.constants import Finish, lazy_load_vertex_dict
|
from langflow.graph.graph.constants import Finish, lazy_load_vertex_dict
|
||||||
from langflow.graph.graph.runnable_vertices_manager import RunnableVerticesManager
|
from langflow.graph.graph.runnable_vertices_manager import RunnableVerticesManager
|
||||||
|
|
@ -1394,7 +1394,7 @@ class Graph:
|
||||||
await set_cache(key=vertex.id, data=vertex_dict)
|
await set_cache(key=vertex.id, data=vertex_dict)
|
||||||
|
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
if not isinstance(exc, ComponentBuildException):
|
if not isinstance(exc, ComponentBuildError):
|
||||||
logger.exception("Error building Component")
|
logger.exception("Error building Component")
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
|
@ -1699,13 +1699,13 @@ class Graph:
|
||||||
return InterfaceVertex
|
return InterfaceVertex
|
||||||
if node_name in {"SharedState", "Notify", "Listen"}:
|
if node_name in {"SharedState", "Notify", "Listen"}:
|
||||||
return StateVertex
|
return StateVertex
|
||||||
if node_base_type in lazy_load_vertex_dict.VERTEX_TYPE_MAP:
|
if node_base_type in lazy_load_vertex_dict.vertex_type_map:
|
||||||
return lazy_load_vertex_dict.VERTEX_TYPE_MAP[node_base_type]
|
return lazy_load_vertex_dict.vertex_type_map[node_base_type]
|
||||||
if node_name in lazy_load_vertex_dict.VERTEX_TYPE_MAP:
|
if node_name in lazy_load_vertex_dict.vertex_type_map:
|
||||||
return lazy_load_vertex_dict.VERTEX_TYPE_MAP[node_name]
|
return lazy_load_vertex_dict.vertex_type_map[node_name]
|
||||||
|
|
||||||
if node_type in lazy_load_vertex_dict.VERTEX_TYPE_MAP:
|
if node_type in lazy_load_vertex_dict.vertex_type_map:
|
||||||
return lazy_load_vertex_dict.VERTEX_TYPE_MAP[node_type]
|
return lazy_load_vertex_dict.vertex_type_map[node_type]
|
||||||
return Vertex
|
return Vertex
|
||||||
|
|
||||||
def _build_vertices(self) -> list[Vertex]:
|
def _build_vertices(self) -> list[Vertex]:
|
||||||
|
|
@ -1730,9 +1730,9 @@ class Graph:
|
||||||
msg = f"Vertex data for {vertex_data['display_name']} does not contain an id"
|
msg = f"Vertex data for {vertex_data['display_name']} does not contain an id"
|
||||||
raise ValueError(msg)
|
raise ValueError(msg)
|
||||||
|
|
||||||
VertexClass = self._get_vertex_class(vertex_type, vertex_base_type, vertex_data["id"])
|
vertex_class = self._get_vertex_class(vertex_type, vertex_base_type, vertex_data["id"])
|
||||||
|
|
||||||
vertex_instance = VertexClass(frontend_data, graph=self)
|
vertex_instance = vertex_class(frontend_data, graph=self)
|
||||||
vertex_instance.set_top_level(self.top_level_vertices)
|
vertex_instance.set_top_level(self.top_level_vertices)
|
||||||
return vertex_instance
|
return vertex_instance
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ class VertexTypesDict(LazyLoadDictBase):
|
||||||
self._types = _import_vertex_types
|
self._types = _import_vertex_types
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def VERTEX_TYPE_MAP(self):
|
def vertex_type_map(self):
|
||||||
return self.all_types_dict
|
return self.all_types_dict
|
||||||
|
|
||||||
def _build_dict(self):
|
def _build_dict(self):
|
||||||
|
|
|
||||||
|
|
@ -48,8 +48,6 @@ class ResultData(BaseModel):
|
||||||
|
|
||||||
|
|
||||||
class InterfaceComponentTypes(str, Enum, metaclass=ContainsEnumMeta):
|
class InterfaceComponentTypes(str, Enum, metaclass=ContainsEnumMeta):
|
||||||
# ChatInput and ChatOutput are the only ones that are
|
|
||||||
# power components
|
|
||||||
ChatInput = "ChatInput"
|
ChatInput = "ChatInput"
|
||||||
ChatOutput = "ChatOutput"
|
ChatOutput = "ChatOutput"
|
||||||
TextInput = "TextInput"
|
TextInput = "TextInput"
|
||||||
|
|
@ -57,14 +55,6 @@ class InterfaceComponentTypes(str, Enum, metaclass=ContainsEnumMeta):
|
||||||
DataOutput = "DataOutput"
|
DataOutput = "DataOutput"
|
||||||
WebhookInput = "Webhook"
|
WebhookInput = "Webhook"
|
||||||
|
|
||||||
def __contains__(cls, item):
|
|
||||||
try:
|
|
||||||
cls(item)
|
|
||||||
except ValueError:
|
|
||||||
return False
|
|
||||||
else:
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
CHAT_COMPONENTS = [InterfaceComponentTypes.ChatInput, InterfaceComponentTypes.ChatOutput]
|
CHAT_COMPONENTS = [InterfaceComponentTypes.ChatInput, InterfaceComponentTypes.ChatOutput]
|
||||||
RECORDS_COMPONENTS = [InterfaceComponentTypes.DataOutput]
|
RECORDS_COMPONENTS = [InterfaceComponentTypes.DataOutput]
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ from typing import TYPE_CHECKING, Any
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
|
|
||||||
from langflow.exceptions.component import ComponentBuildException
|
from langflow.exceptions.component import ComponentBuildError
|
||||||
from langflow.graph.schema import INPUT_COMPONENTS, OUTPUT_COMPONENTS, InterfaceComponentTypes, ResultData
|
from langflow.graph.schema import INPUT_COMPONENTS, OUTPUT_COMPONENTS, InterfaceComponentTypes, ResultData
|
||||||
from langflow.graph.utils import UnbuiltObject, UnbuiltResult, log_transaction
|
from langflow.graph.utils import UnbuiltObject, UnbuiltResult, log_transaction
|
||||||
from langflow.interface import initialize
|
from langflow.interface import initialize
|
||||||
|
|
@ -256,7 +256,7 @@ class Vertex:
|
||||||
)
|
)
|
||||||
|
|
||||||
if self.base_type is None:
|
if self.base_type is None:
|
||||||
for base_type, value in lazy_load_dict.ALL_TYPES_DICT.items():
|
for base_type, value in lazy_load_dict.all_types_dict.items():
|
||||||
if self.vertex_type in value:
|
if self.vertex_type in value:
|
||||||
self.base_type = base_type
|
self.base_type = base_type
|
||||||
break
|
break
|
||||||
|
|
@ -720,7 +720,7 @@ class Vertex:
|
||||||
tb = traceback.format_exc()
|
tb = traceback.format_exc()
|
||||||
logger.exception(exc)
|
logger.exception(exc)
|
||||||
msg = f"Error building Component {self.display_name}: \n\n{exc}"
|
msg = f"Error building Component {self.display_name}: \n\n{exc}"
|
||||||
raise ComponentBuildException(msg, tb) from exc
|
raise ComponentBuildError(msg, tb) from exc
|
||||||
|
|
||||||
def _update_built_object_and_artifacts(self, result: Any | tuple[Any, dict] | tuple[Component, Any, dict]):
|
def _update_built_object_and_artifacts(self, result: Any | tuple[Any, dict] | tuple[Component, Any, dict]):
|
||||||
"""Updates the built object and its artifacts."""
|
"""Updates the built object and its artifacts."""
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
class NoComponentInstance(Exception):
|
class NoComponentInstanceError(Exception):
|
||||||
def __init__(self, vertex_id: str):
|
def __init__(self, vertex_id: str):
|
||||||
message = f"Vertex {vertex_id} does not have a component instance."
|
message = f"Vertex {vertex_id} does not have a component instance."
|
||||||
super().__init__(message)
|
super().__init__(message)
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ from loguru import logger
|
||||||
from langflow.graph.schema import CHAT_COMPONENTS, RECORDS_COMPONENTS, InterfaceComponentTypes, ResultData
|
from langflow.graph.schema import CHAT_COMPONENTS, RECORDS_COMPONENTS, InterfaceComponentTypes, ResultData
|
||||||
from langflow.graph.utils import UnbuiltObject, log_vertex_build, rewrite_file_path, serialize_field
|
from langflow.graph.utils import UnbuiltObject, log_vertex_build, rewrite_file_path, serialize_field
|
||||||
from langflow.graph.vertex.base import Vertex
|
from langflow.graph.vertex.base import Vertex
|
||||||
from langflow.graph.vertex.exceptions import NoComponentInstance
|
from langflow.graph.vertex.exceptions import NoComponentInstanceError
|
||||||
from langflow.schema import Data
|
from langflow.schema import Data
|
||||||
from langflow.schema.artifact import ArtifactType
|
from langflow.schema.artifact import ArtifactType
|
||||||
from langflow.schema.message import Message
|
from langflow.schema.message import Message
|
||||||
|
|
@ -49,7 +49,7 @@ class ComponentVertex(Vertex):
|
||||||
|
|
||||||
def get_output(self, name: str) -> Output:
|
def get_output(self, name: str) -> Output:
|
||||||
if self._custom_component is None:
|
if self._custom_component is None:
|
||||||
raise NoComponentInstance(self.id)
|
raise NoComponentInstanceError(self.id)
|
||||||
return self._custom_component.get_output(name)
|
return self._custom_component.get_output(name)
|
||||||
|
|
||||||
def _built_object_repr(self):
|
def _built_object_repr(self):
|
||||||
|
|
@ -130,7 +130,7 @@ class ComponentVertex(Vertex):
|
||||||
result = self.results[edge.source_handle.name]
|
result = self.results[edge.source_handle.name]
|
||||||
else:
|
else:
|
||||||
result = cast(Any, output.value)
|
result = cast(Any, output.value)
|
||||||
except NoComponentInstance:
|
except NoComponentInstanceError:
|
||||||
result = self.results[edge.source_handle.name]
|
result = self.results[edge.source_handle.name]
|
||||||
break
|
break
|
||||||
if result is UNDEFINED:
|
if result is UNDEFINED:
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ else:
|
||||||
_InputTypesMap: dict[str, type["InputTypes"]] | None = None
|
_InputTypesMap: dict[str, type["InputTypes"]] | None = None
|
||||||
|
|
||||||
|
|
||||||
def get_InputTypesMap():
|
def get_input_types_map():
|
||||||
global _InputTypesMap # noqa: PLW0603
|
global _InputTypesMap # noqa: PLW0603
|
||||||
if _InputTypesMap is None:
|
if _InputTypesMap is None:
|
||||||
from langflow.inputs.inputs import InputTypesMap
|
from langflow.inputs.inputs import InputTypesMap
|
||||||
|
|
@ -20,9 +20,9 @@ def get_InputTypesMap():
|
||||||
|
|
||||||
|
|
||||||
def instantiate_input(input_type: str, data: dict) -> InputTypes:
|
def instantiate_input(input_type: str, data: dict) -> InputTypes:
|
||||||
InputTypesMap = get_InputTypesMap()
|
input_types_map = get_input_types_map()
|
||||||
|
|
||||||
input_type_class = InputTypesMap.get(input_type)
|
input_type_class = input_types_map.get(input_type)
|
||||||
if "type" in data:
|
if "type" in data:
|
||||||
# Replace with field_type
|
# Replace with field_type
|
||||||
data["field_type"] = data.pop("type")
|
data["field_type"] = data.pop("type")
|
||||||
|
|
|
||||||
|
|
@ -6,10 +6,6 @@ class AllTypesDict(LazyLoadDictBase):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self._all_types_dict = None
|
self._all_types_dict = None
|
||||||
|
|
||||||
@property
|
|
||||||
def ALL_TYPES_DICT(self):
|
|
||||||
return self.all_types_dict
|
|
||||||
|
|
||||||
def _build_dict(self):
|
def _build_dict(self):
|
||||||
langchain_types_dict = self.get_type_dict()
|
langchain_types_dict = self.get_type_dict()
|
||||||
return {
|
return {
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
class dotdict(dict):
|
class dotdict(dict): # noqa: N801
|
||||||
"""dotdict allows accessing dictionary elements using dot notation (e.g., dict.key instead of dict['key']).
|
"""dotdict allows accessing dictionary elements using dot notation (e.g., dict.key instead of dict['key']).
|
||||||
|
|
||||||
It automatically converts nested dictionaries into dotdict instances, enabling dot notation on them as well.
|
It automatically converts nested dictionaries into dotdict instances, enabling dot notation on them as well.
|
||||||
|
|
|
||||||
|
|
@ -65,13 +65,13 @@ class Message(Data):
|
||||||
return value
|
return value
|
||||||
|
|
||||||
@field_serializer("flow_id")
|
@field_serializer("flow_id")
|
||||||
def serialize_flow_id(value):
|
def serialize_flow_id(self, value):
|
||||||
if isinstance(value, UUID):
|
if isinstance(value, UUID):
|
||||||
return str(value)
|
return str(value)
|
||||||
return value
|
return value
|
||||||
|
|
||||||
@field_serializer("timestamp")
|
@field_serializer("timestamp")
|
||||||
def serialize_timestamp(value):
|
def serialize_timestamp(self, value):
|
||||||
return datetime.strptime(value, "%Y-%m-%d %H:%M:%S").astimezone(timezone.utc)
|
return datetime.strptime(value, "%Y-%m-%d %H:%M:%S").astimezone(timezone.utc)
|
||||||
|
|
||||||
@field_validator("files", mode="before")
|
@field_validator("files", mode="before")
|
||||||
|
|
|
||||||
|
|
@ -360,8 +360,8 @@ def ensure_valid_key(s: str) -> bytes:
|
||||||
|
|
||||||
|
|
||||||
def get_fernet(settings_service=Depends(get_settings_service)):
|
def get_fernet(settings_service=Depends(get_settings_service)):
|
||||||
SECRET_KEY: str = settings_service.auth_settings.SECRET_KEY.get_secret_value()
|
secret_key: str = settings_service.auth_settings.SECRET_KEY.get_secret_value()
|
||||||
valid_key = ensure_valid_key(SECRET_KEY)
|
valid_key = ensure_valid_key(secret_key)
|
||||||
return Fernet(valid_key)
|
return Fernet(valid_key)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -56,6 +56,7 @@ class FlowBase(SQLModel):
|
||||||
return v
|
return v
|
||||||
|
|
||||||
@field_validator("icon_bg_color")
|
@field_validator("icon_bg_color")
|
||||||
|
@classmethod
|
||||||
def validate_icon_bg_color(cls, v):
|
def validate_icon_bg_color(cls, v):
|
||||||
if v is not None and not isinstance(v, str):
|
if v is not None and not isinstance(v, str):
|
||||||
msg = "Icon background color must be a string"
|
msg = "Icon background color must be a string"
|
||||||
|
|
@ -72,6 +73,7 @@ class FlowBase(SQLModel):
|
||||||
return v
|
return v
|
||||||
|
|
||||||
@field_validator("icon")
|
@field_validator("icon")
|
||||||
|
@classmethod
|
||||||
def validate_icon_atr(cls, v):
|
def validate_icon_atr(cls, v):
|
||||||
# const emojiRegex = /\p{Emoji}/u;
|
# const emojiRegex = /\p{Emoji}/u;
|
||||||
# const isEmoji = emojiRegex.test(data?.node?.icon!);
|
# const isEmoji = emojiRegex.test(data?.node?.icon!);
|
||||||
|
|
@ -111,7 +113,8 @@ class FlowBase(SQLModel):
|
||||||
return v
|
return v
|
||||||
|
|
||||||
@field_validator("data")
|
@field_validator("data")
|
||||||
def validate_json(v):
|
@classmethod
|
||||||
|
def validate_json(cls, v):
|
||||||
if not v:
|
if not v:
|
||||||
return v
|
return v
|
||||||
if not isinstance(v, dict):
|
if not isinstance(v, dict):
|
||||||
|
|
@ -130,7 +133,7 @@ class FlowBase(SQLModel):
|
||||||
|
|
||||||
# updated_at can be serialized to JSON
|
# updated_at can be serialized to JSON
|
||||||
@field_serializer("updated_at")
|
@field_serializer("updated_at")
|
||||||
def serialize_datetime(value):
|
def serialize_datetime(self, value):
|
||||||
if isinstance(value, datetime):
|
if isinstance(value, datetime):
|
||||||
# I'm getting 2024-05-29T17:57:17.631346
|
# I'm getting 2024-05-29T17:57:17.631346
|
||||||
# and I want 2024-05-29T17:57:17-05:00
|
# and I want 2024-05-29T17:57:17-05:00
|
||||||
|
|
@ -141,6 +144,7 @@ class FlowBase(SQLModel):
|
||||||
return value
|
return value
|
||||||
|
|
||||||
@field_validator("updated_at", mode="before")
|
@field_validator("updated_at", mode="before")
|
||||||
|
@classmethod
|
||||||
def validate_dt(cls, v):
|
def validate_dt(cls, v):
|
||||||
if v is None:
|
if v is None:
|
||||||
return v
|
return v
|
||||||
|
|
|
||||||
|
|
@ -292,6 +292,7 @@ class Settings(BaseSettings):
|
||||||
return value
|
return value
|
||||||
|
|
||||||
@field_validator("components_path", mode="before")
|
@field_validator("components_path", mode="before")
|
||||||
|
@classmethod
|
||||||
def set_components_path(cls, value):
|
def set_components_path(cls, value):
|
||||||
if os.getenv("LANGFLOW_COMPONENTS_PATH"):
|
if os.getenv("LANGFLOW_COMPONENTS_PATH"):
|
||||||
logger.debug("Adding LANGFLOW_COMPONENTS_PATH to components_path")
|
logger.debug("Adding LANGFLOW_COMPONENTS_PATH to components_path")
|
||||||
|
|
|
||||||
|
|
@ -1,25 +1,25 @@
|
||||||
class CustomException(Exception):
|
class CustomError(Exception):
|
||||||
def __init__(self, detail, status_code):
|
def __init__(self, detail, status_code):
|
||||||
super().__init__(detail)
|
super().__init__(detail)
|
||||||
self.status_code = status_code
|
self.status_code = status_code
|
||||||
|
|
||||||
|
|
||||||
# Define custom exceptions with status codes
|
# Define custom exceptions with status codes
|
||||||
class UnauthorizedError(CustomException):
|
class UnauthorizedError(CustomError):
|
||||||
def __init__(self, detail="Unauthorized access"):
|
def __init__(self, detail="Unauthorized access"):
|
||||||
super().__init__(detail, 401)
|
super().__init__(detail, 401)
|
||||||
|
|
||||||
|
|
||||||
class ForbiddenError(CustomException):
|
class ForbiddenError(CustomError):
|
||||||
def __init__(self, detail="Forbidden"):
|
def __init__(self, detail="Forbidden"):
|
||||||
super().__init__(detail, 403)
|
super().__init__(detail, 403)
|
||||||
|
|
||||||
|
|
||||||
class APIKeyError(CustomException):
|
class APIKeyError(CustomError):
|
||||||
def __init__(self, detail="API key error"):
|
def __init__(self, detail="API key error"):
|
||||||
super().__init__(detail, 400) # ! Should be 401
|
super().__init__(detail, 400) # ! Should be 401
|
||||||
|
|
||||||
|
|
||||||
class FilterError(CustomException):
|
class FilterError(CustomError):
|
||||||
def __init__(self, detail="Filter error"):
|
def __init__(self, detail="Filter error"):
|
||||||
super().__init__(detail, 400)
|
super().__init__(detail, 400)
|
||||||
|
|
|
||||||
|
|
@ -33,16 +33,15 @@ class TaskService(Service):
|
||||||
self.settings_service = settings_service
|
self.settings_service = settings_service
|
||||||
try:
|
try:
|
||||||
if self.settings_service.settings.celery_enabled:
|
if self.settings_service.settings.celery_enabled:
|
||||||
USE_CELERY = True
|
|
||||||
status = check_celery_availability()
|
status = check_celery_availability()
|
||||||
|
|
||||||
USE_CELERY = status.get("availability") is not None
|
use_celery = status.get("availability") is not None
|
||||||
else:
|
else:
|
||||||
USE_CELERY = False
|
use_celery = False
|
||||||
except ImportError:
|
except ImportError:
|
||||||
USE_CELERY = False
|
use_celery = False
|
||||||
|
|
||||||
self.use_celery = USE_CELERY
|
self.use_celery = use_celery
|
||||||
self.backend = self.get_backend()
|
self.backend = self.get_backend()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,15 @@
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel, Field
|
||||||
|
|
||||||
|
|
||||||
class RunPayload(BaseModel):
|
class RunPayload(BaseModel):
|
||||||
runIsWebhook: bool = False
|
run_is_webhook: bool = Field(default=False, serialization_alias="runIsWebhook")
|
||||||
runSeconds: int
|
run_seconds: int = Field(serialization_alias="runSeconds")
|
||||||
runSuccess: bool
|
run_success: bool = Field(serialization_alias="runSuccess")
|
||||||
runErrorMessage: str = ""
|
run_error_message: str = Field("", serialization_alias="runErrorMessage")
|
||||||
|
|
||||||
|
|
||||||
class ShutdownPayload(BaseModel):
|
class ShutdownPayload(BaseModel):
|
||||||
timeRunning: int
|
time_running: int = Field(serialization_alias="timeRunning")
|
||||||
|
|
||||||
|
|
||||||
class VersionPayload(BaseModel):
|
class VersionPayload(BaseModel):
|
||||||
|
|
@ -18,20 +18,20 @@ class VersionPayload(BaseModel):
|
||||||
platform: str
|
platform: str
|
||||||
python: str
|
python: str
|
||||||
arch: str
|
arch: str
|
||||||
autoLogin: bool
|
auto_login: bool = Field(serialization_alias="autoLogin")
|
||||||
cacheType: str
|
cache_type: str = Field(serialization_alias="cacheType")
|
||||||
backendOnly: bool
|
backend_only: bool = Field(serialization_alias="backendOnly")
|
||||||
|
|
||||||
|
|
||||||
class PlaygroundPayload(BaseModel):
|
class PlaygroundPayload(BaseModel):
|
||||||
playgroundSeconds: int
|
playground_seconds: int = Field(serialization_alias="playgroundSeconds")
|
||||||
playgroundComponentCount: int | None = None
|
playground_component_count: int | None = Field(None, serialization_alias="playgroundComponentCount")
|
||||||
playgroundSuccess: bool
|
playground_success: bool = Field(serialization_alias="playgroundSuccess")
|
||||||
playgroundErrorMessage: str = ""
|
playground_error_message: str = Field("", serialization_alias="playgroundErrorMessage")
|
||||||
|
|
||||||
|
|
||||||
class ComponentPayload(BaseModel):
|
class ComponentPayload(BaseModel):
|
||||||
componentName: str
|
component_name: str = Field(serialization_alias="componentName")
|
||||||
componentSeconds: int
|
component_seconds: int = Field(serialization_alias="componentSeconds")
|
||||||
componentSuccess: bool
|
component_success: bool = Field(serialization_alias="componentSuccess")
|
||||||
componentErrorMessage: str | None = None
|
component_error_message: str | None = Field(serialization_alias="componentErrorMessage")
|
||||||
|
|
|
||||||
|
|
@ -65,7 +65,7 @@ class TelemetryService(Service):
|
||||||
if path:
|
if path:
|
||||||
url = f"{url}/{path}"
|
url = f"{url}/{path}"
|
||||||
try:
|
try:
|
||||||
payload_dict = payload.model_dump(exclude_none=True, exclude_unset=True)
|
payload_dict = payload.model_dump(by_alias=True, exclude_none=True, exclude_unset=True)
|
||||||
response = await self.client.get(url, params=payload_dict)
|
response = await self.client.get(url, params=payload_dict)
|
||||||
if response.status_code != httpx.codes.OK:
|
if response.status_code != httpx.codes.OK:
|
||||||
logger.error(f"Failed to send telemetry data: {response.status_code} {response.text}")
|
logger.error(f"Failed to send telemetry data: {response.status_code} {response.text}")
|
||||||
|
|
@ -82,7 +82,7 @@ class TelemetryService(Service):
|
||||||
await self._queue_event((self.send_telemetry_data, payload, "run"))
|
await self._queue_event((self.send_telemetry_data, payload, "run"))
|
||||||
|
|
||||||
async def log_package_shutdown(self):
|
async def log_package_shutdown(self):
|
||||||
payload = ShutdownPayload(timeRunning=(datetime.now(timezone.utc) - self._start_time).seconds)
|
payload = ShutdownPayload(time_running=(datetime.now(timezone.utc) - self._start_time).seconds)
|
||||||
await self._queue_event(payload)
|
await self._queue_event(payload)
|
||||||
|
|
||||||
async def _queue_event(self, payload):
|
async def _queue_event(self, payload):
|
||||||
|
|
@ -99,10 +99,10 @@ class TelemetryService(Service):
|
||||||
version=version_info["version"],
|
version=version_info["version"],
|
||||||
platform=platform.platform(),
|
platform=platform.platform(),
|
||||||
python=python_version,
|
python=python_version,
|
||||||
cacheType=self.settings_service.settings.cache_type,
|
cache_type=self.settings_service.settings.cache_type,
|
||||||
backendOnly=self.settings_service.settings.backend_only,
|
backend_only=self.settings_service.settings.backend_only,
|
||||||
arch=architecture,
|
arch=architecture,
|
||||||
autoLogin=self.settings_service.auth_settings.AUTO_LOGIN,
|
auto_login=self.settings_service.auth_settings.AUTO_LOGIN,
|
||||||
)
|
)
|
||||||
await self._queue_event((self.send_telemetry_data, payload, None))
|
await self._queue_event((self.send_telemetry_data, payload, None))
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -137,6 +137,7 @@ class Input(BaseModel):
|
||||||
return value
|
return value
|
||||||
|
|
||||||
@field_validator("file_types")
|
@field_validator("file_types")
|
||||||
|
@classmethod
|
||||||
def validate_file_types(cls, value):
|
def validate_file_types(cls, value):
|
||||||
if not isinstance(value, list):
|
if not isinstance(value, list):
|
||||||
msg = "file_types must be a list"
|
msg = "file_types must be a list"
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,7 @@ class ChatOutputResponse(BaseModel):
|
||||||
type: str
|
type: str
|
||||||
|
|
||||||
@field_validator("files", mode="before")
|
@field_validator("files", mode="before")
|
||||||
|
@classmethod
|
||||||
def validate_files(cls, files):
|
def validate_files(cls, files):
|
||||||
"""Validate files."""
|
"""Validate files."""
|
||||||
if not files:
|
if not files:
|
||||||
|
|
|
||||||
|
|
@ -56,9 +56,9 @@ ignore = [
|
||||||
"TRY301", # A bit too harsh (Abstract `raise` to an inner function)
|
"TRY301", # A bit too harsh (Abstract `raise` to an inner function)
|
||||||
|
|
||||||
# Rules that are TODOs
|
# Rules that are TODOs
|
||||||
"ANN",
|
"ANN", # Missing type annotations
|
||||||
"D1", # Missing docstrings
|
"D1", # Missing docstrings
|
||||||
"N",
|
"N999", # Invalid module names
|
||||||
"S",
|
"S",
|
||||||
"SLF",
|
"SLF",
|
||||||
]
|
]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue