"""LLM Provider 基础抽象层""" from abc import ABC, abstractmethod from dataclasses import dataclass @dataclass class LLMMessage: role: str # "system", "user", "assistant" content: str @dataclass class LLMResponse: content: str model: str usage: dict # {"total_tokens": int, "prompt_tokens": int, "completion_tokens": int} class BaseLLMProvider(ABC): """LLM Provider 抽象基类""" @abstractmethod async def chat(self, messages: list[LLMMessage]) -> LLMResponse: """非流式对话""" pass @abstractmethod async def chat_stream(self, messages: list[LLMMessage]) -> str: """流式对话,返回 token 异步生成器""" pass @abstractmethod async def embed(self, texts: list[str]) -> list[list[float]]: """生成嵌入向量""" pass