feat: 添加 VEO3 场景写作和角色定义 SDK
- 新增 gemini-sdk: 基于 Gemini AI 的通用 SDK - 新增 veo3-scene-writer: VEO3 场景写作专用工具 - 支持图片/视频附件分析 - 多轮会话功能 - VEO3 专业提示词集成 - 角色一致性管理 - 新增 Veo3ActorDefine: 角色定义专用工具 - 添加完整的示例和文档 - 支持多种输出格式 (文本/JSON/YAML)
This commit is contained in:
119
cargos/gemini-sdk/examples/basic_usage.rs
Normal file
119
cargos/gemini-sdk/examples/basic_usage.rs
Normal file
@@ -0,0 +1,119 @@
|
||||
//! Basic usage example for the Gemini SDK
|
||||
|
||||
use gemini_sdk::{GeminiSDK, MessageRequest, Agent};
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
// Initialize SDK
|
||||
let mut sdk = GeminiSDK::new()?;
|
||||
|
||||
// Example 1: Simple text message
|
||||
println!("=== Example 1: Simple text message ===");
|
||||
let request = MessageRequest::text_only("Hello, how are you?");
|
||||
|
||||
match sdk.send_message(request).await {
|
||||
Ok(response) => {
|
||||
println!("Response: {}", response.content);
|
||||
}
|
||||
Err(e) => {
|
||||
println!("Error: {}", e);
|
||||
}
|
||||
}
|
||||
|
||||
// Example 2: Using an agent
|
||||
println!("\n=== Example 2: Using an agent ===");
|
||||
let agent = Agent::new(
|
||||
"helpful_assistant",
|
||||
"Helpful Assistant",
|
||||
"You are a helpful assistant that provides clear and concise answers."
|
||||
).with_temperature(0.7);
|
||||
|
||||
sdk.add_agent(agent);
|
||||
|
||||
let request = MessageRequest::with_agent(
|
||||
"Explain quantum computing in simple terms",
|
||||
"helpful_assistant"
|
||||
);
|
||||
|
||||
match sdk.send_message(request).await {
|
||||
Ok(response) => {
|
||||
println!("Agent response: {}", response.content);
|
||||
}
|
||||
Err(e) => {
|
||||
println!("Error: {}", e);
|
||||
}
|
||||
}
|
||||
|
||||
// Example 3: Message with image attachment (commented out as it requires a real image file)
|
||||
/*
|
||||
println!("\n=== Example 3: Message with image attachment ===");
|
||||
let request = MessageRequest::with_attachments(
|
||||
"What do you see in this image?",
|
||||
vec![Attachment::new("./example.jpg")]
|
||||
);
|
||||
|
||||
match sdk.send_message(request).await {
|
||||
Ok(response) => {
|
||||
println!("Image analysis: {}", response.content);
|
||||
}
|
||||
Err(e) => {
|
||||
println!("Error: {}", e);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
// Example 4: Creating a specialized agent
|
||||
println!("\n=== Example 4: Creating a specialized agent ===");
|
||||
let code_agent = Agent::new(
|
||||
"code_reviewer",
|
||||
"Code Reviewer",
|
||||
r#"You are an expert code reviewer. When given code, you should:
|
||||
1. Analyze the code for potential bugs or issues
|
||||
2. Suggest improvements for readability and performance
|
||||
3. Check for best practices and coding standards
|
||||
4. Provide constructive feedback
|
||||
|
||||
Always be specific and provide examples when possible."#
|
||||
).with_temperature(0.3) // Lower temperature for more focused responses
|
||||
.with_max_tokens(4096);
|
||||
|
||||
sdk.add_agent(code_agent);
|
||||
|
||||
let code_example = r#"
|
||||
def fibonacci(n):
|
||||
if n <= 1:
|
||||
return n
|
||||
else:
|
||||
return fibonacci(n-1) + fibonacci(n-2)
|
||||
|
||||
print(fibonacci(10))
|
||||
"#;
|
||||
|
||||
let request = MessageRequest::with_agent(
|
||||
format!("Please review this Python code:\n\n```python{}\n```", code_example),
|
||||
"code_reviewer"
|
||||
);
|
||||
|
||||
match sdk.send_message(request).await {
|
||||
Ok(response) => {
|
||||
println!("Code review: {}", response.content);
|
||||
}
|
||||
Err(e) => {
|
||||
println!("Error: {}", e);
|
||||
}
|
||||
}
|
||||
|
||||
// Example 5: List all agents
|
||||
println!("\n=== Example 5: List all agents ===");
|
||||
let agents = sdk.list_agents();
|
||||
for agent in agents {
|
||||
println!("Agent: {} (ID: {})", agent.name, agent.id);
|
||||
println!(" Temperature: {}", agent.temperature);
|
||||
println!(" Max tokens: {}", agent.max_tokens);
|
||||
println!(" System prompt: {}...",
|
||||
agent.system_prompt.chars().take(50).collect::<String>());
|
||||
println!();
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Reference in New Issue
Block a user