Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/app/endpoints/responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import time
from collections.abc import AsyncIterator, Sequence
from datetime import UTC, datetime
from typing import Annotated, Any, Final, NoReturn, Optional, cast
from typing import TYPE_CHECKING, Annotated, Any, Final, NoReturn, Optional, cast

from fastapi import APIRouter, BackgroundTasks, Depends, HTTPException, Request
from fastapi.responses import StreamingResponse
Expand Down Expand Up @@ -55,7 +55,6 @@
)
from models.api.responses.error.bases import AbstractErrorResponse
from models.api.responses.successful import ResponsesResponse
from models.common.moderation import ShieldModerationBlocked
from models.common.responses.contexts import ResponsesContext
from models.common.responses.responses_api_params import ResponsesApiParams
from models.common.responses.types import ResponseInput, ResponseMessage
Expand Down Expand Up @@ -129,6 +128,9 @@
build_rag_context,
)

if TYPE_CHECKING:
from models.common.moderation import ShieldModerationBlocked

logger = get_logger(__name__)
tracer = trace.get_tracer(__name__)
router = APIRouter(tags=["responses"])
Expand Down
6 changes: 4 additions & 2 deletions src/app/endpoints/streaming_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import asyncio
import datetime
from collections.abc import AsyncIterator
from typing import Annotated, Optional
from typing import TYPE_CHECKING, Annotated, Optional

