Skip to content

Commit a2a9825

Browse files
committed
cargo fmt
1 parent 5c43264 commit a2a9825

File tree

2 files changed

+25
-30
lines changed

2 files changed

+25
-30
lines changed

examples/openrouter_reasoning.rs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use openai_api_rs::v1::api::OpenAIClient;
2-
use openai_api_rs::v1::chat_completion::{self, ChatCompletionRequest, Reasoning, ReasoningMode, ReasoningEffort};
2+
use openai_api_rs::v1::chat_completion::{
3+
self, ChatCompletionRequest, Reasoning, ReasoningEffort, ReasoningMode,
4+
};
35
use std::env;
46

57
#[tokio::main]
@@ -15,13 +17,15 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
1517
"x-ai/grok-3-mini".to_string(), // Grok model that supports reasoning
1618
vec![chat_completion::ChatCompletionMessage {
1719
role: chat_completion::MessageRole::user,
18-
content: chat_completion::Content::Text(String::from("Explain quantum computing in simple terms.")),
20+
content: chat_completion::Content::Text(String::from(
21+
"Explain quantum computing in simple terms.",
22+
)),
1923
name: None,
2024
tool_calls: None,
2125
tool_call_id: None,
2226
}],
2327
);
24-
28+
2529
// Set reasoning with high effort
2630
req.reasoning = Some(Reasoning {
2731
mode: Some(ReasoningMode::Effort {
@@ -33,24 +37,24 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
3337

3438
let result = client.chat_completion(req).await?;
3539
println!("Content: {:?}", result.choices[0].message.content);
36-
40+
3741
// Example 2: Using reasoning with max_tokens
3842
let mut req2 = ChatCompletionRequest::new(
3943
"anthropic/claude-4-sonnet".to_string(), // Claude model that supports max_tokens
4044
vec![chat_completion::ChatCompletionMessage {
4145
role: chat_completion::MessageRole::user,
42-
content: chat_completion::Content::Text(String::from("What's the most efficient sorting algorithm?")),
46+
content: chat_completion::Content::Text(String::from(
47+
"What's the most efficient sorting algorithm?",
48+
)),
4349
name: None,
4450
tool_calls: None,
4551
tool_call_id: None,
4652
}],
4753
);
48-
54+
4955
// Set reasoning with max_tokens
5056
req2.reasoning = Some(Reasoning {
51-
mode: Some(ReasoningMode::MaxTokens {
52-
max_tokens: 2000,
53-
}),
57+
mode: Some(ReasoningMode::MaxTokens { max_tokens: 2000 }),
5458
exclude: None,
5559
enabled: None,
5660
});
@@ -61,4 +65,4 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
6165
Ok(())
6266
}
6367

64-
// OPENROUTER_API_KEY=xxxx cargo run --package openai-api-rs --example openrouter_reasoning
68+
// OPENROUTER_API_KEY=xxxx cargo run --package openai-api-rs --example openrouter_reasoning

src/v1/chat_completion.rs

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,8 @@ pub enum ReasoningEffort {
2626
#[derive(Debug, Serialize, Deserialize, Clone)]
2727
#[serde(untagged)]
2828
pub enum ReasoningMode {
29-
Effort {
30-
effort: ReasoningEffort,
31-
},
32-
MaxTokens {
33-
max_tokens: i64,
34-
},
29+
Effort { effort: ReasoningEffort },
30+
MaxTokens { max_tokens: i64 },
3531
}
3632

3733
#[derive(Debug, Serialize, Deserialize, Clone)]
@@ -366,40 +362,38 @@ mod tests {
366362
exclude: Some(false),
367363
enabled: None,
368364
};
369-
365+
370366
let serialized = serde_json::to_value(&reasoning).unwrap();
371367
let expected = json!({
372368
"effort": "high",
373369
"exclude": false
374370
});
375-
371+
376372
assert_eq!(serialized, expected);
377373
}
378374

379375
#[test]
380376
fn test_reasoning_max_tokens_serialization() {
381377
let reasoning = Reasoning {
382-
mode: Some(ReasoningMode::MaxTokens {
383-
max_tokens: 2000,
384-
}),
378+
mode: Some(ReasoningMode::MaxTokens { max_tokens: 2000 }),
385379
exclude: None,
386380
enabled: Some(true),
387381
};
388-
382+
389383
let serialized = serde_json::to_value(&reasoning).unwrap();
390384
let expected = json!({
391385
"max_tokens": 2000,
392386
"enabled": true
393387
});
394-
388+
395389
assert_eq!(serialized, expected);
396390
}
397391

398392
#[test]
399393
fn test_reasoning_deserialization() {
400394
let json_str = r#"{"effort": "medium", "exclude": true}"#;
401395
let reasoning: Reasoning = serde_json::from_str(json_str).unwrap();
402-
396+
403397
match reasoning.mode {
404398
Some(ReasoningMode::Effort { effort }) => {
405399
assert_eq!(effort, ReasoningEffort::Medium);
@@ -411,19 +405,16 @@ mod tests {
411405

412406
#[test]
413407
fn test_chat_completion_request_with_reasoning() {
414-
let mut req = ChatCompletionRequest::new(
415-
"gpt-4".to_string(),
416-
vec![],
417-
);
418-
408+
let mut req = ChatCompletionRequest::new("gpt-4".to_string(), vec![]);
409+
419410
req.reasoning = Some(Reasoning {
420411
mode: Some(ReasoningMode::Effort {
421412
effort: ReasoningEffort::Low,
422413
}),
423414
exclude: None,
424415
enabled: None,
425416
});
426-
417+
427418
let serialized = serde_json::to_value(&req).unwrap();
428419
assert_eq!(serialized["reasoning"]["effort"], "low");
429420
}

0 commit comments

Comments
 (0)