@@ -8,38 +8,49 @@ use serde_json::json;
8
8
9
9
const OPENROUTER_REASONING_KEY : & str = "reasoning" ;
10
10
const OPENROUTER_BASEURL : & str = "https://openrouter.ai/api/v1" ;
11
+ const OPENROUTER_MODEL_NAME : & str = "deepseek/deepseek-r1" ;
11
12
const DEEPSEEK_REASONING_KEY : & str = "reasoning_content" ;
12
13
const DEEPSEEK_BASEURL : & str = "https://api.deepseek.com" ;
14
+ const DEEPSEEK_MODEL_NAME : & str = "deepseek-reasoner" ;
13
15
14
16
15
17
#[ tokio:: main( flavor = "current_thread" ) ]
16
18
async fn main ( ) {
17
19
let test_key = std:: env:: var ( "TEST_API_KEY" ) . unwrap ( ) ;
18
20
let use_deepseek = std:: env:: var ( "USE_DEEPSEEK" ) . is_ok ( ) ;
19
- let ( reasoning_key, base_url) = if use_deepseek {
20
- ( DEEPSEEK_REASONING_KEY , DEEPSEEK_BASEURL )
21
+ let ( reasoning_key, base_url, model_name ) = if use_deepseek {
22
+ ( DEEPSEEK_REASONING_KEY , DEEPSEEK_BASEURL , DEEPSEEK_MODEL_NAME )
21
23
} else {
22
- ( OPENROUTER_REASONING_KEY , OPENROUTER_BASEURL )
24
+ ( OPENROUTER_REASONING_KEY , OPENROUTER_BASEURL , OPENROUTER_MODEL_NAME )
23
25
} ;
24
26
let client = Client :: with_config (
25
27
OpenAIConfig :: new ( )
26
28
. with_api_base ( base_url)
27
29
. with_api_key ( test_key) ,
28
30
) ;
29
- let request = CreateChatCompletionRequestArgs :: default ( )
30
- . messages ( vec ! [ ChatCompletionRequestUserMessageArgs :: default ( )
31
- . content( "Hello! Do you know the Rust programming language?" )
31
+ let messages = vec ! [ ChatCompletionRequestUserMessageArgs :: default ( )
32
+ . content( "Hello! Do you know the Rust programming language?" )
33
+ . build( )
34
+ . unwrap( )
35
+ . into( ) ] ;
36
+ let request = if use_deepseek {
37
+ CreateChatCompletionRequestArgs :: default ( )
38
+ . messages ( messages)
39
+ . model ( model_name)
32
40
. build ( )
33
41
. unwrap ( )
34
- . into( ) ] )
35
- . model ( "deepseek/deepseek-r1" )
36
- // The extra params that OpenRouter requires to get reasoning content
37
- // See https://openrouter.ai/docs/api-reference/parameters#include-reasoning
38
- . extra_params ( json ! ( {
39
- "include_reasoning" : true
40
- } ) )
41
- . build ( )
42
- . unwrap ( ) ;
42
+ } else {
43
+ CreateChatCompletionRequestArgs :: default ( )
44
+ . messages ( messages)
45
+ . model ( model_name)
46
+ // The extra params that OpenRouter requires to get reasoning content
47
+ // See https://openrouter.ai/docs/api-reference/parameters#include-reasoning
48
+ . extra_params ( json ! ( {
49
+ "include_reasoning" : true
50
+ } ) )
51
+ . build ( )
52
+ . unwrap ( )
53
+ } ;
43
54
44
55
let mut result = client. chat ( ) . create_stream ( request) . await . unwrap ( ) ;
45
56
let mut reasoning = String :: new ( ) ;
0 commit comments