142 lines
4.2 KiB
Rust
142 lines
4.2 KiB
Rust
use text_video_agent_client::apis::configuration::Configuration;
|
|
use text_video_agent_client::apis::llm_api;
|
|
use std::io::{self, Write};
|
|
|
|
#[tokio::main]
|
|
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|
// 创建支持 HTTPS 的客户端
|
|
let client = reqwest::Client::builder()
|
|
.timeout(std::time::Duration::from_secs(30))
|
|
.build()?;
|
|
|
|
// 创建配置
|
|
let config = Configuration {
|
|
base_path: "https://bowongai-dev--text-video-agent-fastapi-app.modal.run".to_string(),
|
|
user_agent: Some("text-video-agent-rust-client/1.0.6".to_string()),
|
|
client,
|
|
basic_auth: None,
|
|
oauth_access_token: None,
|
|
bearer_access_token: None,
|
|
api_key: None,
|
|
};
|
|
|
|
println!("🤖 大语言模型聊天测试");
|
|
println!("====================");
|
|
println!("API 地址: {}", config.base_path);
|
|
println!();
|
|
|
|
// 1. 获取支持的模型列表
|
|
println!("📋 获取支持的模型列表...");
|
|
match llm_api::llm_supported_models(&config).await {
|
|
Ok(models) => {
|
|
println!("✅ 支持的模型: {}", models);
|
|
}
|
|
Err(e) => {
|
|
println!("❌ 获取模型列表失败: {:?}", e);
|
|
return Ok(());
|
|
}
|
|
}
|
|
println!();
|
|
|
|
// 2. 测试基本聊天功能
|
|
println!("💬 测试基本聊天功能...");
|
|
let test_prompts = vec![
|
|
"你好,请介绍一下你自己",
|
|
"什么是人工智能?",
|
|
"请用中文回答:今天天气怎么样?",
|
|
"帮我写一首关于春天的诗",
|
|
];
|
|
|
|
for (i, prompt) in test_prompts.iter().enumerate() {
|
|
println!("🔸 测试 {}: {}", i + 1, prompt);
|
|
|
|
match llm_api::llm_chat(
|
|
&config,
|
|
prompt,
|
|
None, // model_name: 使用默认模型
|
|
Some(0.7), // temperature: 创造性参数
|
|
Some(1000), // max_tokens: 最大令牌数
|
|
Some(30.0), // timeout: 超时时间(秒)
|
|
).await {
|
|
Ok(response) => {
|
|
println!("✅ 回复: {}", response);
|
|
}
|
|
Err(e) => {
|
|
println!("❌ 聊天错误: {:?}", e);
|
|
}
|
|
}
|
|
println!();
|
|
|
|
// 添加延迟避免请求过于频繁
|
|
tokio::time::sleep(tokio::time::Duration::from_secs(2)).await;
|
|
}
|
|
|
|
// 3. 测试 Gemini 聊天
|
|
println!("🌟 测试 Gemini 聊天...");
|
|
match llm_api::invoke_gemini_ai_api_llm_google_chat_post(
|
|
&config,
|
|
"请用中文简单介绍一下 Rust 编程语言的特点",
|
|
Some(30.0), // timeout
|
|
).await {
|
|
Ok(response) => {
|
|
println!("✅ Gemini 回复: {}", response);
|
|
}
|
|
Err(e) => {
|
|
println!("❌ Gemini 聊天错误: {:?}", e);
|
|
}
|
|
}
|
|
println!();
|
|
|
|
// 4. 交互式聊天(可选)
|
|
println!("🎯 想要进行交互式聊天吗?(y/n)");
|
|
print!("> ");
|
|
io::stdout().flush()?;
|
|
|
|
let mut input = String::new();
|
|
io::stdin().read_line(&mut input)?;
|
|
|
|
if input.trim().to_lowercase() == "y" {
|
|
println!("💭 进入交互式聊天模式(输入 'quit' 退出):");
|
|
|
|
loop {
|
|
print!("您: ");
|
|
io::stdout().flush()?;
|
|
|
|
let mut user_input = String::new();
|
|
io::stdin().read_line(&mut user_input)?;
|
|
let user_input = user_input.trim();
|
|
|
|
if user_input == "quit" {
|
|
break;
|
|
}
|
|
|
|
if user_input.is_empty() {
|
|
continue;
|
|
}
|
|
|
|
print!("🤖 思考中...");
|
|
io::stdout().flush()?;
|
|
|
|
match llm_api::llm_chat(
|
|
&config,
|
|
user_input,
|
|
None,
|
|
Some(0.7),
|
|
Some(1000),
|
|
Some(30.0),
|
|
).await {
|
|
Ok(response) => {
|
|
println!("\r🤖 AI: {}", response);
|
|
}
|
|
Err(e) => {
|
|
println!("\r❌ 错误: {:?}", e);
|
|
}
|
|
}
|
|
println!();
|
|
}
|
|
}
|
|
|
|
println!("👋 聊天测试完成!");
|
|
Ok(())
|
|
}
|