from fastapi import APIRouter, Depends, HTTPException, Request
from fastapi.responses import StreamingResponse
Expand Down Expand Up @@ -42,7 +42,6 @@
from models.common.query import Attachment
from models.common.responses.contexts import ResponseGeneratorContext
from models.common.responses.responses_api_params import ResponsesApiParams
from models.common.turn_summary import ContextStatus
from models.config import Action
from utils.agents.streaming import (
generate_agent_response,
Expand Down Expand Up @@ -93,6 +92,9 @@
from utils.types import Responses
from utils.vector_search import build_rag_context

if TYPE_CHECKING:
from models.common.turn_summary import ContextStatus

logger = get_logger(__name__)
tracer = trace.get_tracer(__name__)
router = APIRouter(tags=["streaming_query"])
Expand Down
5 changes: 3 additions & 2 deletions src/knowledge/capability.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@

from collections.abc import Sequence
from dataclasses import dataclass
from typing import Optional
from typing import TYPE_CHECKING, Optional

from pydantic_ai.capabilities import AbstractCapability
from pydantic_ai.tools import AgentDepsT
from sentence_transformers import CrossEncoder

from knowledge.sources.base import KnowledgeSource
if TYPE_CHECKING:
from knowledge.sources.base import KnowledgeSource


@dataclass
Expand Down
4 changes: 3 additions & 1 deletion src/knowledge/reranker.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@

import logging
from dataclasses import replace
from typing import TYPE_CHECKING

from sentence_transformers import CrossEncoder

from knowledge.types import KnowledgeMatch
if TYPE_CHECKING:
from knowledge.types import KnowledgeMatch

logger = logging.getLogger(__name__)

Expand Down
6 changes: 4 additions & 2 deletions src/providers/inference/azure/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from __future__ import annotations

from typing import Any
from typing import TYPE_CHECKING, Any

from azure.identity.aio import ClientSecretCredential, get_bearer_token_provider
from openai import AsyncAzureOpenAI
Expand All @@ -21,7 +21,9 @@
from providers.inference.model_type_inference import (
infer_model_type_from_pai_known_names,
)
from providers.inference.types import ModelType

if TYPE_CHECKING:
from providers.inference.types import ModelType


class AzureInferenceProvider(
Expand Down
6 changes: 4 additions & 2 deletions src/providers/inference/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from __future__ import annotations

from abc import ABC, abstractmethod
from typing import Any, Generic, Literal, Optional, TypeVar, overload
from typing import TYPE_CHECKING, Any, Generic, Literal, Optional, TypeVar, overload

from pydantic_ai.embeddings import EmbeddingModel
from pydantic_ai.models import Model
Expand All @@ -17,7 +17,9 @@
)
from providers.inference.catalog import CatalogModel, DiscoveredModel
from providers.inference.errors import ModelNotAvailableError
from providers.inference.types import ModelType, ProviderId

if TYPE_CHECKING:
from providers.inference.types import ModelType, ProviderId

logger = get_logger(__name__)

Expand Down
6 changes: 4 additions & 2 deletions src/providers/inference/bedrock/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import asyncio
import os
from typing import Any, Optional
from typing import TYPE_CHECKING, Any, Optional

import boto3
from botocore.client import BaseClient
Expand All @@ -23,7 +23,9 @@
from providers.inference.bedrock.specs import FoundationModelSummary
from providers.inference.catalog import CatalogModel, DiscoveredModel
from providers.inference.errors import ModelTypeNotSupportedError
from providers.inference.types import ModelType

if TYPE_CHECKING:
from providers.inference.types import ModelType


class _BearerTokenSession(Session):
Expand Down
5 changes: 3 additions & 2 deletions src/providers/inference/model_type_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

from __future__ import annotations

from typing import Optional, TypeAliasType, get_args
from typing import TYPE_CHECKING, Optional, TypeAliasType, get_args

from pydantic_ai.embeddings import KnownEmbeddingModelName
from pydantic_ai.models import KnownModelName

from providers.inference.types import ModelType
if TYPE_CHECKING:
from providers.inference.types import ModelType


def _model_ids_from_known_names(known_names: TypeAliasType) -> frozenset[str]:
Expand Down
6 changes: 4 additions & 2 deletions src/providers/inference/openai/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from __future__ import annotations

from typing import Any
from typing import TYPE_CHECKING, Any

from pydantic_ai.embeddings import EmbeddingModel
from pydantic_ai.embeddings.openai import OpenAIEmbeddingModel
Expand All @@ -18,7 +18,9 @@
from providers.inference.model_type_inference import (
infer_model_type_from_pai_known_names,
)
from providers.inference.types import ModelType

if TYPE_CHECKING:
from providers.inference.types import ModelType


class OpenAIInferenceProvider(
Expand Down
12 changes: 7 additions & 5 deletions src/providers/inference/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,22 @@

from __future__ import annotations

from typing import Any, Final, Optional
from typing import TYPE_CHECKING, Any, Final, Optional

from models.config import InferenceConfiguration
from providers.inference.azure.provider import AzureInferenceProvider
from providers.inference.base import InferenceProvider
from providers.inference.bedrock.provider import BedrockInferenceProvider
from providers.inference.catalog import CatalogModel
from providers.inference.errors import ProviderNotFoundError
from providers.inference.openai.provider import OpenAIInferenceProvider
from providers.inference.types import ModelType, ProviderId, ProviderType
from providers.inference.vertexai.provider import VertexAIInferenceProvider
from providers.inference.watsonx.provider import WatsonxInferenceProvider
from utils.types import Singleton

if TYPE_CHECKING:
from models.config import InferenceConfiguration
from providers.inference.base import InferenceProvider
from providers.inference.catalog import CatalogModel
from providers.inference.types import ModelType, ProviderId, ProviderType

PROVIDER_CLASSES: Final[dict[ProviderType, type[InferenceProvider[Any, Any]]]] = {
"openai": OpenAIInferenceProvider,
"azure": AzureInferenceProvider,
Expand Down
6 changes: 4 additions & 2 deletions src/providers/inference/vertexai/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from __future__ import annotations

from typing import Any
from typing import TYPE_CHECKING, Any

from pydantic_ai.embeddings import EmbeddingModel
from pydantic_ai.embeddings.google import GoogleEmbeddingModel
Expand All @@ -18,7 +18,9 @@
from providers.inference.model_type_inference import (
infer_model_type_from_pai_known_names,
)
from providers.inference.types import ModelType

if TYPE_CHECKING:
from providers.inference.types import ModelType


class VertexAIInferenceProvider(
Expand Down
6 changes: 4 additions & 2 deletions src/providers/inference/watsonx/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from __future__ import annotations

import asyncio
from typing import Any, Optional
from typing import TYPE_CHECKING, Any, Optional

from pydantic_ai.embeddings import EmbeddingModel
from pydantic_ai.embeddings.openai import OpenAIEmbeddingModel
Expand All @@ -15,10 +15,12 @@
from providers.inference.base import InferenceProvider
from providers.inference.catalog import CatalogModel, DiscoveredModel
from providers.inference.errors import ModelTypeNotSupportedError
from providers.inference.types import ModelType
from providers.inference.watsonx.pai_provider import WatsonxProvider
from providers.inference.watsonx.specs import FoundationModelSpecsResponse

if TYPE_CHECKING:
from providers.inference.types import ModelType


class WatsonxInferenceProvider(
InferenceProvider[WatsonxInferenceProviderEntry, WatsonxProvider]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from collections.abc import Sequence
from dataclasses import dataclass, field
from string import Template
from typing import Optional
from typing import TYPE_CHECKING, Optional
from uuid import uuid4

from pydantic_ai import AgentRunResult, RunContext
Expand All @@ -35,9 +35,6 @@
ShieldModerationPassed,
ShieldModerationResult,
)
from models.config import (
QuestionValidityConfig,
)
from pydantic_ai_lightspeed.capabilities.base import AbstractSafetyCapability
from pydantic_ai_lightspeed.capabilities.utils import (
extract_conversation_id,
Expand All @@ -46,6 +43,11 @@
from pydantic_ai_lightspeed.ogx import OgxResponsesModel
from utils.conversations import append_turn_to_conversation

if TYPE_CHECKING:
from models.config import (
QuestionValidityConfig,
)

logger = get_logger(__name__)

SUBJECT_REJECTED = "REJECTED"
Expand Down
6 changes: 4 additions & 2 deletions src/pydantic_ai_lightspeed/ogx/_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from collections import defaultdict
from collections.abc import AsyncIterator, Callable
from contextlib import asynccontextmanager
from typing import Any, Final, Optional, cast
from typing import TYPE_CHECKING, Any, Final, Optional, cast

from ogx.core.library_client import AsyncOGXAsLibraryClient
from ogx_client import AsyncOgxClient
Expand All @@ -48,9 +48,11 @@
from pydantic_ai.settings import ModelSettings

from log import get_logger
from models.common.responses.responses_api_params import ResponsesApiParams
from pydantic_ai_lightspeed.ogx._provider import OgxProvider

if TYPE_CHECKING:
from models.common.responses.responses_api_params import ResponsesApiParams

logger = get_logger(__name__)

_LLS_RESPONSES_EXTRA_FIELDS: Final[frozenset[str]] = frozenset(
Expand Down
9 changes: 7 additions & 2 deletions src/quota/quota_limiter.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,20 @@
import datetime
import sqlite3
from abc import ABC, abstractmethod
from typing import Optional
from typing import TYPE_CHECKING, Optional

import psycopg2

from log import get_logger
from models.config import PostgreSQLDatabaseConfiguration, SQLiteDatabaseConfiguration
from quota.connect_pg import connect_pg
from quota.connect_sqlite import connect_sqlite

if TYPE_CHECKING:
from models.config import (
PostgreSQLDatabaseConfiguration,
SQLiteDatabaseConfiguration,
)

logger = get_logger(__name__)


Expand Down
8 changes: 5 additions & 3 deletions src/utils/agents/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import time
from enum import StrEnum
from typing import Optional
from typing import TYPE_CHECKING, Optional

from fastapi import HTTPException
from ogx_client import ApiException, AsyncOgxClient
Expand All @@ -25,8 +25,6 @@
PromptTooLongResponse,
)
from models.common.agents import AgentTurnAccumulator
from models.common.query import Attachment
from models.common.responses.responses_api_params import ResponsesApiParams
from models.common.turn_summary import TurnSummary
from utils.agents.error_handler import map_agent_inference_error
from utils.agents.tool_processor import (
Expand Down Expand Up @@ -55,6 +53,10 @@
from utils.responses import extract_vector_store_ids_from_tools
from utils.token_counter import TokenCounter

if TYPE_CHECKING:
from models.common.query import Attachment
from models.common.responses.responses_api_params import ResponsesApiParams

logger = get_logger(__name__)
tracer = trace.get_tracer(__name__)

Expand Down
10 changes: 6 additions & 4 deletions src/utils/agents/streaming.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import time
from collections.abc import AsyncIterator
from functools import singledispatch
from typing import Any, Final, Optional
from typing import TYPE_CHECKING, Any, Final, Optional

from fastapi import HTTPException
from ogx_client import ApiException
Expand Down Expand Up @@ -43,9 +43,6 @@
ToolResultStreamPayload,
TurnCompleteStreamPayload,
)
from models.common.query import Attachment
from models.common.responses.contexts import ResponseGeneratorContext
from models.common.responses.responses_api_params import ResponsesApiParams
from models.common.turn_summary import ContextStatus, TurnSummary
from utils.agents.error_handler import map_agent_inference_error
from utils.agents.query import (
Expand Down Expand Up @@ -92,6 +89,11 @@
register_interrupt_callback,
)

if TYPE_CHECKING:
from models.common.query import Attachment
from models.common.responses.contexts import ResponseGeneratorContext
from models.common.responses.responses_api_params import ResponsesApiParams

type AgentDispatchEvent = AgentStreamEvent | AgentRunResultEvent

logger = get_logger(__name__)
Expand Down
Loading
Loading