Skip to content

Commit 4415263

Browse files
committed
fix: refine proxy and timeout handling 🏓 #1
- Improve environment variable handling for proxy and timeout settings. - Remove default timeout.
1 parent 0cf51e0 commit 4415263

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/openai.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* File Created: 2025-03-01 21:55:58
1010
*
1111
* Modified By: mingcheng ([email protected])
12-
* Last Modified: 2025-03-05 10:46:26
12+
* Last Modified: 2025-03-06 17:59:08
1313
*/
1414

1515
use askama::Template;
@@ -66,17 +66,23 @@ impl OpenAI {
6666
});
6767

6868
// Set up proxy if specified
69-
let proxy_addr = env::var("OPENAI_APT_PROXY").unwrap_or_else(|_| String::from(""));
69+
let proxy_addr: String = env::var("OPENAI_APT_PROXY").unwrap_or_else(|_| String::from(""));
7070
if !proxy_addr.is_empty() {
7171
trace!("Using proxy: {}", proxy_addr);
7272
http_client_builder = http_client_builder.proxy(Proxy::all(proxy_addr).unwrap());
7373
}
7474

75+
let request_timeout =
76+
env::var("OPENAI_REQUEST_TIMEOUT").unwrap_or_else(|_| String::from(""));
77+
if !request_timeout.is_empty() {
78+
if let Ok(timeout) = request_timeout.parse::<u64>() {
79+
trace!("Setting request timeout to: {}ms", request_timeout);
80+
http_client_builder = http_client_builder.timeout(Duration::from_millis(timeout));
81+
}
82+
}
83+
7584
// Set up timeout and build the HTTP client
76-
let http_client = http_client_builder
77-
.timeout(Duration::from_secs(10))
78-
.build()
79-
.unwrap();
85+
let http_client = http_client_builder.build().unwrap();
8086

8187
let client = Client::with_config(ai_config).with_http_client(http_client);
8288
OpenAI { client }

0 commit comments

Comments
 (0)