fix: Remove noisy sentry error on llm failure and upgrade deps (#396)
This commit is contained in:
parent
5bd93a2bef
commit
78df86dc66
|
|
@ -8,11 +8,11 @@ authors = [
|
|||
readme = "README.md"
|
||||
requires-python = ">=3.10"
|
||||
dependencies = [
|
||||
"fastapi[standard]>=0.111.0",
|
||||
"fastapi[standard]>=0.131.0",
|
||||
"groq>=0.31.0",
|
||||
"python-dotenv>=1.0.0",
|
||||
"sqlalchemy>=2.0.30",
|
||||
"fastapi-pagination>=0.12.24",
|
||||
"fastapi-pagination>=0.14.2",
|
||||
"pgvector>=0.2.5",
|
||||
"sentry-sdk[anthropic,fastapi,sqlalchemy]>=2.3.1",
|
||||
"greenlet>=3.0.3",
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
import datetime
|
||||
from collections.abc import Sequence
|
||||
from logging import getLogger
|
||||
from typing import Any
|
||||
from typing import Any, cast
|
||||
|
||||
from sqlalchemy import delete, select, update
|
||||
from sqlalchemy.engine import CursorResult
|
||||
from sqlalchemy.exc import IntegrityError
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
from sqlalchemy.sql import Select
|
||||
|
|
@ -530,7 +531,7 @@ async def delete_document(
|
|||
update_stmt = (
|
||||
update(models.Document).where(*conditions).values(deleted_at=func.now())
|
||||
)
|
||||
result = await db.execute(update_stmt)
|
||||
result = cast(CursorResult[Any], await db.execute(update_stmt))
|
||||
|
||||
if result.rowcount == 0:
|
||||
raise ResourceNotFoundException(
|
||||
|
|
@ -568,7 +569,7 @@ async def delete_document_by_id(
|
|||
)
|
||||
.values(deleted_at=func.now())
|
||||
)
|
||||
result = await db.execute(update_stmt)
|
||||
result = cast(CursorResult[Any], await db.execute(update_stmt))
|
||||
|
||||
if result.rowcount == 0:
|
||||
raise ResourceNotFoundException(
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
from typing import cast
|
||||
from typing import Any, cast
|
||||
|
||||
from sqlalchemy import update
|
||||
from sqlalchemy.engine import CursorResult
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from src import exceptions, models, schemas
|
||||
|
|
@ -84,7 +85,7 @@ async def set_peer_card(
|
|||
)
|
||||
)
|
||||
)
|
||||
result = await db.execute(stmt)
|
||||
result = cast(CursorResult[Any], await db.execute(stmt))
|
||||
if result.rowcount == 0:
|
||||
raise exceptions.ResourceNotFoundException(
|
||||
f"Peer {observer} not found in workspace {workspace_name}"
|
||||
|
|
|
|||
|
|
@ -1,11 +1,13 @@
|
|||
from dataclasses import dataclass
|
||||
from logging import getLogger
|
||||
from typing import Any
|
||||
from typing import cast as typing_cast
|
||||
|
||||
from cashews import NOT_NONE
|
||||
from nanoid import generate as generate_nanoid
|
||||
from sqlalchemy import Select, and_, case, cast, delete, func, insert, select, update
|
||||
from sqlalchemy.dialects.postgresql import insert as pg_insert
|
||||
from sqlalchemy.engine import CursorResult
|
||||
from sqlalchemy.exc import IntegrityError
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
from sqlalchemy.types import BigInteger, Boolean
|
||||
|
|
@ -378,7 +380,7 @@ async def _batch_delete_matching(
|
|||
select(primary_key_column).where(and_(*filter_conditions)).limit(batch_size)
|
||||
)
|
||||
delete_stmt = delete(model).where(primary_key_column.in_(subquery))
|
||||
delete_result = await db.execute(delete_stmt)
|
||||
delete_result = typing_cast(CursorResult[Any], await db.execute(delete_stmt))
|
||||
batch_deleted = delete_result.rowcount or 0
|
||||
total_deleted += batch_deleted
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ from asyncio import Task
|
|||
from collections.abc import Sequence
|
||||
from datetime import datetime, timedelta, timezone
|
||||
from logging import getLogger
|
||||
from typing import NamedTuple
|
||||
from typing import Any, NamedTuple, cast
|
||||
|
||||
import sentry_sdk
|
||||
from dotenv import load_dotenv
|
||||
|
|
@ -12,6 +12,7 @@ from nanoid import generate as generate_nanoid
|
|||
from sentry_sdk.integrations.asyncio import AsyncioIntegration
|
||||
from sqlalchemy import and_, delete, or_, select, update
|
||||
from sqlalchemy.dialects.postgresql import insert
|
||||
from sqlalchemy.engine import CursorResult
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
from sqlalchemy.sql import func
|
||||
|
||||
|
|
@ -832,10 +833,13 @@ class QueueManager:
|
|||
Clean up a specific work unit session by both work_unit_key and AQS ID.
|
||||
"""
|
||||
async with tracked_db("cleanup_work_unit") as db:
|
||||
result = await db.execute(
|
||||
delete(models.ActiveQueueSession)
|
||||
.where(models.ActiveQueueSession.id == aqs_id)
|
||||
.where(models.ActiveQueueSession.work_unit_key == work_unit_key)
|
||||
result = cast(
|
||||
CursorResult[Any],
|
||||
await db.execute(
|
||||
delete(models.ActiveQueueSession)
|
||||
.where(models.ActiveQueueSession.id == aqs_id)
|
||||
.where(models.ActiveQueueSession.work_unit_key == work_unit_key)
|
||||
),
|
||||
)
|
||||
await db.commit()
|
||||
return result.rowcount > 0
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ from collections.abc import Callable
|
|||
from typing import ParamSpec, TypeVar, overload
|
||||
|
||||
from fastapi import Request
|
||||
from langfuse import observe # pyright: ignore
|
||||
from langfuse import observe
|
||||
from rich import box
|
||||
from rich.console import Console, Group, RenderableType
|
||||
from rich.panel import Panel
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
import inspect
|
||||
import logging
|
||||
from collections.abc import Callable, Sequence
|
||||
from functools import wraps
|
||||
|
|
@ -70,7 +70,7 @@ def with_sentry_transaction(
|
|||
"""
|
||||
|
||||
def decorator(func: Callable[P, T]) -> Callable[P, T]:
|
||||
if asyncio.iscoroutinefunction(func):
|
||||
if inspect.iscoroutinefunction(func):
|
||||
|
||||
@wraps(func)
|
||||
async def async_wrapper(*args: P.args, **kwargs: P.kwargs) -> T:
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import logging
|
|||
import re
|
||||
from typing import Any
|
||||
|
||||
from json_repair import repair_json # pyright: ignore
|
||||
from json_repair import repair_json
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
# logging.getLogger("sqlalchemy.engine.Engine").disabled = True
|
||||
|
|
|
|||
|
|
@ -430,11 +430,7 @@ class ExplicitJudge:
|
|||
)
|
||||
for block in resp.content:
|
||||
if block.type == "tool_use":
|
||||
# block.input is typed as object, but we know it's a dict
|
||||
input_data = block.input
|
||||
if isinstance(input_data, dict):
|
||||
# Cast to dict[str, Any] for type checker
|
||||
return dict(input_data) # pyright: ignore[reportUnknownArgumentType]
|
||||
return dict(block.input)
|
||||
return {}
|
||||
|
||||
else: # AsyncOpenAI
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import threading
|
|||
import time
|
||||
from datetime import datetime, timezone
|
||||
from pathlib import Path
|
||||
from typing import Any, cast
|
||||
from typing import Any
|
||||
|
||||
import httpx
|
||||
from anthropic import AsyncAnthropic
|
||||
|
|
@ -418,16 +418,10 @@ class UnifiedTestExecutor:
|
|||
f"No tool use in judge response: {resp.content}"
|
||||
)
|
||||
|
||||
data: object = tool_use.input
|
||||
if not isinstance(data, dict):
|
||||
raise TestExecutionError(f"Tool input is not a dict: {data}")
|
||||
|
||||
typed_data = cast(dict[str, Any], data)
|
||||
passed: bool = typed_data.get("passed", False)
|
||||
data = tool_use.input
|
||||
passed = bool(data.get("passed", False))
|
||||
if passed != assertion.pass_if:
|
||||
raise TestExecutionError(
|
||||
f"LLM Judge failed: {typed_data.get('reasoning')}"
|
||||
)
|
||||
raise TestExecutionError(f"LLM Judge failed: {data.get('reasoning')}")
|
||||
|
||||
elif isinstance(assertion, ContainsAssertion):
|
||||
text = result_str if assertion.case_sensitive else result_str.lower()
|
||||
|
|
|
|||
Loading…
Reference in New Issue