qualia_core_db/inference/conditioning_opt/
runtime_contract.rs1use crate::inference::conditioning::ConditioningBudget;
9
10#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
12#[serde(rename_all = "kebab-case")]
13pub enum PrefixConfiguration {
14 Standard,
16 CanonicalCacheAligned,
19}
20
21impl PrefixConfiguration {
22 pub const fn as_str(self) -> &'static str {
24 match self {
25 Self::Standard => "standard",
26 Self::CanonicalCacheAligned => "canonical-cache-aligned",
27 }
28 }
29}
30
31#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
33#[serde(rename_all = "kebab-case")]
34pub enum CompressionStrategy {
35 PreservePrefix,
38 CompactContext,
41}
42
43impl CompressionStrategy {
44 pub const fn as_str(self) -> &'static str {
46 match self {
47 Self::PreservePrefix => "preserve-prefix",
48 Self::CompactContext => "compact-context",
49 }
50 }
51}
52
53#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
56pub struct ModelPrecisionContract {
57 pub profile_id: String,
58 pub profile_version: u64,
59 pub spec_identity: u64,
60 pub budget: ConditioningBudget,
61 pub prefix: PrefixConfiguration,
62 pub compression: CompressionStrategy,
63}
64
65impl ModelPrecisionContract {
66 pub fn new(
68 profile_id: impl Into<String>,
69 profile_version: u64,
70 spec_identity: u64,
71 budget: ConditioningBudget,
72 prefix: PrefixConfiguration,
73 compression: CompressionStrategy,
74 ) -> Result<Self, &'static str> {
75 let profile_id = profile_id.into();
76 if profile_id.is_empty()
77 || profile_version == 0
78 || budget.input_tokens == 0
79 || budget.output_tokens == 0
80 || budget.max_bytes == 0
81 {
82 return Err("invalid model precision contract");
83 }
84 Ok(Self {
85 profile_id,
86 profile_version,
87 spec_identity,
88 budget,
89 prefix,
90 compression,
91 })
92 }
93}