style: format seluruh workspace dengan cargo fmt
Menyeragamkan format kode sesuai rustfmt (126 file). Sebelumnya lefthook pre-commit 'cargo fmt --check' akan gagal pada commit apa pun.
This commit is contained in:
1 parent
884b19ccb5
commit
7b0b53671f
127 files changed
+1271
-1156
No files matched your search
@@ -4,10 +4,10 @@
|
||||
use rand_core::RngCore;
|
||||
use std::time::Duration;
|
||||
|
||||
use zesdex_application::ports::ProviderService;
|
||||
use zesdex_domain::core::{
|
||||
ChatMessage, ChatRequest, ChatResponse, SseParser, StreamEvent, StreamOptions, ToolDef,
|
||||
};
|
||||
use zesdex_application::ports::ProviderService;
|
||||
|
||||
use zesdex_domain::agent::defaults::{DEFAULT_API_BASE, DEFAULT_MODEL};
|
||||
const DEFAULT_BASE_URL: &str = DEFAULT_API_BASE;
|
||||
@@ -82,10 +82,7 @@ impl LlmClient {
|
||||
retrying without connect timeout",
|
||||
e,
|
||||
);
|
||||
match reqwest::Client::builder()
|
||||
.timeout(REQUEST_TIMEOUT)
|
||||
.build()
|
||||
{
|
||||
match reqwest::Client::builder().timeout(REQUEST_TIMEOUT).build() {
|
||||
Ok(c) => c,
|
||||
Err(e2) => {
|
||||
tracing::warn!("also failed: {e2}. using default client");
|
||||
@@ -115,8 +112,7 @@ impl LlmClient {
|
||||
.post(url)
|
||||
.header("Content-Type", "application/json");
|
||||
if !self.api_key.is_empty() {
|
||||
http_req =
|
||||
http_req.header("Authorization", format!("Bearer {}", self.api_key));
|
||||
http_req = http_req.header("Authorization", format!("Bearer {}", self.api_key));
|
||||
}
|
||||
|
||||
let mut resp = http_req.json(req).send().await.map_err(|e| {
|
||||
@@ -182,7 +178,7 @@ impl LlmClient {
|
||||
}
|
||||
|
||||
let tc = &mut self.tool_calls[index];
|
||||
|
||||
|
||||
if let Some(ref id_val) = id {
|
||||
tc.id = id_val.clone();
|
||||
}
|
||||
@@ -237,8 +233,7 @@ impl LlmClient {
|
||||
n
|
||||
}
|
||||
};
|
||||
let text =
|
||||
String::from_utf8_lossy(&byte_buf[..valid_len]).into_owned();
|
||||
let text = String::from_utf8_lossy(&byte_buf[..valid_len]).into_owned();
|
||||
byte_buf.drain(..valid_len);
|
||||
|
||||
for event in parser.feed(&text) {
|
||||
@@ -306,8 +301,7 @@ impl ProviderService for LlmClient {
|
||||
.header("Content-Type", "application/json");
|
||||
|
||||
if !self.api_key.is_empty() {
|
||||
http_req =
|
||||
http_req.header("Authorization", format!("Bearer {}", self.api_key));
|
||||
http_req = http_req.header("Authorization", format!("Bearer {}", self.api_key));
|
||||
}
|
||||
|
||||
let result = async {
|
||||
@@ -335,9 +329,9 @@ impl ProviderService for LlmClient {
|
||||
}
|
||||
|
||||
let data: ChatResponse = resp.json().await?;
|
||||
let usage = data.usage.map(|u| {
|
||||
(u64::from(u.prompt_tokens), u64::from(u.completion_tokens))
|
||||
});
|
||||
let usage = data
|
||||
.usage
|
||||
.map(|u| (u64::from(u.prompt_tokens), u64::from(u.completion_tokens)));
|
||||
let message = data
|
||||
.choices
|
||||
.into_iter()
|
||||
@@ -345,7 +339,8 @@ impl ProviderService for LlmClient {
|
||||
.and_then(|c| c.message)
|
||||
.ok_or_else(|| anyhow::anyhow!("API response had no choices"))?;
|
||||
Ok((message, usage))
|
||||
}.await;
|
||||
}
|
||||
.await;
|
||||
|
||||
match result {
|
||||
Ok((msg, usage)) => return Ok((msg, usage)),
|
||||
@@ -393,14 +388,16 @@ impl ProviderService for LlmClient {
|
||||
let mut captured_content = false;
|
||||
let mut wrapped = |event: &StreamEvent| -> bool {
|
||||
match event {
|
||||
StreamEvent::Token(_) | StreamEvent::Reasoning(_) | StreamEvent::ToolCallDelta { .. } => {
|
||||
StreamEvent::Token(_)
|
||||
| StreamEvent::Reasoning(_)
|
||||
| StreamEvent::ToolCallDelta { .. } => {
|
||||
captured_content = true;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
on_event(event)
|
||||
};
|
||||
|
||||
|
||||
match self.try_stream_once(&req, &url, &mut wrapped).await {
|
||||
Ok(result) => return Ok(result),
|
||||
Err(e) => {
|
||||
@@ -425,11 +422,7 @@ pub fn resolve_api_key(
|
||||
) -> String {
|
||||
let provider = &settings.provider;
|
||||
|
||||
let mut api_key = settings
|
||||
.api_keys
|
||||
.get(provider)
|
||||
.cloned()
|
||||
.unwrap_or_default();
|
||||
let mut api_key = settings.api_keys.get(provider).cloned().unwrap_or_default();
|
||||
|
||||
if api_key.is_empty() {
|
||||
if let Some(provider_cfg) = app_config.providers.get(provider) {
|
||||
|
||||
Reference in new issue
Block a user