interplane.Get Omega
Read in your language

aien-sovereign-core-mv

AienOS host runtime: inference scheduling, paged KV state, the aien CLI and Spark verification tooling. Its inference engine is in alpha testing (DGX Spark GB10); Omega is the implementation destination.

Brought by drakestapleton

branch main Branches Tags History

aien-sovereign-core-mv / crates / spark-adapters / src / models.rs

237 lines · 8587 bytes Raw Blame History
1// SPDX-License-Identifier: Apache-2.0
2// Copyright 2026 Drake Stapleton (AIEN / aien-dev)
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15
16use serde::{Deserialize, Serialize};
17
18#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
19#[serde(rename_all = "snake_case")]
20pub enum ProviderType {
21 OpenAI,
22 Anthropic,
23 OpenRouter,
24 Gemini,
25 Groq,
26 Ollama,
27 DeepSeek,
28 Together,
29 Mistral,
30 ChatGPTWeb,
31 ClaudeWeb,
32 /// Local OpenAI-compatible model seat on port 18006. Accepts the old `local_max` id.
33 #[serde(alias = "local_max")]
34 LocalSeat,
35 EmbeddedNative,
36}
37
38impl ProviderType {
39 pub fn slug(&self) -> &'static str {
40 match self {
41 ProviderType::OpenAI => "openai",
42 ProviderType::Anthropic => "anthropic",
43 ProviderType::OpenRouter => "openrouter",
44 ProviderType::Gemini => "gemini",
45 ProviderType::Groq => "groq",
46 ProviderType::Ollama => "ollama",
47 ProviderType::DeepSeek => "deepseek",
48 ProviderType::Together => "together",
49 ProviderType::Mistral => "mistral",
50 ProviderType::ChatGPTWeb => "chatgpt_web",
51 ProviderType::ClaudeWeb => "claude_web",
52 ProviderType::LocalSeat => "local_seat",
53 ProviderType::EmbeddedNative => "embedded_native",
54 }
55 }
56
57 pub fn display_name(&self) -> &'static str {
58 match self {
59 ProviderType::OpenAI => "OpenAI",
60 ProviderType::Anthropic => "Anthropic",
61 ProviderType::OpenRouter => "OpenRouter (Multi-Model Gateway)",
62 ProviderType::Gemini => "Google Gemini",
63 ProviderType::Groq => "Groq LPU Engine",
64 ProviderType::Ollama => "Ollama Local Engine",
65 ProviderType::DeepSeek => "DeepSeek Cloud",
66 ProviderType::Together => "Together AI",
67 ProviderType::Mistral => "Mistral AI",
68 ProviderType::ChatGPTWeb => "ChatGPT Plus (Web Session)",
69 ProviderType::ClaudeWeb => "Claude Pro (Web Session)",
70 ProviderType::LocalSeat => "Local Model Seat (GB10, port 18006)",
71 ProviderType::EmbeddedNative => "Embedded Native (In-Process GB10/CPU)",
72 }
73 }
74
75 pub fn default_endpoint(&self) -> &'static str {
76 match self {
77 ProviderType::OpenAI => "https://api.openai.com/v1/chat/completions",
78 ProviderType::Anthropic => "https://api.anthropic.com/v1/messages",
79 ProviderType::OpenRouter => "https://openrouter.ai/api/v1/chat/completions",
80 ProviderType::Gemini => {
81 "https://generativelanguage.googleapis.com/v1beta/openai/chat/completions"
82 }
83 ProviderType::Groq => "https://api.groq.com/openai/v1/chat/completions",
84 ProviderType::Ollama => "http://127.0.0.1:11434/v1/chat/completions",
85 ProviderType::DeepSeek => "https://api.deepseek.com/v1/chat/completions",
86 ProviderType::Together => "https://api.together.xyz/v1/chat/completions",
87 ProviderType::Mistral => "https://api.mistral.ai/v1/chat/completions",
88 ProviderType::ChatGPTWeb => "https://chatgpt.com/backend-api/conversation",
89 ProviderType::ClaudeWeb => "https://claude.ai/api/organizations/chat_conversations",
90 ProviderType::LocalSeat => "http://127.0.0.1:18006/v1/chat/completions",
91 ProviderType::EmbeddedNative => "in-process://native-transformer",
92 }
93 }
94
95 pub fn key_name(&self) -> Option<&'static str> {
96 match self {
97 ProviderType::OpenAI => Some("OPENAI_API_KEY"),
98 ProviderType::Anthropic => Some("ANTHROPIC_API_KEY"),
99 ProviderType::OpenRouter => Some("OPENROUTER_API_KEY"),
100 ProviderType::Gemini => Some("GEMINI_API_KEY"),
101 ProviderType::Groq => Some("GROQ_API_KEY"),
102 ProviderType::Ollama => None,
103 ProviderType::DeepSeek => Some("DEEPSEEK_API_KEY"),
104 ProviderType::Together => Some("TOGETHER_API_KEY"),
105 ProviderType::Mistral => Some("MISTRAL_API_KEY"),
106 ProviderType::ChatGPTWeb => Some("CHATGPT_SESSION_TOKEN"),
107 ProviderType::ClaudeWeb => Some("CLAUDE_SESSION_KEY"),
108 ProviderType::LocalSeat => None,
109 ProviderType::EmbeddedNative => None,
110 }
111 }
112
113 pub fn key_aliases(&self) -> &'static [&'static str] {
114 match self {
115 ProviderType::OpenAI => &["OPENAI_API_KEY"],
116 ProviderType::Anthropic => &["ANTHROPIC_API_KEY"],
117 ProviderType::OpenRouter => &["OPENROUTER_API_KEY"],
118 ProviderType::Gemini => &["GEMINI_API_KEY"],
119 ProviderType::Groq => &["GROQ_API_KEY"],
120 ProviderType::Ollama => &[],
121 ProviderType::DeepSeek => &["DEEPSEEK_API_KEY"],
122 ProviderType::Together => &["TOGETHER_API_KEY"],
123 ProviderType::Mistral => &["MISTRAL_API_KEY"],
124 ProviderType::ChatGPTWeb => &["CHATGPT_SESSION_TOKEN", "OPENAI_WEB_TOKEN"],
125 ProviderType::ClaudeWeb => &["CLAUDE_SESSION_KEY", "CLAUDE_WEB_SESSION_KEY"],
126 ProviderType::LocalSeat => &[],
127 ProviderType::EmbeddedNative => &[],
128 }
129 }
130}
131
132#[derive(Debug, Clone, Serialize, Deserialize)]
133pub struct AdapterSpec {
134 pub id: String,
135 pub name: String,
136 pub provider: ProviderType,
137 pub endpoint: String,
138 pub model_id: String,
139 pub context_length: usize,
140 pub is_available: bool,
141 pub requires_key: bool,
142 pub is_resident: bool,
143}
144
145#[derive(Debug, Clone, Serialize, Deserialize)]
146pub struct ChatMessage {
147 pub role: String,
148 pub content: String,
149 #[serde(skip_serializing_if = "Option::is_none")]
150 pub reasoning: Option<String>,
151}
152
153#[derive(Debug, Clone, Serialize, Deserialize)]
154pub struct NormalizedChunk {
155 pub content: String,
156 pub reasoning: String,
157 pub is_done: bool,
158}
159
160#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
161#[serde(rename_all = "snake_case")]
162pub enum TaskType {
163 CodeSynthesis,
164 SystemArchitecture,
165 ReasoningTrace,
166 RefactorLogic,
167 VerificationHarness,
168}
169
170#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
171#[serde(rename_all = "snake_case")]
172pub enum VerificationStrategy {
173 CompilerCheck,
174 JsonSchema,
175 UnslopStrict,
176 DualConsensus,
177}
178
179#[derive(Debug, Clone, Serialize, Deserialize)]
180pub struct VerificationOutcome {
181 pub passed: bool,
182 pub score: f32,
183 pub rule_violations: Vec<String>,
184 pub compiler_output: Option<String>,
185}
186
187#[derive(Debug, Clone, Serialize, Deserialize)]
188pub struct Rollout {
189 pub provider: ProviderType,
190 pub model_id: String,
191 pub content: String,
192 pub reasoning: Option<String>,
193 pub duration_ms: u64,
194 pub token_count: usize,
195 pub verification: VerificationOutcome,
196}
197
198#[derive(Debug, Clone, Serialize, Deserialize)]
199pub struct DistillTask {
200 pub id: String,
201 pub task_type: TaskType,
202 pub prompt: String,
203 pub system_prompt: Option<String>,
204 pub teacher_model: String,
205 pub student_model: Option<String>,
206 pub verification_strategy: VerificationStrategy,
207 pub commit_to_cortex: bool,
208}
209
210#[derive(Debug, Clone, Serialize, Deserialize)]
211pub struct DistillationRecord {
212 pub task_id: String,
213 pub task_type: TaskType,
214 pub prompt: String,
215 pub system_prompt: Option<String>,
216 pub teacher_rollout: Rollout,
217 pub student_rollout: Option<Rollout>,
218 pub chosen: String,
219 pub chosen_reasoning: Option<String>,
220 pub rejected: Option<String>,
221 pub rejected_reasoning: Option<String>,
222 pub preference_delta: f32,
223 pub durable_memory_committed: bool,
224 pub cortex_entity_id: Option<String>,
225 pub created_at: String,
226}
227
228impl DistillationRecord {
229 pub fn has_dpo_pair(&self) -> bool {
230 self.preference_delta > 0.0
231 && self
232 .rejected
233 .as_deref()
234 .map(|rej| rej != self.chosen.as_str())
235 .unwrap_or(false)
236 }
237}