Spaces:
Sleeping
Sleeping
File size: 2,661 Bytes
0d03152 2af1cca 0d03152 2af1cca d5149c9 0d03152 6c1463d 0d03152 6c1463d d5149c9 0d03152 2af1cca 6de6c5e d5149c9 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | """FastAPI request/response models."""
from __future__ import annotations
from typing import Any, Dict, List, Literal, Optional
from pydantic import BaseModel, Field
class QueryRequestModel(BaseModel):
query: str = Field(..., min_length=1)
top_k: int = Field(5, ge=1, le=50)
use_llm: bool = True
use_rerank: bool = True
stream: bool = False
include_citations: bool = True
provider: Optional[str] = None
model: Optional[str] = None
reranker_model: Optional[str] = None
provider_api_key: Optional[str] = None
session_id: Optional[str] = None
knowledge_scope: Literal["global", "session", "both"] = "global"
embedding_profile: Optional[str] = None
class CitationModel(BaseModel):
raw_id: str
chunk_id: str
resolved: bool
title: Optional[str] = None
source: Optional[str] = None
verification_score: float = 0.0
verification: str = "unresolved"
class RetrievedChunkModel(BaseModel):
id: str
score: float = 0.0
source: str = "hybrid"
confidence: float = 0.0
metadata: Dict[str, Any] = Field(default_factory=dict)
preview: str = ""
class TruthfulnessModel(BaseModel):
nli_faithfulness: float = 0.0
citation_groundedness: float = 0.0
uncited_claims: int = 0
score: float = 0.0
class QueryResponseModel(BaseModel):
query: str
provider: str
model: str
answer: str = ""
processing_time_ms: float = 0.0
cached: bool = False
validation_issues: List[str] = Field(default_factory=list)
citations: List[CitationModel] = Field(default_factory=list)
retrieved: List[RetrievedChunkModel] = Field(default_factory=list)
truthfulness: Optional[TruthfulnessModel] = None
embedding_profile: Optional[str] = None
class HealthModel(BaseModel):
status: str
collection: str
class MetricsModel(BaseModel):
cache_ttl_seconds: int
available_providers: List[str]
class LLMConfigModel(BaseModel):
"""Public LLM routing options for UI clients (no secrets)."""
default_provider: str
default_model_by_provider: Dict[str, str]
allowed_models_by_provider: Dict[str, List[str]]
provider_key_configured: Dict[str, bool] = Field(
default_factory=dict,
description="Whether server-side API key env vars are configured for each provider",
)
demo_mode: bool = Field(
False,
description="True when API is running in hosted demo profile",
)
class RuntimeConfigModel(BaseModel):
chunking_default_strategy: str
chunking_allowed_strategies: List[str]
embedding_default_profile: str
embedding_profiles: Dict[str, Dict[str, Any]]
|