Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions crates/agentflare-store/src/documents.rs
Original file line number Diff line number Diff line change
Expand Up @@ -550,8 +550,10 @@ impl Store {
|row| {
let blob: Vec<u8> = row.get(0)?;
let vec: Vec<f32> = blob
.chunks_exact(4)
.map(|c| f32::from_le_bytes([c[0], c[1], c[2], c[3]]))
.as_chunks::<4>()
.0
.iter()
.map(|c| f32::from_le_bytes(*c))
.collect();
Ok(vec)
},
Expand Down Expand Up @@ -588,8 +590,10 @@ impl Store {
return None;
}
let doc_vec: Vec<f32> = blob
.chunks_exact(4)
.map(|c| f32::from_le_bytes([c[0], c[1], c[2], c[3]]))
.as_chunks::<4>()
.0
.iter()
.map(|c| f32::from_le_bytes(*c))
.collect();
let sim = crate::embed::cosine_similarity(query_vec, &doc_vec)? as f64;
Some((
Expand Down
6 changes: 4 additions & 2 deletions crates/agentflare-store/src/embed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ pub fn bytes_to_vec(b: &[u8]) -> Option<Vec<f32>> {
return None;
}
Some(
b.chunks_exact(4)
.map(|c| f32::from_le_bytes([c[0], c[1], c[2], c[3]]))
b.as_chunks::<4>()
.0
.iter()
.map(|c| f32::from_le_bytes(*c))
.collect(),
)
}
Expand Down
26 changes: 16 additions & 10 deletions crates/flare-proxy/src/forward.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ async fn proxy_anthropic(

let resp = match check_status(resp).await {
Ok(resp) => resp,
Err(err) => return err,
Err(err) => return *err,
};

Response::builder()
Expand Down Expand Up @@ -170,7 +170,7 @@ async fn proxy_gemini(
false,
false,
),
Err(err) => err,
Err(err) => *err,
}
}

Expand Down Expand Up @@ -212,7 +212,7 @@ async fn proxy_openai_compat(
needs_heuristic,
needs_think,
),
Err(err) => err,
Err(err) => *err,
}
}

Expand All @@ -233,19 +233,25 @@ fn apply_extra_headers(
/// Verify the upstream response succeeded, converting a non-2xx into an
/// Anthropic-shaped error `Response`. On success, hands back the still-open
/// `reqwest::Response` so the caller can stream its body.
async fn check_status(resp: reqwest::Response) -> Result<reqwest::Response, Response> {
///
/// `Response` (`axum::http::Response<axum::body::Body>`) is >=128 bytes, so
/// it's boxed in the `Err` variant rather than inflating every `Result`
/// return by that much even on the success path (`clippy::result_large_err`).
async fn check_status(resp: reqwest::Response) -> Result<reqwest::Response, Box<Response>> {
if resp.status().is_success() {
return Ok(resp);
}
let status = resp.status();
let body = resp.text().await.unwrap_or_default();
let err_val: Value = serde_json::from_str(&body).unwrap_or(json!({"error": {"message": body}}));
Err((
StatusCode::from_u16(status.as_u16()).unwrap_or(StatusCode::BAD_GATEWAY),
[(axum::http::header::CONTENT_TYPE, "application/json")],
serde_json::to_string(&shape_xlat::error_to_anthropic(&err_val)).unwrap_or_default(),
)
.into_response())
Err(Box::new(
(
StatusCode::from_u16(status.as_u16()).unwrap_or(StatusCode::BAD_GATEWAY),
[(axum::http::header::CONTENT_TYPE, "application/json")],
serde_json::to_string(&shape_xlat::error_to_anthropic(&err_val)).unwrap_or_default(),
)
.into_response(),
))
}

/// Shared SSE loop for providers whose raw stream needs translating into
Expand Down
Loading