test_https_proxy/
test_https_proxy.rs1use ai_lib::{AiClient, Provider, ChatCompletionRequest, Message, Role};
2
3#[tokio::main]
4async fn main() -> Result<(), Box<dyn std::error::Error>> {
5 println!("🔒 HTTPS代理测试");
6 println!("================");
7
8 std::env::set_var("AI_PROXY_URL", "https://192.168.2.13:8889");
10 println!("🌐 使用HTTPS代理: https://192.168.2.13:8889");
11
12 if std::env::var("OPENAI_API_KEY").is_err() {
13 println!("❌ 未设置OPENAI_API_KEY");
14 return Ok(());
15 }
16
17 println!("\n🤖 测试OpenAI (HTTPS代理):");
19 let client = AiClient::new(Provider::OpenAI)?;
20
21 let request = ChatCompletionRequest::new(
22 "gpt-3.5-turbo".to_string(),
23 vec![Message {
24 role: Role::User,
25 content: "Say 'HTTPS proxy works!' exactly.".to_string(),
26 }],
27 ).with_max_tokens(10);
28
29 match client.chat_completion(request).await {
30 Ok(response) => {
31 println!("✅ HTTPS代理测试成功!");
32 println!(" 响应: '{}'", response.choices[0].message.content);
33 println!(" Token使用: {}", response.usage.total_tokens);
34 }
35 Err(e) => {
36 println!("❌ HTTPS代理测试失败: {}", e);
37
38 let error_str = e.to_string();
40 if error_str.contains("you must provide a model parameter") {
41 println!(" → 这可能是代理服务器的问题,而不是HTTPS协议问题");
42 } else if error_str.contains("certificate") || error_str.contains("tls") {
43 println!(" → HTTPS证书或TLS相关问题");
44 } else if error_str.contains("connection") {
45 println!(" → 连接问题,可能是代理服务器配置");
46 }
47 }
48 }
49
50 println!("\n🚀 测试Groq (HTTPS代理对比):");
52 if std::env::var("GROQ_API_KEY").is_ok() {
53 let groq_client = AiClient::new(Provider::Groq)?;
54 let groq_request = ChatCompletionRequest::new(
55 "llama3-8b-8192".to_string(),
56 vec![Message {
57 role: Role::User,
58 content: "Say 'Groq HTTPS proxy works!' exactly.".to_string(),
59 }],
60 ).with_max_tokens(10);
61
62 match groq_client.chat_completion(groq_request).await {
63 Ok(response) => {
64 println!("✅ Groq HTTPS代理成功!");
65 println!(" 响应: '{}'", response.choices[0].message.content);
66 }
67 Err(e) => {
68 println!("❌ Groq HTTPS代理失败: {}", e);
69 }
70 }
71 }
72
73 println!("\n💡 HTTPS代理测试结论:");
74 println!(" • 如果Groq成功而OpenAI失败,说明是OpenAI特定问题");
75 println!(" • 如果都失败,可能是HTTPS代理配置问题");
76 println!(" • 如果都成功,说明HTTPS代理完全支持");
77
78 Ok(())
79}