Skip to content

Commit 598caa4

Browse files
committed
fix clippy warnings and formatting
1 parent f5e7823 commit 598caa4

11 files changed

Lines changed: 317 additions & 241 deletions

File tree

src/api/client.rs

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use crate::error::{Result, SofosError};
21
use super::types::*;
2+
use crate::error::{Result, SofosError};
33
use futures::stream::{Stream, StreamExt};
44
use reqwest::header::{HeaderMap, HeaderValue, CONTENT_TYPE};
55
use std::pin::Pin;
@@ -21,10 +21,7 @@ impl AnthropicClient {
2121
HeaderValue::from_str(&api_key)
2222
.map_err(|e| SofosError::Config(format!("Invalid API key format: {}", e)))?,
2323
);
24-
headers.insert(
25-
"anthropic-version",
26-
HeaderValue::from_static(API_VERSION),
27-
);
24+
headers.insert("anthropic-version", HeaderValue::from_static(API_VERSION));
2825
headers.insert(CONTENT_TYPE, HeaderValue::from_static("application/json"));
2926

3027
let client = reqwest::Client::builder()
@@ -42,12 +39,7 @@ impl AnthropicClient {
4239
) -> Result<CreateMessageResponse> {
4340
let url = format!("{}/messages", API_BASE);
4441

45-
let response = self
46-
.client
47-
.post(&url)
48-
.json(&request)
49-
.send()
50-
.await?;
42+
let response = self.client.post(&url).json(&request).send().await?;
5143

5244
if !response.status().is_success() {
5345
let status = response.status();
@@ -69,12 +61,7 @@ impl AnthropicClient {
6961
request.stream = Some(true);
7062
let url = format!("{}/messages", API_BASE);
7163

72-
let response = self
73-
.client
74-
.post(&url)
75-
.json(&request)
76-
.send()
77-
.await?;
64+
let response = self.client.post(&url).json(&request).send().await?;
7865

7966
if !response.status().is_success() {
8067
let status = response.status();
@@ -88,12 +75,10 @@ impl AnthropicClient {
8875
let stream = response
8976
.bytes_stream()
9077
.map(|result| {
91-
result
92-
.map_err(SofosError::from)
93-
.and_then(|bytes| {
94-
let text = String::from_utf8_lossy(&bytes);
95-
_parse_sse_events(&text)
96-
})
78+
result.map_err(SofosError::from).and_then(|bytes| {
79+
let text = String::from_utf8_lossy(&bytes);
80+
_parse_sse_events(&text)
81+
})
9782
})
9883
.flat_map(|result| {
9984
futures::stream::iter(match result {
@@ -110,8 +95,7 @@ fn _parse_sse_events(text: &str) -> Result<Vec<_StreamEvent>> {
11095
let mut events = Vec::new();
11196

11297
for line in text.lines() {
113-
if line.starts_with("data: ") {
114-
let json_str = &line[6..]; // Skip "data: "
98+
if let Some(json_str) = line.strip_prefix("data: ") {
11599
if json_str.trim() == "[DONE]" {
116100
break;
117101
}

src/api/morph.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,7 @@ impl MorphClient {
8484

8585
let url = format!("{}/chat/completions", MORPH_BASE_URL);
8686

87-
let response = self
88-
.client
89-
.post(&url)
90-
.json(&request)
91-
.send()
92-
.await?;
87+
let response = self.client.post(&url).json(&request).send().await?;
9388

9489
if !response.status().is_success() {
9590
let status = response.status();
@@ -102,11 +97,11 @@ impl MorphClient {
10297

10398
let result: MorphResponse = response.json().await?;
10499

105-
Ok(result
100+
result
106101
.choices
107102
.first()
108103
.map(|c| c.message.content.clone())
109-
.ok_or_else(|| SofosError::Api("No response from Morph API".to_string()))?)
104+
.ok_or_else(|| SofosError::Api("No response from Morph API".to_string()))
110105
}
111106
}
112107

src/api/types.rs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,7 @@ impl Message {
3636
pub fn user_with_tool_results(results: Vec<MessageContentBlock>) -> Self {
3737
Self {
3838
role: "user".to_string(),
39-
content: MessageContent::Blocks {
40-
content: results,
41-
},
39+
content: MessageContent::Blocks { content: results },
4240
}
4341
}
4442
}
@@ -114,9 +112,7 @@ pub enum MessageContentBlock {
114112
impl MessageContentBlock {
115113
pub fn from_content_block(block: &ContentBlock) -> Self {
116114
match block {
117-
ContentBlock::Text { text } => MessageContentBlock::Text {
118-
text: text.clone(),
119-
},
115+
ContentBlock::Text { text } => MessageContentBlock::Text { text: text.clone() },
120116
ContentBlock::ToolUse { id, name, input } => MessageContentBlock::ToolUse {
121117
id: id.clone(),
122118
name: name.clone(),
@@ -154,10 +150,7 @@ pub enum _StreamEventType {
154150
content_block: ContentBlock,
155151
},
156152
#[serde(rename = "content_block_delta")]
157-
ContentBlockDelta {
158-
index: usize,
159-
delta: _ContentDelta,
160-
},
153+
ContentBlockDelta { index: usize, delta: _ContentDelta },
161154
#[serde(rename = "content_block_stop")]
162155
ContentBlockStop { index: usize },
163156
#[serde(rename = "message_delta")]

src/conversation.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,13 @@ mod tests {
126126
#[test]
127127
fn test_message_limit_trimming() {
128128
let mut history = ConversationHistory::new();
129-
129+
130130
for i in 0..60 {
131131
history.add_user_message(format!("Message {}", i));
132132
}
133-
133+
134134
assert_eq!(history.messages().len(), 50);
135-
135+
136136
if let crate::api::MessageContent::Text { content } = &history.messages()[0].content {
137137
assert_eq!(content, "Message 10");
138138
}
@@ -141,25 +141,25 @@ mod tests {
141141
#[test]
142142
fn test_message_limit_with_blocks() {
143143
let mut history = ConversationHistory::new();
144-
144+
145145
for i in 0..30 {
146146
history.add_user_message(format!("User {}", i));
147-
history.add_assistant_with_blocks(vec![
148-
MessageContentBlock::Text { text: format!("Assistant {}", i) }
149-
]);
147+
history.add_assistant_with_blocks(vec![MessageContentBlock::Text {
148+
text: format!("Assistant {}", i),
149+
}]);
150150
}
151-
151+
152152
assert_eq!(history.messages().len(), 50);
153153
}
154154

155155
#[test]
156156
fn test_no_trimming_below_limit() {
157157
let mut history = ConversationHistory::new();
158-
158+
159159
for i in 0..20 {
160160
history.add_user_message(format!("Message {}", i));
161161
}
162-
162+
163163
assert_eq!(history.messages().len(), 20);
164164
}
165165
}

src/main.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,9 @@ fn main() -> Result<()> {
3636
}
3737
};
3838

39-
let workspace = env::current_dir()
40-
.map_err(|e| error::SofosError::Config(format!("Failed to get current directory: {}", e)))?;
39+
let workspace = env::current_dir().map_err(|e| {
40+
error::SofosError::Config(format!("Failed to get current directory: {}", e))
41+
})?;
4142

4243
println!(
4344
"{} {}",
@@ -52,7 +53,11 @@ fn main() -> Result<()> {
5253
Some(client)
5354
}
5455
Err(e) => {
55-
eprintln!("{} Failed to initialize Morph client: {}", "Warning:".bright_yellow(), e);
56+
eprintln!(
57+
"{} Failed to initialize Morph client: {}",
58+
"Warning:".bright_yellow(),
59+
e
60+
);
5661
None
5762
}
5863
}

0 commit comments

Comments
 (0)