File tree Expand file tree Collapse file tree 1 file changed +13
-8
lines changed Expand file tree Collapse file tree 1 file changed +13
-8
lines changed Original file line number Diff line number Diff line change @@ -51,15 +51,20 @@ impl OpenAI {
5151 self
5252 }
5353
54- pub fn use_env_proxy ( mut self ) -> Result < OpenAI , String > {
55- let mut proxy = std:: env:: var ( "http_proxy" ) ;
56- if let Err ( _) = proxy {
57- proxy = std:: env:: var ( "https_proxy" ) ;
54+ pub fn use_env_proxy ( mut self ) -> OpenAI {
55+ let proxy = match ( std:: env:: var ( "http_proxy" ) , std:: env:: var ( "https_proxy" ) ) {
56+ ( Ok ( http_proxy) , _) => Some ( http_proxy) ,
57+ ( _, Ok ( https_proxy) ) => Some ( https_proxy) ,
58+ _ => {
59+ log:: warn!( "Missing http_proxy or https_proxy" ) ;
60+ None
61+ }
62+ } ;
63+ if let Some ( proxy) = proxy {
64+ let proxy = ureq:: Proxy :: new ( & proxy) . unwrap ( ) ;
65+ self . agent = ureq:: AgentBuilder :: new ( ) . proxy ( proxy) . build ( ) ;
5866 }
59- let proxy = proxy. map_err ( |_| "Missing http_proxy or https_proxy" . to_string ( ) ) ?;
60- let proxy = ureq:: Proxy :: new ( proxy) . unwrap ( ) ;
61- self . agent = ureq:: AgentBuilder :: new ( ) . proxy ( proxy) . build ( ) ;
62- Ok ( self )
67+ self
6368 }
6469}
6570
You can’t perform that action at this time.
0 commit comments