How jjjjstiyyyy/my-llm works
my-llm-py is an async LLM protocol adapter: an application supplies messages in a selected input/output format, configures an upstream provider and model, and receives translated messages or stream events. The principal path runs through profile resolution, request validation and conversion, a protocol-specific transport, then decoding and stream assembly. The graph also preserves offline conversion, semantic-loss handling, middleware I/O, caching, and protocol-specific implementations. Edges follow README statements or SOURCE INDEX references; unsampled subsystem links are omitted where their caller is not evidenced.
Main entry points: converter.py Format converter · my_llm.py MyLLM · decoder.py Native decoder · codec.py Codec registry
Components 25
Application entry
- MyLLM
src/my_llm/my_llm.py
Profiles and middleware
- Profile resolution
src/my_llm/profile/resolution.py - Profile declarations
src/my_llm/profile/configuration.py - Middleware models
src/my_llm/middleware/models.py - Middleware validation
src/my_llm/middleware/validation.py - Middleware stream
src/my_llm/middleware/stream.py
Conversion core
- Format converter
src/my_llm/codec/converter.py - Codec registry
src/my_llm/codec/base/codec.py - Native encoder
src/my_llm/codec/base/encoder.py - Native decoder
src/my_llm/codec/base/decoder.py - Shared conversion
src/my_llm/codec/shared/conversion.py - Input helpers
src/my_llm/codec/shared/input.py - Capability rules
src/my_llm/codec/shared/capabilities.py - Stream operations
src/my_llm/codec/shared/stream.py - Data views
src/my_llm/basic/data.py - Semantic-loss policy
src/my_llm/basic/semantic_loss.py - Compiled cache
src/my_llm/cache/compiled_cache.py
Protocol adapters
- OpenAI Chat
src/my_llm/codec/openai/chat - OpenAI Responses
src/my_llm/codec/openai/responses - Anthropic Messages
src/my_llm/codec/anthropic
Runtime and state
- Generation state
src/my_llm/runtime/state.py - Message stream
src/my_llm/runtime/message_stream.py - Message cache
src/my_llm/cache/message_cache.py
Other components
- Application
- Provider APIs
Connections 31
- Application → MyLLM: calls generate
README.md - MyLLM → Profile resolution: resolves settings
src/my_llm/my_llm.py - Profile resolution → Profile declarations: uses declarations
src/my_llm/profile/resolution.py - MyLLM → Format converter: converts requests
src/my_llm/my_llm.py - MyLLM → Middleware models: uses middleware
src/my_llm/my_llm.py - MyLLM → Middleware stream: uses stream types
src/my_llm/my_llm.py - Format converter → Codec registry: uses codecs
src/my_llm/codec/converter.py - Format converter → Native encoder: uses encoders
src/my_llm/codec/converter.py - Format converter → Native decoder: uses decoders
src/my_llm/codec/converter.py - Format converter → Middleware models: converts middleware
src/my_llm/codec/converter.py - Format converter → Middleware validation: validates values
src/my_llm/codec/converter.py - Native decoder → Compiled cache: uses schemas
src/my_llm/codec/base/decoder.py - Native decoder → Capability rules: filters capabilities
src/my_llm/codec/base/decoder.py - Native decoder → Input helpers: uses input helpers
src/my_llm/codec/base/decoder.py - Native decoder → Semantic-loss policy: reports losses
src/my_llm/codec/base/decoder.py - OpenAI Chat → Codec registry: implements codec
src/my_llm/codec/openai/chat/codec.py - OpenAI Responses → Codec registry: implements codec
src/my_llm/codec/openai/responses/codec.py - Anthropic Messages → Codec registry: implements codec
src/my_llm/codec/anthropic/codec.py - Format converter → OpenAI Chat: selects protocol
- Format converter → OpenAI Responses: selects protocol
- Format converter → Anthropic Messages: selects protocol
- OpenAI Chat → Provider APIs: sends requests
- OpenAI Responses → Provider APIs: sends requests
- Anthropic Messages → Provider APIs: sends requests
- MyLLM → Generation state: manages generation
src/my_llm/my_llm.py - MyLLM → Message stream: returns stream
src/my_llm/my_llm.py - MyLLM → Message cache: uses cache
- Application → Format converter: converts offline
README.md - Application → Middleware models: uses middleware I/O
README.md - Format converter → Shared conversion: uses shared helpers
src/my_llm/codec/converter.py - Format converter → Stream operations: converts stream events
src/my_llm/codec/converter.py