Skip to main content

InferenceEngine

Struct InferenceEngine 

Source
pub struct InferenceEngine {
    pub provider: Arc<RwLock<Box<dyn ModelProvider>>>,
    pub cached_model: Arc<RwLock<String>>,
    pub cached_context: Arc<AtomicUsize>,
    pub base_url: String,
    pub species: String,
    pub snark: u8,
    pub kv_semaphore: Semaphore,
    pub economics: Arc<Mutex<SessionEconomics>>,
    pub worker_model: Option<String>,
    pub gemma_native_formatting: Arc<AtomicBool>,
    pub cancel_token: Arc<AtomicBool>,
}

Fields§

§provider: Arc<RwLock<Box<dyn ModelProvider>>>§cached_model: Arc<RwLock<String>>§cached_context: Arc<AtomicUsize>§base_url: String§species: String§snark: u8§kv_semaphore: Semaphore§economics: Arc<Mutex<SessionEconomics>>§worker_model: Option<String>

Optional model ID for worker-level tasks (Swarms / research).

§gemma_native_formatting: Arc<AtomicBool>

Opt-in Gemma-native request shaping. Off by default.

§cancel_token: Arc<AtomicBool>

Global cancellation token for hard-interrupting the inference stream.

Implementations§

Source§

impl InferenceEngine

Source

pub fn new( api_url: String, species: String, snark: u8, ) -> Result<Self, Box<dyn Error>>

Source

pub fn set_gemma_native_formatting(&self, enabled: bool)

Source

pub async fn health_check(&self) -> bool

Source

pub async fn provider_name(&self) -> String

Source

pub async fn get_loaded_model(&self) -> Option<String>

Source

pub async fn get_embedding_model(&self) -> Option<String>

Source

pub async fn load_model(&self, model_id: &str) -> Result<(), String>

Source

pub async fn load_model_with_context( &self, model_id: &str, context_length: Option<usize>, ) -> Result<(), String>

Source

pub async fn load_embedding_model(&self, model_id: &str) -> Result<(), String>

Source

pub async fn list_provider_models( &self, kind: ProviderModelKind, loaded_only: bool, ) -> Result<Vec<String>, String>

Source

pub async fn unload_model( &self, model_id: Option<&str>, all: bool, ) -> Result<String, String>

Source

pub async fn unload_embedding_model( &self, model_id: Option<&str>, ) -> Result<String, String>

Source

pub async fn prewarm(&self) -> Result<(), String>

Source

pub async fn detect_context_length(&self) -> usize

Source

pub async fn set_runtime_profile(&self, model: &str, context_length: usize)

Source

pub async fn refresh_runtime_profile(&self) -> Option<(String, usize, bool)>

Source

pub fn build_system_prompt( &self, snark: u8, chaos: u8, brief: bool, professional: bool, tools: &[ToolDefinition], reasoning_history: Option<&str>, environment_summary: Option<&str>, mcp_tools: &[McpTool], ) -> String

Source

pub fn build_system_prompt_legacy( &self, snark: u8, _chaos: u8, brief: bool, professional: bool, tools: &[ToolDefinition], reasoning_history: Option<&str>, environment_summary: Option<&str>, ) -> String

Source

pub fn current_model(&self) -> String

Source

pub fn current_context_length(&self) -> usize

Source

pub fn is_compact_context_window(&self) -> bool

Source

pub fn gemma_native_formatting_enabled(&self) -> bool

Source

pub async fn call_with_tools( &self, messages: &[ChatMessage], tools: &[ToolDefinition], model_override: Option<&str>, ) -> Result<(Option<String>, Option<Vec<ToolCallResponse>>, Option<TokenUsage>, Option<String>), String>

Source

pub async fn stream_messages( &self, messages: &[ChatMessage], tx: Sender<InferenceEvent>, ) -> Result<(), Box<dyn Error>>

Stream a conversation (no tools). Emits Token/Done/Error events.

Source

pub async fn stream_generation( &self, prompt: &str, snark: u8, chaos: u8, brief: bool, professional: bool, tx: Sender<InferenceEvent>, ) -> Result<(), Box<dyn Error>>

Single-turn streaming (legacy helper used by startup sequence).

Source

pub async fn generate_task_worker( &self, prompt: &str, professional: bool, ) -> Result<String, String>

Runs a task using the worker_model if set, otherwise falls back to the main model.

Source

pub async fn generate_task( &self, prompt: &str, professional: bool, ) -> Result<String, String>

Source

pub async fn generate_task_with_temp( &self, prompt: &str, temp: f32, professional: bool, ) -> Result<String, String>

Source

pub async fn generate_task_with_model( &self, prompt: &str, _temp: f32, professional: bool, model: &str, ) -> Result<String, String>

Source

pub fn snip_history( &self, turns: &[ChatMessage], max_tokens_estimate: usize, keep_recent: usize, ) -> Vec<ChatMessage>

Prune middle turns when context grows too large, keeping system + recent N.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<S> FromSample<S> for S

Source§

fn from_sample_(s: S) -> S

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<F, T> IntoSample<T> for F
where T: FromSample<F>,

Source§

fn into_sample(self) -> T

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

Source§

fn to_sample_(self) -> U

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,