api.services.ai.providers.base¶
Provider-neutral request/result: features describe what they need once, each provider translates it to its own API.
Exceptions¶
A call that failed: the service moves on to the next AI model. |
Classes¶
Functions¶
|
(stable system prompt, the AI model's own directives or None). |
|
A JSON answer cut by the token limit (often eaten by the model's own |
Module Contents¶
- class api.services.ai.providers.base.AIRequest¶
- system: str¶
- user: list[dict[str, str]]¶
- max_tokens: int = 4000¶
- output_schema: dict[str, Any] | None = None¶
- schema_name: str = 'result'¶
- web: bool = False¶
- thinking: bool = False¶
- effort: Literal['low', 'medium', 'high'] = 'medium'¶
- cache_system: bool = False¶
- property images: int¶
- class api.services.ai.providers.base.AIResult¶
- text: str¶
- served_model: str¶
- stop_reason: str | None = None¶
- input_tokens: int = 0¶
- output_tokens: int = 0¶
- cache_read_tokens: int = 0¶
- cache_write_tokens: int = 0¶
- web_searches: int = 0¶
- cost_usd: float = 0.0¶
- request_id: str | None = None¶
- sources: list[dict[str, Any]] = []¶
- exception api.services.ai.providers.base.ProviderError(code: str, message: str)¶
Bases:
ExceptionA call that failed: the service moves on to the next AI model.
code: rate_limited | overloaded | no_credit | refused | timeout | connection | invalid_response | truncated | bad_request | error.- code¶
- message¶
- class api.services.ai.providers.base.AIProvider¶
Bases:
Protocol- name: str¶
- configured() bool¶
- generate(profile: api.services.ai.settings.ModelProfile, request: AIRequest) AIResult¶
- api.services.ai.providers.base.system_with_directives(request: AIRequest, profile: api.services.ai.settings.ModelProfile) tuple[str, str | None]¶
(stable system prompt, the AI model’s own directives or None).
- api.services.ai.providers.base.truncated(limit: int, reasoning_tokens: int | None = None) ProviderError¶
A JSON answer cut by the token limit (often eaten by the model’s own reasoning): useless, the service moves on to the next AI model.