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
aien-sovereign-core-mv / crates / spark-adapters / src / providers / mod.rs
| 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 | |
| 16 | pub mod anthropic; |
| 17 | pub mod openai; |
| 18 | |
| 19 | pub use anthropic::*; |
| 20 | pub use openai::*; |
| 21 | |
| 22 | use crate::models::{ChatMessage, ProviderType}; |
| 23 | use reqwest::Client; |
| 24 | |
| 25 | pub async fn call_provider_unary( |
| 26 | client: &Client, |
| 27 | provider: ProviderType, |
| 28 | endpoint: &str, |
| 29 | model: &str, |
| 30 | api_key: Option<&str>, |
| 31 | messages: &[ChatMessage], |
| 32 | temperature: Option<f32>, |
| 33 | ) -> Result<(String, Option<String>, usize), String> { |
| 34 | if provider == ProviderType::EmbeddedNative || endpoint.starts_with("in-process://") { |
| 35 | return Err("EmbeddedNative provider must be executed via in-process EmbeddedInferenceBackend, not HTTP adapter transport".to_string()); |
| 36 | } |
| 37 | |
| 38 | match provider { |
| 39 | ProviderType::Anthropic => { |
| 40 | let key = api_key.ok_or_else(|| "Anthropic requires an API key".to_string())?; |
| 41 | call_anthropic_unary(client, endpoint, model, key, messages, temperature).await |
| 42 | } |
| 43 | ProviderType::OpenAI |
| 44 | | ProviderType::OpenRouter |
| 45 | | ProviderType::Gemini |
| 46 | | ProviderType::Groq |
| 47 | | ProviderType::DeepSeek |
| 48 | | ProviderType::Together |
| 49 | | ProviderType::Mistral |
| 50 | | ProviderType::Ollama |
| 51 | | ProviderType::LocalSeat => { |
| 52 | call_openai_unary(client, endpoint, model, api_key, messages, temperature).await |
| 53 | } |
| 54 | ProviderType::ChatGPTWeb | ProviderType::ClaudeWeb => { |
| 55 | let key = api_key.ok_or_else(|| { |
| 56 | format!( |
| 57 | "{} requires session token in hardware vault", |
| 58 | provider.display_name() |
| 59 | ) |
| 60 | })?; |
| 61 | call_openai_unary(client, endpoint, model, Some(key), messages, temperature).await |
| 62 | } |
| 63 | ProviderType::EmbeddedNative => unreachable!(), |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | #[cfg(test)] |
| 68 | mod tests { |
| 69 | use super::*; |
| 70 | |
| 71 | #[tokio::test] |
| 72 | async fn test_embedded_native_rejects_http_transport() { |
| 73 | let client = Client::new(); |
| 74 | let msgs = vec![ChatMessage { |
| 75 | role: "user".to_string(), |
| 76 | content: "ping".to_string(), |
| 77 | reasoning: None, |
| 78 | }]; |
| 79 | let res = call_provider_unary( |
| 80 | &client, |
| 81 | ProviderType::EmbeddedNative, |
| 82 | "in-process://native-transformer", |
| 83 | "tinyllama", |
| 84 | None, |
| 85 | &msgs, |
| 86 | Some(0.0), |
| 87 | ) |
| 88 | .await; |
| 89 | |
| 90 | assert!(res.is_err()); |
| 91 | let err = res.unwrap_err(); |
| 92 | assert!(err.contains( |
| 93 | "EmbeddedNative provider must be executed via in-process EmbeddedInferenceBackend" |
| 94 | )); |
| 95 | } |
| 96 | } |