配置 SSOT(TOML + .env) 统一错误契约 Auth 与事务边界 Redis / Celery 可靠性:业务 Redis(DB/0)与 Celery broker/backend(DB/1)显式拆分;连接池、sync client 可观测性(OpenTelemetry + LGTM)
39 lines
1.1 KiB
Python
39 lines
1.1 KiB
Python
"""LLMProvider port — 大语言模型能力契约。"""
|
|
|
|
from collections.abc import AsyncIterator
|
|
from typing import Protocol, runtime_checkable
|
|
|
|
|
|
@runtime_checkable
|
|
class LLMProvider(Protocol):
|
|
async def complete(
|
|
self,
|
|
messages: list[dict],
|
|
*,
|
|
temperature: float = 0.7,
|
|
model: str | None = None,
|
|
max_tokens: int | None = None,
|
|
) -> str:
|
|
"""Single-turn completion, returns full response text.
|
|
|
|
Implementations MUST wrap underlying SDK calls with their own telemetry
|
|
(e.g. ``langchain_invoke_span``) so callers such as ``LlmGateway`` can
|
|
invoke ``complete()`` without adding a second observability layer.
|
|
|
|
``max_tokens`` when set is passed to the underlying chat API (adapter-specific).
|
|
"""
|
|
|
|
...
|
|
|
|
def stream(
|
|
self,
|
|
messages: list[dict],
|
|
*,
|
|
temperature: float = 0.7,
|
|
model: str | None = None,
|
|
max_tokens: int | None = None,
|
|
) -> AsyncIterator[str]:
|
|
"""Streaming completion, yields text chunks (async generator)."""
|
|
|
|
...
|