Skip to main content

sim_codec_chat/providers/
profile.rs

1//! Open provider-codec profile records.
2//!
3//! These values are ordinary data owned by the codec crate. Provider identity
4//! stays outside the kernel so new providers can be added without expanding a
5//! closed enum in `sim-kernel`.
6
7use sim_kernel::Symbol;
8
9/// Provider request-body family.
10#[derive(Clone, Copy, Debug, PartialEq, Eq)]
11pub enum RequestWire {
12    /// OpenAI Responses API request shape.
13    OpenAiResponses,
14    /// OpenAI chat-completions request shape.
15    OpenAiChat,
16    /// Anthropic Messages request shape.
17    AnthropicMessages,
18    /// Ollama `/api/chat` request shape.
19    OllamaChat,
20}
21
22/// Provider streaming frame family.
23#[derive(Clone, Copy, Debug, PartialEq, Eq)]
24pub enum StreamWire {
25    /// Provider has no streaming frame shape in this profile.
26    None,
27    /// Server-sent-event frames.
28    Sse,
29    /// Newline-delimited JSON frames.
30    Ndjson,
31}
32
33/// Data profile for a provider codec.
34#[derive(Clone, Debug, PartialEq, Eq)]
35pub struct CodecProfile {
36    /// Runtime codec symbol such as `codec:openai`.
37    pub codec: Symbol,
38    /// Open provider id such as `openai` or `ollama`.
39    pub provider: Symbol,
40    /// Request wire shape accepted by the provider.
41    pub request_wire: RequestWire,
42    /// Stream frame shape emitted by the provider.
43    pub stream_wire: StreamWire,
44}
45
46impl CodecProfile {
47    /// Builds a provider profile from its open data fields.
48    pub fn new(
49        codec: Symbol,
50        provider: Symbol,
51        request_wire: RequestWire,
52        stream_wire: StreamWire,
53    ) -> Self {
54        Self {
55            codec,
56            provider,
57            request_wire,
58            stream_wire,
59        }
60    }
61}
62
63/// Profile for the native OpenAI provider codec.
64pub fn openai_profile() -> CodecProfile {
65    CodecProfile::new(
66        Symbol::qualified("codec", "openai"),
67        Symbol::new("openai"),
68        RequestWire::OpenAiChat,
69        StreamWire::Sse,
70    )
71}
72
73/// Profile for the native Anthropic provider codec.
74pub fn anthropic_profile() -> CodecProfile {
75    CodecProfile::new(
76        Symbol::qualified("codec", "anthropic"),
77        Symbol::new("anthropic"),
78        RequestWire::AnthropicMessages,
79        StreamWire::Sse,
80    )
81}
82
83/// Profile for the native Ollama provider codec.
84pub fn ollama_profile() -> CodecProfile {
85    CodecProfile::new(
86        Symbol::qualified("codec", "ollama"),
87        Symbol::new("ollama"),
88        RequestWire::OllamaChat,
89        StreamWire::Ndjson,
90    )
91}
92
93/// Profile for the native LM Studio provider codec.
94pub fn lm_studio_profile() -> CodecProfile {
95    CodecProfile::new(
96        Symbol::qualified("codec", "lm-studio"),
97        Symbol::new("lm-studio"),
98        RequestWire::OpenAiChat,
99        StreamWire::Sse,
100    )
101}
102
103/// Profile for the native Lemonade provider codec.
104pub fn lemonade_profile() -> CodecProfile {
105    CodecProfile::new(
106        Symbol::qualified("codec", "lemonade"),
107        Symbol::new("lemonade"),
108        RequestWire::OpenAiChat,
109        StreamWire::Sse,
110    )
111}