返回 CodeWhale
speech_host_test_support.rs
根目录 / crates / engine / src / tools / speech_host_test_support.rs
1 use crate::extension_host::{ExtensionHostManager, ExtensionHostOptions};
2 use codewhale_config::ProviderKind;
3 use codewhale_runtime::config::Config;
4 use codewhale_runtime::features::FeaturesToml;
5 use serde_json::json;
6 use std::path::{Path, PathBuf};
7 use std::sync::Arc;
8 use wiremock::matchers::{method, path};
9 use wiremock::{Mock, MockServer, ResponseTemplate};
10
11 pub fn manager(node: PathBuf, home: &Path) -> Arc<ExtensionHostManager> {
12 Arc::new(ExtensionHostManager::new(ExtensionHostOptions {
13 runtime: codewhale_config::extension_host::ExtensionHostRuntime::Node,
14 node_override: Some(node),
15 root: Some(home.join("host")),
16 ..ExtensionHostOptions::default()
17 }))
18 }
19
20 pub fn config(url: &str, host: bool) -> Config {
21 let mut config = {
22 let __cw_config_init_0_0 = Some("xiaomi-mimo".into());
23 let mut __cw_config_init_0_value: Config = Config::default();
24 __cw_config_init_0_value.provider = __cw_config_init_0_0;
25 __cw_config_init_0_value
26 };
27 config
28 .set_provider_base_url_override(
29 &config.test_identity_for_kind(ProviderKind::XiaomiMimo),
30 Some(url.into()),
31 )
32 .unwrap();
33 config
34 .set_provider_api_key_override(
35 &config.test_identity_for_kind(ProviderKind::XiaomiMimo),
36 Some("local-fixture-only".into()),
37 )
38 .unwrap();
39 config.features = Some(FeaturesToml {
40 entries: [("speech_host".into(), host)].into_iter().collect(),
41 });
42 config
43 }
44 pub async fn provider(server: &MockServer, count: u64) {
45 Mock::given(method("POST"))
46 .and(path("/v1/chat/completions"))
47 .respond_with(ResponseTemplate::new(200).set_body_json(json!({
48 "choices":[{"message":{"audio":{"data":"aGk=","transcript":"hi"}}}]
49 })))
50 .expect(count)
51 .mount(server)
52 .await;
53 }
54
54 lines RUST