open-standards/mesh/mesh-rs/crates/mesh-openai/examples/serve.rs
Transaction Science a24982ce5a wai.generate.spectral: extend the lexicon to 370 words (data-only, pin unchanged)
Adds ~110 more words across new domains: creatures (tiger→warm horizontal stripes,
zebra→vertical, peacock/jellyfish→radial, dragon/phoenix, swan/raven/wolf/whale…),
food & drink (wine/honey/coffee/cherry/mango/saffron/matcha/blueberry…), gems
(opal/pearl/onyx/quartz/topaz/garnet/obsidian/moonstone…), architecture
(city/cathedral/temple/tower/dome/labyrinth/maze/spire…), abstract concepts
(love/passion/harmony/energy/freedom/infinity/eternity/zen/echo…), cosmic/sci-fi
(plasma/quasar/pulsar/supernova/blackhole/matrix/circuit/hologram/wormhole…),
botanical (lotus/orchid/daisy/sunflower/poppy/tulip/lily…), seasons
(autumn/spring/summer/winter/harvest/solstice…) and synesthetic music
(rhythm/melody/pulse/bass/jazz/blues/resonance…). Shape-bearing words carry the
right primitive — supernova/pulsar/lotus→radial, cathedral/maze/matrix→mirror,
blackhole/blues→gradient.

Data-only: generate.rs + architecture unchanged (wasm unchanged), and the
conformance prompt still matches only calm+horizon, so the pin is UNCHANGED
(4bd80c0ef51bb843) — no test churn. Verified: tiger→horizontal stripes,
supernova→radial rings, cathedral→symmetry, all byte-exact.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-06-27 05:33:47 -04:00

49 lines
1.9 KiB
Rust

//! Run the Mesh OpenAI-compatible reference server — a real
//! `/v1/chat/completions` endpoint any OpenAI client (curl, the SDKs, vLLM-style
//! tooling) can drive, returning energy-metered serving + a sealed receipt.
//!
//! ```text
//! cargo run --example serve --features server -- 127.0.0.1:8088 &
//! curl -s localhost:8088/v1/chat/completions \
//! -d '{"model":"gpt-mini","messages":[{"role":"user","content":"hi"}],"max_tokens":8}'
//! ```
use std::net::TcpListener;
use ed25519_dalek::SigningKey;
use mesh_core::Mesh;
use mesh_engine::ReferenceEngine;
use mesh_meter::{Provenance, SteppingMeter};
use mesh_openai::{server, ChatBackend};
use mesh_router::BackendSpec;
use mesh_schema::Fidelity;
/// A trivial tokenizer bridge: bytes in, a deterministic note out. A real
/// deployment pairs the model's own tokenizer with the engine that serves it.
struct ByteBackend;
impl ChatBackend for ByteBackend {
fn encode(&self, text: &str) -> Vec<u32> {
text.bytes().map(u32::from).collect()
}
fn decode(&self, ids: &[u32]) -> String {
format!("[mesh reference engine served {} tokens]", ids.len())
}
}
fn main() -> std::io::Result<()> {
let addr = std::env::args().nth(1).unwrap_or_else(|| "127.0.0.1:8088".to_string());
let listener = TcpListener::bind(&addr)?;
eprintln!("mesh OpenAI server: http://{addr}/v1/chat/completions");
// A measured-grade meter (stepping, HwShunt) + the deterministic reference
// engine, behind one steward-signed receipt chain.
let meter = SteppingMeter::new("rapl", Provenance::HwShunt, 4_800_000);
let sk = SigningKey::from_bytes(&[8u8; 32]);
let mut mesh = Mesh::new(&meter, sk, "did:example:mesh-demo");
mesh.register(
BackendSpec::new("tiny", "ssm-1b", Fidelity::F2, 50_000),
Box::new(ReferenceEngine::new("tiny", "ssm-1b", Fidelity::F2, 50_000, 32)),
);
server::run(&listener, &mut mesh, &ByteBackend, 100_000_000)
}