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
15 changes: 6 additions & 9 deletions src/llm/anthropic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,24 +89,21 @@ impl LlmGenerationClient for Client {
let encoded_api_key = encode(&self.api_key);

let resp = retryable::run(
|| {
|| async {
self.client
.post(url)
.header("x-api-key", encoded_api_key.as_ref())
.header("anthropic-version", "2023-06-01")
.json(&payload)
.send()
.await?
.error_for_status()
},
&retryable::HEAVY_LOADED_OPTIONS,
)
.await?;
if !resp.status().is_success() {
bail!(
"Anthropic API error: {:?}\n{}\n",
resp.status(),
resp.text().await?
);
}
.await
.context("Anthropic API error")?;

let mut resp_json: serde_json::Value = resp.json().await.context("Invalid JSON")?;
if let Some(error) = resp_json.get("error") {
bail!("Anthropic API error: {:?}", error);
Expand Down
28 changes: 10 additions & 18 deletions src/llm/ollama.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,22 +102,18 @@ impl LlmGenerationClient for Client {
stream: Some(false),
};
let res = retryable::run(
|| {
|| async {
self.reqwest_client
.post(self.generate_url.as_str())
.json(&req)
.send()
.await?
.error_for_status()
},
&retryable::HEAVY_LOADED_OPTIONS,
)
.await?;
if !res.status().is_success() {
bail!(
"Ollama API error: {:?}\n{}\n",
res.status(),
res.text().await?
);
}
.await
.context("Ollama API error")?;
let json: OllamaResponse = res.json().await?;
Ok(super::LlmGenerateResponse {
text: json.response,
Expand Down Expand Up @@ -145,22 +141,18 @@ impl LlmEmbeddingClient for Client {
input: request.text.as_ref(),
};
let resp = retryable::run(
|| {
|| async {
self.reqwest_client
.post(self.embed_url.as_str())
.json(&req)
.send()
.await?
.error_for_status()
},
&retryable::HEAVY_LOADED_OPTIONS,
)
.await?;
if !resp.status().is_success() {
bail!(
"Ollama API error: {:?}\n{}\n",
resp.status(),
resp.text().await?
);
}
.await
.context("Ollama API error")?;
let embedding_resp: OllamaEmbeddingResponse = resp.json().await.context("Invalid JSON")?;
Ok(super::LlmEmbeddingResponse {
embedding: embedding_resp.embedding,
Expand Down
15 changes: 5 additions & 10 deletions src/llm/voyage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,24 +76,19 @@ impl LlmEmbeddingClient for Client {
}

let resp = retryable::run(
|| {
|| async {
self.client
.post(url)
.header("Authorization", format!("Bearer {}", self.api_key))
.json(&payload)
.send()
.await?
.error_for_status()
},
&retryable::HEAVY_LOADED_OPTIONS,
)
.await?;

if !resp.status().is_success() {
bail!(
"Voyage AI API error: {:?}\n{}\n",
resp.status(),
resp.text().await?
);
}
.await
.context("Voyage AI API error")?;

let embedding_resp: EmbedResponse = resp.json().await.context("Invalid JSON")?;

Expand Down
12 changes: 3 additions & 9 deletions src/ops/targets/kuzu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,18 +80,12 @@ impl KuzuThinClient {
let query = json!({
"query": cyper_builder.query
});
let response = self
.reqwest_client
self.reqwest_client
.post(&self.query_url)
.json(&query)
.send()
.await?;
if !response.status().is_success() {
return Err(anyhow::anyhow!(
"Failed to run cypher: {}",
response.text().await?
));
}
.await?
.error_for_status()?;
Ok(())
}
}
Expand Down
Loading