mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-06-30 21:59:46 +02:00
chore: ran linting
This commit is contained in:
parent
b9b4d0b377
commit
cd25175b84
14 changed files with 78 additions and 82 deletions
|
|
@ -286,9 +286,7 @@ def initialize_openrouter_integration():
|
|||
|
||||
if new_configs:
|
||||
config.GLOBAL_LLM_CONFIGS.extend(new_configs)
|
||||
free_count = sum(
|
||||
1 for c in new_configs if c.get("billing_tier") == "free"
|
||||
)
|
||||
free_count = sum(1 for c in new_configs if c.get("billing_tier") == "free")
|
||||
premium_count = sum(
|
||||
1 for c in new_configs if c.get("billing_tier") == "premium"
|
||||
)
|
||||
|
|
|
|||
|
|
@ -277,9 +277,7 @@ async def resolve_or_get_pinned_llm_config_id(
|
|||
c for c in _global_candidates() if int(c.get("id", 0)) not in excluded_ids
|
||||
]
|
||||
if not candidates:
|
||||
raise ValueError(
|
||||
"No usable global LLM configs are available for Auto mode"
|
||||
)
|
||||
raise ValueError("No usable global LLM configs are available for Auto mode")
|
||||
candidate_by_id = {int(c["id"]): c for c in candidates}
|
||||
|
||||
# Reuse an existing valid pin without re-checking current quota (no silent
|
||||
|
|
|
|||
|
|
@ -405,9 +405,7 @@ class OpenRouterIntegrationService:
|
|||
# Re-blend health scores against the freshly fetched catalogue. Also
|
||||
# re-stamps health for any YAML-curated cfg with provider==OPENROUTER
|
||||
# so a hand-picked dead OR model is gated like a dynamic one.
|
||||
await self._enrich_health_safely(
|
||||
static_configs + new_configs, log_summary=True
|
||||
)
|
||||
await self._enrich_health_safely(static_configs + new_configs, log_summary=True)
|
||||
|
||||
# Rebuild the LiteLLM router so freshly fetched configs flow through
|
||||
# (dynamic OR premium entries now opt into the pool, free ones stay
|
||||
|
|
@ -415,8 +413,8 @@ class OpenRouterIntegrationService:
|
|||
# reset cached context-window profiles).
|
||||
try:
|
||||
from app.config import config as _app_config
|
||||
from app.services.llm_router_service import LLMRouterService
|
||||
from app.services.llm_router_service import (
|
||||
LLMRouterService,
|
||||
_router_instance_cache as _chat_router_cache,
|
||||
)
|
||||
|
||||
|
|
@ -426,9 +424,7 @@ class OpenRouterIntegrationService:
|
|||
)
|
||||
_chat_router_cache.clear()
|
||||
except Exception as exc:
|
||||
logger.warning(
|
||||
"OpenRouter refresh: router rebuild skipped (%s)", exc
|
||||
)
|
||||
logger.warning("OpenRouter refresh: router rebuild skipped (%s)", exc)
|
||||
|
||||
@staticmethod
|
||||
def _tier_counts(configs: list[dict]) -> dict[str, int]:
|
||||
|
|
@ -475,19 +471,11 @@ class OpenRouterIntegrationService:
|
|||
return
|
||||
|
||||
premium_pool = sorted(
|
||||
[
|
||||
c
|
||||
for c in or_cfgs
|
||||
if str(c.get("billing_tier", "")).lower() == "premium"
|
||||
],
|
||||
[c for c in or_cfgs if str(c.get("billing_tier", "")).lower() == "premium"],
|
||||
key=lambda c: -int(c.get("quality_score_static") or 0),
|
||||
)[:_HEALTH_ENRICH_TOP_N_PREMIUM]
|
||||
free_pool = sorted(
|
||||
[
|
||||
c
|
||||
for c in or_cfgs
|
||||
if str(c.get("billing_tier", "")).lower() == "free"
|
||||
],
|
||||
[c for c in or_cfgs if str(c.get("billing_tier", "")).lower() == "free"],
|
||||
key=lambda c: -int(c.get("quality_score_static") or 0),
|
||||
)[:_HEALTH_ENRICH_TOP_N_FREE]
|
||||
# De-duplicate while preserving order: a cfg shouldn't fall in both
|
||||
|
|
@ -507,9 +495,7 @@ class OpenRouterIntegrationService:
|
|||
api_key = str(self._settings.get("api_key") or "")
|
||||
semaphore = asyncio.Semaphore(_HEALTH_ENRICH_CONCURRENCY)
|
||||
|
||||
async with httpx.AsyncClient(
|
||||
timeout=_HEALTH_FETCH_TIMEOUT_SEC
|
||||
) as client:
|
||||
async with httpx.AsyncClient(timeout=_HEALTH_FETCH_TIMEOUT_SEC) as client:
|
||||
results = await asyncio.gather(
|
||||
*(
|
||||
self._fetch_endpoints(client, semaphore, api_key, cfg)
|
||||
|
|
|
|||
|
|
@ -7,12 +7,12 @@ sort and a SHA256 pick.
|
|||
|
||||
Score components (0-100 scale, higher is better):
|
||||
|
||||
* ``static_score_or`` – derived from the bulk ``/api/v1/models`` payload
|
||||
* ``static_score_or`` - derived from the bulk ``/api/v1/models`` payload
|
||||
(provider prestige + ``created`` recency + pricing band + context window
|
||||
+ capabilities + narrow tiny/legacy slug penalty).
|
||||
* ``static_score_yaml`` – same shape for hand-curated YAML configs, plus
|
||||
* ``static_score_yaml`` - same shape for hand-curated YAML configs, plus
|
||||
an operator-trust bonus (the operator deliberately picked this model).
|
||||
* ``aggregate_health`` – run on per-model ``/api/v1/models/{id}/endpoints``
|
||||
* ``aggregate_health`` - run on per-model ``/api/v1/models/{id}/endpoints``
|
||||
responses; returns ``(gated, score_or_none)``.
|
||||
|
||||
The blended ``quality_score`` (0.5 * static + 0.5 * health) is computed in
|
||||
|
|
@ -281,9 +281,7 @@ def static_score_yaml(cfg: dict) -> int:
|
|||
model_name = cfg.get("model_name") or ""
|
||||
litellm_params = cfg.get("litellm_params") or {}
|
||||
lookup_name = (
|
||||
litellm_params.get("base_model")
|
||||
or litellm_params.get("model")
|
||||
or model_name
|
||||
litellm_params.get("base_model") or litellm_params.get("model") or model_name
|
||||
)
|
||||
|
||||
ctx = 0
|
||||
|
|
|
|||
|
|
@ -1814,7 +1814,9 @@ async def _stream_agent_events(
|
|||
resolved_path = _extract_resolved_file_path(
|
||||
tool_name=tool_name,
|
||||
tool_output=tool_output,
|
||||
tool_input={"file_path": staged_file_path} if staged_file_path else None,
|
||||
tool_input={"file_path": staged_file_path}
|
||||
if staged_file_path
|
||||
else None,
|
||||
)
|
||||
result_text = _tool_output_to_text(tool_output)
|
||||
if _tool_output_has_error(tool_output):
|
||||
|
|
@ -2441,8 +2443,7 @@ async def stream_new_chat(
|
|||
await _preflight_llm(llm)
|
||||
mark_healthy(llm_config_id)
|
||||
_perf_log.info(
|
||||
"[stream_new_chat] auto_pin_preflight ok config_id=%s "
|
||||
"took=%.3fs",
|
||||
"[stream_new_chat] auto_pin_preflight ok config_id=%s took=%.3fs",
|
||||
llm_config_id,
|
||||
time.perf_counter() - _t_preflight,
|
||||
)
|
||||
|
|
@ -2891,7 +2892,11 @@ async def stream_new_chat(
|
|||
|
||||
# Inject title update mid-stream as soon as the background
|
||||
# task finishes.
|
||||
if title_task is not None and title_task.done() and not title_emitted:
|
||||
if (
|
||||
title_task is not None
|
||||
and title_task.done()
|
||||
and not title_emitted
|
||||
):
|
||||
generated_title, title_usage = title_task.result()
|
||||
if title_usage:
|
||||
accumulator.add(**title_usage)
|
||||
|
|
@ -2944,7 +2949,9 @@ async def stream_new_chat(
|
|||
)
|
||||
).resolved_llm_config_id
|
||||
|
||||
llm, agent_config, llm_load_error = await _load_llm_bundle(llm_config_id)
|
||||
llm, agent_config, llm_load_error = await _load_llm_bundle(
|
||||
llm_config_id
|
||||
)
|
||||
if llm_load_error:
|
||||
raise stream_exc
|
||||
|
||||
|
|
@ -3480,8 +3487,7 @@ async def stream_resume_chat(
|
|||
await _preflight_llm(llm)
|
||||
mark_healthy(llm_config_id)
|
||||
_perf_log.info(
|
||||
"[stream_resume] auto_pin_preflight ok config_id=%s "
|
||||
"took=%.3fs",
|
||||
"[stream_resume] auto_pin_preflight ok config_id=%s took=%.3fs",
|
||||
llm_config_id,
|
||||
time.perf_counter() - _t_preflight,
|
||||
)
|
||||
|
|
@ -3684,7 +3690,9 @@ async def stream_resume_chat(
|
|||
)
|
||||
).resolved_llm_config_id
|
||||
|
||||
llm, agent_config, llm_load_error = await _load_llm_bundle(llm_config_id)
|
||||
llm, agent_config, llm_load_error = await _load_llm_bundle(
|
||||
llm_config_id
|
||||
)
|
||||
if llm_load_error:
|
||||
raise stream_exc
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue