Skip to content

Commit 06fe1f9

Browse files
committed
Update bitloops-platform-embeddings to version 0.1.5, modify gateway URL handling to support optional explicit configuration, and add tests for URL resolution logic.
1 parent c50135e commit 06fe1f9

3 files changed

Lines changed: 53 additions & 5 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/bitloops-platform-embeddings/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "bitloops-platform-embeddings"
3-
version = "0.1.4"
3+
version = "0.1.5"
44
edition.workspace = true
55
rust-version.workspace = true
66
license.workspace = true

crates/bitloops-platform-embeddings/src/lib.rs

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,16 @@ use serde_json::{Value, json};
77

88
const READY_PROTOCOL_VERSION: u32 = 1;
99
const CAPABILITIES: &[&str] = &["embed", "ping", "health", "shutdown"];
10+
const DEFAULT_PLATFORM_EMBEDDINGS_GATEWAY_URL: &str = "https://platform.bitloops.net/v1/embeddings";
11+
const PLATFORM_GATEWAY_URL_ENV: &str = "BITLOOPS_PLATFORM_GATEWAY_URL";
12+
const DEFAULT_PLATFORM_API_KEY_ENV: &str = "BITLOOPS_PLATFORM_GATEWAY_TOKEN";
1013

1114
#[derive(Debug, Parser)]
1215
#[command(name = "bitloops-platform-embeddings")]
1316
pub struct Cli {
1417
#[arg(long)]
15-
pub gateway_url: String,
16-
#[arg(long)]
18+
pub gateway_url: Option<String>,
19+
#[arg(long, default_value = DEFAULT_PLATFORM_API_KEY_ENV)]
1720
pub api_key_env: String,
1821
#[command(subcommand)]
1922
command: Commands,
@@ -37,14 +40,15 @@ pub fn run(cli: Cli) -> Result<()> {
3740

3841
match cli.command {
3942
Commands::Daemon(args) => {
43+
let gateway_url = resolve_gateway_url(cli.gateway_url.as_deref())?;
4044
let api_key = std::env::var(&cli.api_key_env).with_context(|| {
4145
format!(
4246
"reading embeddings API token from environment variable `{}`",
4347
cli.api_key_env
4448
)
4549
})?;
4650
let client = GatewayEmbeddingsClient::new()?;
47-
let daemon = EmbeddingsDaemon::new(cli.gateway_url, api_key, args.model, client);
51+
let daemon = EmbeddingsDaemon::new(gateway_url, api_key, args.model, client);
4852
daemon.run_with_stdio(std::io::stdin().lock(), std::io::stdout())
4953
}
5054
}
@@ -60,6 +64,22 @@ fn init_tracing() {
6064
.try_init();
6165
}
6266

67+
fn resolve_gateway_url(explicit: Option<&str>) -> Result<String> {
68+
if let Some(gateway_url) = explicit.map(str::trim).filter(|value| !value.is_empty()) {
69+
return Ok(gateway_url.to_string());
70+
}
71+
72+
if let Some(base_url) = std::env::var(PLATFORM_GATEWAY_URL_ENV)
73+
.ok()
74+
.map(|value| value.trim().to_string())
75+
.filter(|value| !value.is_empty())
76+
{
77+
return Ok(format!("{}/v1/embeddings", base_url.trim_end_matches('/')));
78+
}
79+
80+
Ok(DEFAULT_PLATFORM_EMBEDDINGS_GATEWAY_URL.to_string())
81+
}
82+
6383
#[derive(Debug, Clone, PartialEq)]
6484
struct EmbeddingsFailure {
6585
message: String,
@@ -606,4 +626,32 @@ mod tests {
606626
vec![vec![1.0, 2.0], vec![3.0, 4.0]]
607627
);
608628
}
629+
630+
#[test]
631+
fn resolve_gateway_url_prefers_explicit_flag() {
632+
let url = resolve_gateway_url(Some("https://override.example/v1/embeddings"))
633+
.expect("explicit gateway url");
634+
assert_eq!(url, "https://override.example/v1/embeddings");
635+
}
636+
637+
#[test]
638+
fn resolve_gateway_url_derives_from_platform_gateway_env() {
639+
unsafe {
640+
std::env::set_var(PLATFORM_GATEWAY_URL_ENV, "https://platform.example");
641+
}
642+
let url = resolve_gateway_url(None).expect("gateway url from env");
643+
unsafe {
644+
std::env::remove_var(PLATFORM_GATEWAY_URL_ENV);
645+
}
646+
assert_eq!(url, "https://platform.example/v1/embeddings");
647+
}
648+
649+
#[test]
650+
fn resolve_gateway_url_defaults_to_production_gateway() {
651+
unsafe {
652+
std::env::remove_var(PLATFORM_GATEWAY_URL_ENV);
653+
}
654+
let url = resolve_gateway_url(None).expect("default gateway url");
655+
assert_eq!(url, DEFAULT_PLATFORM_EMBEDDINGS_GATEWAY_URL);
656+
}
609657
}

0 commit comments

Comments
 (0)