Files
leleka/crates/engine-fake/src/tests.rs
T

48 lines
1.9 KiB
Rust

use super::*;
use leleka_backend_api::{
FinishReason, GenerationEvent, GenerationRequest, GenerationTerminal, InferenceMode, RuntimeConfig, Usage,
scripted::Script,
};
use leleka_engine_core::family::spawn;
fn config() -> RuntimeConfig {
RuntimeConfig {
load_config_version: leleka_backend_api::LOAD_CONFIG_VERSION,
inference_mode: InferenceMode::Native,
gpu_memory_limit_bytes: None,
allow_experimental: false,
}
}
#[test]
fn the_family_starts_through_the_composition_root_and_plays_its_script() {
let (start, receiver) = FakeStart::fixture();
let mut backend = spawn::<EngineFake>(start).expect("the fake engine always starts");
let handle = receiver.recv().expect("the handle is delivered at start-up");
let usage = Usage { input_tokens: 3, output_tokens: 2, reused_input_tokens: 0 };
handle.push(Script::stop_with(&["he", "llo"], usage));
let model = backend.load(ScriptedEngine::fixture_descriptor(), config()).expect("the fixture model loads");
let request = GenerationRequest {
request_id: "r1".into(),
prompt: "p".into(),
max_output_tokens: 8,
temperature_milli: 0,
sampling: Default::default(),
};
let mut stream = backend.start_generation(&model, request).expect("a loaded engine admits a request");
let mut text = String::new();
let mut terminal = None;
while let Ok(Some(event)) = stream.recv() {
match event {
GenerationEvent::TextDelta { text: delta } => text.push_str(&delta),
GenerationEvent::Terminal(t) => terminal = Some(t),
_ => {}
}
}
assert_eq!(text, "hello");
assert!(matches!(terminal, Some(GenerationTerminal::Completed { reason: FinishReason::Stop, .. })));
assert_eq!(handle.requests().len(), 1);
assert_eq!(<EngineFake as EngineFamily>::NAME, "engine-fake");
}