Contracts (the shared language): - percept / state / context / utterance / render / audio / capabilities - Capability model instead of vendor schemas (see below) Providers (capability-based abstraction): - LLM + Embedding: OpenAI-compatible shape IS the standard, adopted directly - ASR: internal contract is an event stream (partial -> final), because /v1/audio/transcriptions has no partial and dialogue needs it for endpointing. OpenAI adapter degrades to supports_partial=False. - TTS: internal contract carries tags/emotion/style, because /v1/audio/speech has no paralinguistics and [laughter]/[breath] are the core of feeling alive. Unsupported providers are stripped AND reported via Degradation -- silent degradation is forbidden. - Avatar: no de-facto standard, custom RenderCmd protocol driven by State. Core: - mood: dynamical system, slow variables, negativity bias (grudge), numbing after prolonged negativity - bazi: four pillars -> numeric vector; 'ming' is data, not prose - projection: phi, system event -> in-world statement; uncovered events are counted as projection gaps Storage: - SQLite schema, three memory layers, dyad ledger - accessibility floor 0.03 (not 0): forgettable but still there Config split: - models.yaml is the ONLY place model versions live - character.yaml holds world rules / emotion params, no version numbers 58 tests pass; ruff clean.
29 lines
822 B
Python
29 lines
822 B
Python
"""Embedding provider 抽象。
|
|
|
|
这块 OpenAI 形状是够用的:/v1/embeddings 就是 input → vectors。
|
|
所以内部契约直接采用,不发明。
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from abc import abstractmethod
|
|
|
|
from ...contracts import Capabilities, Modality
|
|
from ..base import Provider
|
|
|
|
|
|
class EmbeddingProvider(Provider):
|
|
@abstractmethod
|
|
async def embed(self, texts: list[str]) -> list[list[float]]:
|
|
"""批量向量化。返回顺序必须与输入一致。"""
|
|
|
|
async def embed_one(self, text: str) -> list[float]:
|
|
return (await self.embed([text]))[0]
|
|
|
|
@property
|
|
def dim(self) -> int:
|
|
return int(self.capabilities.extra.get("dim", 0))
|
|
|
|
def _caps(self, dim: int) -> Capabilities:
|
|
return Capabilities(modality=Modality.VECTOR, extra={"dim": dim})
|