feat: Anthropic provider/inbound + embeddings

- Anthropic outbound provider: /v1/messages, system extraction, x-api-key +
  anthropic-version; streaming translates Anthropic SSE -> unified OpenAI wire format
- Anthropic inbound adapter (POST /v1/messages): non-streaming JSON + streaming SSE
  (OpenAI -> Anthropic event translation)
- Embeddings: POST /v1/embeddings inbound + Provider::embed(); embedding models
  resolvable from the pool (registry no longer skips them)
- protocols mounted always, gated on live flags; admin meta marks them implemented
This commit is contained in:
infosave2007
2026-06-30 16:50:22 +03:00
parent 70d8cde258
commit bf8534f13d
9 changed files with 528 additions and 24 deletions
+26
View File
@@ -185,4 +185,30 @@ impl Provider for OpenAiProvider {
.map(|res| res.map_err(|e| GatewayError::UpstreamUnavailable(e.to_string())));
Ok(Box::pin(stream))
}
async fn embed(&self, input: serde_json::Value) -> Result<serde_json::Value> {
let body = serde_json::json!({ "model": self.model, "input": input });
let mut r = self
.http
.post(format!("{}/embeddings", self.base_url))
.json(&body);
if let Some(key) = &self.api_key {
r = r.bearer_auth(key);
}
let resp = r
.send()
.await
.map_err(|e| GatewayError::UpstreamUnavailable(e.to_string()))?;
if !resp.status().is_success() {
let status = resp.status();
let err_body = resp.text().await.unwrap_or_default();
return Err(GatewayError::UpstreamUnavailable(format!(
"provider {} returned HTTP {}: {}",
self.id, status, err_body
)));
}
resp.json().await.map_err(|e| {
GatewayError::Internal(format!("failed to parse embeddings response: {e}"))
})
}
}