mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-07-22 23:31:12 +02:00
chore: ran linting
This commit is contained in:
parent
ceace003aa
commit
c7409c8995
48 changed files with 342 additions and 187 deletions
|
|
@ -86,4 +86,3 @@ def user_content_to_llm_content(
|
|||
if allow_images and any(part.get("type") == "image_url" for part in parts):
|
||||
return parts
|
||||
return "\n".join(text_chunks)
|
||||
|
||||
|
|
|
|||
|
|
@ -31,7 +31,9 @@ def _text_from_content(content: Any) -> str:
|
|||
return "".join(text_parts)
|
||||
|
||||
|
||||
def normalize_ai_message_to_parts(message: AIMessage | Any | None) -> list[dict[str, Any]]:
|
||||
def normalize_ai_message_to_parts(
|
||||
message: AIMessage | Any | None,
|
||||
) -> list[dict[str, Any]]:
|
||||
"""Return user-visible assistant-ui parts for a final AI message.
|
||||
|
||||
We intentionally do not backfill provider ``thinking`` /
|
||||
|
|
@ -60,7 +62,9 @@ def last_ai_message(messages: Iterable[Any] | None) -> AIMessage | Any | None:
|
|||
return None
|
||||
|
||||
|
||||
def final_assistant_parts_from_messages(messages: Iterable[Any] | None) -> list[dict[str, Any]]:
|
||||
def final_assistant_parts_from_messages(
|
||||
messages: Iterable[Any] | None,
|
||||
) -> list[dict[str, Any]]:
|
||||
return normalize_ai_message_to_parts(last_ai_message(messages))
|
||||
|
||||
|
||||
|
|
@ -83,4 +87,3 @@ def merge_streamed_and_final_parts(
|
|||
if not has_non_empty_text_part(final_parts):
|
||||
return streamed_parts
|
||||
return [*streamed_parts, *final_parts]
|
||||
|
||||
|
|
|
|||
|
|
@ -16,6 +16,9 @@ from app.agents.chat.multi_agent_chat.main_agent.middleware.kb_persistence impor
|
|||
)
|
||||
from app.agents.chat.multi_agent_chat.shared.filesystem_selection import FilesystemMode
|
||||
from app.services.new_streaming_service import VercelStreamingService
|
||||
from app.tasks.chat.message_parts_normalizer import (
|
||||
final_assistant_parts_from_messages,
|
||||
)
|
||||
from app.tasks.chat.streaming.contract.file_contract import (
|
||||
contract_enforcement_active,
|
||||
evaluate_file_contract_outcome,
|
||||
|
|
@ -25,9 +28,6 @@ from app.tasks.chat.streaming.graph_stream.event_stream import stream_output
|
|||
from app.tasks.chat.streaming.helpers.interrupt_inspector import (
|
||||
all_interrupt_values,
|
||||
)
|
||||
from app.tasks.chat.message_parts_normalizer import (
|
||||
final_assistant_parts_from_messages,
|
||||
)
|
||||
from app.tasks.chat.streaming.shared.stream_result import StreamResult
|
||||
from app.tasks.chat.streaming.shared.utils import safe_float
|
||||
from app.utils.perf import get_perf_logger
|
||||
|
|
|
|||
|
|
@ -146,9 +146,10 @@ def _provider_error_extra(adapted: Any) -> dict[str, Any] | None:
|
|||
|
||||
def _classify_provider_exception(
|
||||
exc: Exception,
|
||||
) -> tuple[
|
||||
str, str, Literal["info", "warn", "error"], bool, str, dict[str, Any] | None
|
||||
] | None:
|
||||
) -> (
|
||||
tuple[str, str, Literal["info", "warn", "error"], bool, str, dict[str, Any] | None]
|
||||
| None
|
||||
):
|
||||
adapted = adapt_llm_exception(exc)
|
||||
|
||||
if adapted.category is LLMErrorCategory.RATE_LIMITED:
|
||||
|
|
|
|||
|
|
@ -55,8 +55,12 @@ def _agent_config_from_resolved(
|
|||
)
|
||||
|
||||
|
||||
async def _load_search_space(session: AsyncSession, search_space_id: int) -> SearchSpace | None:
|
||||
result = await session.execute(select(SearchSpace).where(SearchSpace.id == search_space_id))
|
||||
async def _load_search_space(
|
||||
session: AsyncSession, search_space_id: int
|
||||
) -> SearchSpace | None:
|
||||
result = await session.execute(
|
||||
select(SearchSpace).where(SearchSpace.id == search_space_id)
|
||||
)
|
||||
return result.scalars().first()
|
||||
|
||||
|
||||
|
|
@ -131,7 +135,9 @@ async def load_llm_bundle(
|
|||
None,
|
||||
)
|
||||
|
||||
global_model = next((m for m in config.GLOBAL_MODELS if m.get("id") == config_id), None)
|
||||
global_model = next(
|
||||
(m for m in config.GLOBAL_MODELS if m.get("id") == config_id), None
|
||||
)
|
||||
if not global_model or not has_capability(global_model, "chat"):
|
||||
return None, None, f"Failed to load global chat model with id {config_id}"
|
||||
global_connection = next(
|
||||
|
|
@ -144,7 +150,9 @@ async def load_llm_bundle(
|
|||
)
|
||||
if not global_connection:
|
||||
return None, None, f"Failed to load global connection for model {config_id}"
|
||||
model_string, litellm_kwargs = to_litellm(global_connection, global_model["model_id"])
|
||||
model_string, litellm_kwargs = to_litellm(
|
||||
global_connection, global_model["model_id"]
|
||||
)
|
||||
display_name = global_model.get("display_name") or global_model.get("model_id")
|
||||
provider = global_connection.get("provider") or ""
|
||||
register_model_usage_metadata(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue