std.ml — Universal AI Model Hub & SIMD Tensor Engine
Universal client connectors for frontier AI models (OpenAI GPT-4o, Anthropic Claude 3.5, Google Gemini 2.0, DeepSeek R1, Ollama) and high-performance AVX2/SIMD tensor math.
1. Universal AI Model Client
Nyx provides a unified interface across all major LLM providers with SSE streaming and tool calling:
import std.ml.ai_model
import std.io
pub fn main() {
// 1. Initialize frontier model clients
let gpt4 = ai_model.create_openai_client("gpt-4o", "sk-proj-...")
let claude = ai_model.create_anthropic_client("claude-3-5-sonnet-20241022", "sk-ant-...")
let gemini = ai_model.create_gemini_client("gemini-2.0-flash", "AIzaSy...")
let deepseek = ai_model.create_deepseek_client("deepseek-reasoner", "sk-...")
let local_llm = ai_model.create_ollama_client("http://localhost:11434", "llama3.3:70b")
// 2. Multi-turn chat completion
let mut messages = Vec.new()
messages.push(ai_model.ChatMessage {
role: "system".to_string(),
content: "You are an expert autonomous systems engineer.".to_string(),
})
messages.push(ai_model.ChatMessage {
role: "user".to_string(),
content: "Analyze geospatial risk for sensor cluster alpha.".to_string(),
})
let response = ai_model.chat_complete(gpt4, messages, 0.7)
std.io.println("AI Assistant Reply: " + response)
}
2. High-Performance AVX2 SIMD Tensor Operations
Direct C runtime bindings (rt_ml.h) deliver cache-blocked matrix multiplication, RMSNorm, and SwiGLU activations:
import std.ml
import std.vec
pub fn main() {
// Cache-blocked AVX2 GEMM matrix multiplication
let a = [1.0, 2.0, 3.0, 4.0]
let b = [5.0, 6.0, 7.0, 8.0]
let c = ml.simd_gemm(a, b, 2, 2, 2)
// Vector Cosine Similarity Search for RAG Embeddings
let query_embedding = [0.12, 0.88, 0.45, 0.02]
let doc_embedding = [0.12, 0.88, 0.45, 0.02]
let score = ml.cosine_similarity(query_embedding, doc_embedding)
std.io.println("Similarity Score: " + score.to_string()) // 1.000000
}
3. Function Reference
| Function | Signature | Description |
|---|---|---|
create_openai_client | (model: String, key: String) -> AiClient | Initializes OpenAI client with Bearer token authentication |
create_anthropic_client | (model: String, key: String) -> AiClient | Initializes Anthropic client with x-api-key headers |
create_gemini_client | (model: String, key: String) -> AiClient | Initializes Google Gemini client |
create_deepseek_client | (model: String, key: String) -> AiClient | Initializes DeepSeek Reasoner/Chat client |
create_ollama_client | (endpoint: String, model: String) -> AiClient | Initializes local Ollama server connector |
chat_complete | (client: AiClient, msgs: Vec, temp: f64) -> String | Executes multi-turn inference request |
simd_gemm | (a: [f64], b: [f64], m: i32, k: i32, n: i32) -> [f64] | AVX2/NEON hardware accelerated matrix multiplication |
cosine_similarity | (a: [f64], b: [f64]) -> f64 | Calculates cosine similarity between embedding vectors |