2026-03-18 17:18:23 +08:00
|
|
|
"""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,
|
2026-04-30 09:17:01 +08:00
|
|
|
max_tokens: int | None = None,
|
2026-03-18 17:18:23 +08:00
|
|
|
) -> str:
|
2026-04-30 09:17:01 +08:00
|
|
|
"""Single-turn completion, returns full response text.
|
|
|
|
|
|
|
|
|
|
``max_tokens`` when set is passed to the underlying chat API (adapter-specific).
|
|
|
|
|
"""
|
|
|
|
|
|
2026-03-18 17:18:23 +08:00
|
|
|
...
|
|
|
|
|
|
|
|
|
|
def stream(
|
|
|
|
|
self,
|
|
|
|
|
messages: list[dict],
|
|
|
|
|
*,
|
|
|
|
|
temperature: float = 0.7,
|
|
|
|
|
model: str | None = None,
|
2026-04-30 09:17:01 +08:00
|
|
|
max_tokens: int | None = None,
|
2026-03-18 17:18:23 +08:00
|
|
|
) -> AsyncIterator[str]:
|
|
|
|
|
"""Streaming completion, yields text chunks (async generator)."""
|
2026-04-30 09:17:01 +08:00
|
|
|
|
2026-03-18 17:18:23 +08:00
|
|
|
...
|