完善Tripo冒烟CLI产物流程
等待三类生成任务完成并打印映射后的输出 完成后下载模型产物到当前目录并输出文件信息 仅在示例内部使用SDK轮询器,不扩展平台公共接口
This commit is contained in:
@@ -8,10 +8,11 @@
|
||||
//! --manifest-path server-rs/Cargo.toml
|
||||
//! ```
|
||||
//!
|
||||
//! The example performs one-shot task queries after submission. It does not
|
||||
//! expose or call the SDK's polling helpers.
|
||||
//! The example waits for each submitted task to finish, prints its mapped
|
||||
//! output, and writes the downloaded model into the current directory. The
|
||||
//! SDK poller is used only here and is not exposed by `platform-tripo`.
|
||||
|
||||
use std::{env, time::Duration};
|
||||
use std::{env, fs, time::Duration};
|
||||
|
||||
use platform_tripo::TripoProviderClient;
|
||||
use shared_contracts::model3d::{
|
||||
@@ -20,6 +21,7 @@ use shared_contracts::model3d::{
|
||||
multiview_to_model::{Model3dMultiviewInputs, Model3dMultiviewToModelRequest},
|
||||
text_to_model::Model3dTextToModelRequest,
|
||||
};
|
||||
use tripo3d_sdk::{ClientOptions, TripoClient, WaitOptions};
|
||||
|
||||
const SAMPLE_IMAGE_URL: &str =
|
||||
"https://raw.githubusercontent.com/VAST-AI-Research/tripo-python-sdk/master/example.png";
|
||||
@@ -28,6 +30,13 @@ const SAMPLE_IMAGE_URL: &str =
|
||||
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let api_key = required_env("TRIPO_API_KEY")?;
|
||||
let base_url = required_env("TRIPO_BASE_URL")?;
|
||||
let sdk_client = TripoClient::new(ClientOptions {
|
||||
api_key: Some(api_key.clone()),
|
||||
base_url: Some(base_url.clone()),
|
||||
timeout: Some(Duration::from_secs(60)),
|
||||
retries: Some(2),
|
||||
user_agent: Some("genarrative-tripo-smoke/1".to_string()),
|
||||
})?;
|
||||
let client = TripoProviderClient::new(platform_tripo::TripoSettings::new(
|
||||
api_key,
|
||||
base_url,
|
||||
@@ -125,10 +134,32 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
("image_to_model", image),
|
||||
("multiview_to_model", multiview),
|
||||
] {
|
||||
// The SDK poller is used only by this smoke example. It is not part
|
||||
// of the platform-tripo public API.
|
||||
sdk_client
|
||||
.wait_for_task(
|
||||
&handle.task_id,
|
||||
WaitOptions {
|
||||
timeout: Some(Duration::from_secs(30 * 60)),
|
||||
..WaitOptions::default()
|
||||
},
|
||||
)
|
||||
.await?;
|
||||
|
||||
let snapshot = client.get_task(&handle).await?;
|
||||
println!(
|
||||
"{name} status={:?} progress={:?}",
|
||||
snapshot.status, snapshot.progress
|
||||
"{name} status={:?} progress={:?} output={:?}",
|
||||
snapshot.status, snapshot.progress, snapshot.output
|
||||
);
|
||||
|
||||
let downloaded = client.download_model(&snapshot).await?;
|
||||
let filename = downloaded.filename(name);
|
||||
fs::write(&filename, &downloaded.data)?;
|
||||
println!(
|
||||
"{name} artifact={} bytes={} url={}",
|
||||
filename,
|
||||
downloaded.data.len(),
|
||||
downloaded.url
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user