File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -11,25 +11,23 @@ pub struct GPT {
1111
1212impl GPT {
1313 pub fn new ( api_key : Option < String > ) -> Self {
14- match std:: env:: var ( "OPENAI_API_KEY" ) {
15- Ok ( key) => Self {
16- client : reqwest:: blocking:: Client :: new ( ) ,
17- openai_api_key : key,
18- } ,
19- Err ( _) => match api_key {
20- Some ( key) => Self {
21- client : reqwest:: blocking:: Client :: new ( ) ,
22- openai_api_key : key,
23- } ,
24- None => {
14+ let openai_api_key = match std:: env:: var ( "OPENAI_API_KEY" ) {
15+ Ok ( key) => key,
16+ Err ( _) => api_key
17+ . ok_or_else ( || {
2518 eprintln ! (
2619 r#"Can not find the openai api key
2720You need to define one wether in the configuration file or as an environment variable"#
2821 ) ;
2922
3023 std:: process:: exit ( 1 ) ;
31- }
32- } ,
24+ } )
25+ . unwrap ( ) ,
26+ } ;
27+
28+ Self {
29+ client : reqwest:: blocking:: Client :: new ( ) ,
30+ openai_api_key,
3331 }
3432 }
3533
You can’t perform that action at this time.
0 commit comments