@@ -4,7 +4,7 @@ mod prompt;
44use std:: env;
55
66pub use agent:: { Agent , run_agent} ;
7- use openai_api_rs:: v1:: api:: OpenAIClient ;
7+ use openai_api_rs:: v1:: { api:: OpenAIClient , common :: GPT3_5_TURBO } ;
88pub use prompt:: { PromptConfig , prompt_with_config} ;
99
1010use serde:: Deserialize ;
@@ -22,10 +22,37 @@ pub struct ModelConfig {
2222 pub model : Option < String > ,
2323}
2424
25+ // deepseek-chat
26+ const DEEPSEEK_CHAT : & str = "deepseek-chat" ;
27+
28+ /// We use OPENAI_API_KEY as default,
29+ /// buf if don't have OPENAI_API_KEY, we use DEEPSEEK_API_KEY and DEEPSEEK_API_ENDPOINT both
2530#[ allow( unused) ]
2631pub ( crate ) fn openai_client ( ) -> OpenAIClient {
27- OpenAIClient :: builder ( )
28- . with_api_key ( env:: var ( "OPENAI_API_KEY" ) . unwrap ( ) . to_string ( ) )
29- . build ( )
30- . unwrap ( )
32+ if let Ok ( api_key) = env:: var ( "OPENAI_API_KEY" ) {
33+ return OpenAIClient :: builder ( )
34+ . with_api_key ( api_key)
35+ . build ( )
36+ . unwrap ( ) ;
37+ }
38+ if let Ok ( api_key) = env:: var ( "DEEPSEEK_API_KEY" ) {
39+ let api_endpoint =
40+ env:: var ( "DEEPSEEK_API_ENDPOINT" ) . unwrap_or ( "https://api.deepseek.com" . to_string ( ) ) ;
41+ return OpenAIClient :: builder ( )
42+ . with_api_key ( api_key)
43+ . with_endpoint ( api_endpoint)
44+ . build ( )
45+ . unwrap ( ) ;
46+ }
47+ panic ! ( "No API key or endpoint found." ) ;
48+ }
49+
50+ pub ( crate ) fn default_model ( ) -> & ' static str {
51+ if env:: var ( "OPENAI_API_KEY" ) . is_ok ( ) {
52+ return GPT3_5_TURBO ;
53+ } else if env:: var ( "DEEPSEEK_API_KEY" ) . is_ok ( ) {
54+ return DEEPSEEK_CHAT ;
55+ } else {
56+ panic ! ( "No API key found." ) ;
57+ }
3158}
0 commit comments