11use 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+ } ;
35use 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
0 commit comments