Skip to content

Commit

Permalink
better docs
Browse files Browse the repository at this point in the history
Signed-off-by: Jess Frazelle <github@jessfraz.com>
  • Loading branch information
jessfraz committed Sep 20, 2024
1 parent a067e14 commit 017c260
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "zoo"
version = "0.2.79"
version = "0.2.80"
edition = "2021"
build = "build.rs"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
28 changes: 21 additions & 7 deletions src/cmd_ml/cmd_text_to_cad.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use kcmc::each_cmd as mcmd;
use kcmc::format::InputFormat;
use kcmc::ok_response::OkModelingCmdResponse;
use kcmc::websocket::OkWebSocketResponseData;
use kcmc::{shared::FileExportFormat, ImageFormat, ModelingCmd};
use kcmc::{ImageFormat, ModelingCmd};
use kittycad_modeling_cmds::{self as kcmc, ImportFile};

/// Perform Text-to-CAD commands.
Expand Down Expand Up @@ -51,7 +51,7 @@ pub struct CmdTextToCadExport {

/// A valid output file format.
#[clap(short = 't', long = "output-format", value_enum)]
output_format: FileExportFormat,
output_format: kittycad::types::FileExportFormat,

/// Command output format.
#[clap(long, short, value_enum)]
Expand Down Expand Up @@ -81,7 +81,9 @@ impl crate::cmd::Command for CmdTextToCadExport {
anyhow::bail!("prompt cannot be empty");
}

let mut model = ctx.get_model_for_prompt("", &prompt, self.output_format).await?;
let mut model = ctx
.get_model_for_prompt("", &prompt, self.output_format.clone())
.await?;

if let Some(outputs) = model.outputs {
// Write the contents of the files to the output directory.
Expand Down Expand Up @@ -131,7 +133,7 @@ pub struct CmdTextToCadSnapshot {

/// A valid output image format.
#[clap(short = 't', long = "output-format", value_enum, default_value = "png")]
output_format: ImageFormat,
output_format: kittycad::types::ImageFormat,

/// Command output format.
#[clap(long, short, value_enum)]
Expand Down Expand Up @@ -161,7 +163,9 @@ impl crate::cmd::Command for CmdTextToCadSnapshot {
anyhow::bail!("prompt cannot be empty");
}

let model = ctx.get_model_for_prompt("", &prompt, FileExportFormat::Gltf).await?;
let model = ctx
.get_model_for_prompt("", &prompt, kittycad::types::FileExportFormat::Gltf)
.await?;

// Get the gltf bytes.
let mut gltf_bytes = vec![];
Expand All @@ -179,7 +183,15 @@ impl crate::cmd::Command for CmdTextToCadSnapshot {
let output_file = prompt.replace(' ', "_").to_lowercase() + "." + &self.output_format.to_string();
let output_file_path = output_dir.join(&output_file);

let image_bytes = get_image_bytes(ctx, &gltf_bytes, self.output_format.clone()).await?;
let image_bytes = get_image_bytes(
ctx,
&gltf_bytes,
match self.output_format {
kittycad::types::ImageFormat::Png => ImageFormat::Png,
kittycad::types::ImageFormat::Jpeg => ImageFormat::Jpeg,
},
)
.await?;
// Save the snapshot locally.
std::fs::write(&output_file_path, image_bytes)?;

Expand Down Expand Up @@ -217,7 +229,9 @@ impl crate::cmd::Command for CmdTextToCadView {
anyhow::bail!("prompt cannot be empty");
}

let model = ctx.get_model_for_prompt("", &prompt, FileExportFormat::Gltf).await?;
let model = ctx
.get_model_for_prompt("", &prompt, kittycad::types::FileExportFormat::Gltf)
.await?;

// Get the gltf bytes.
let mut gltf_bytes = vec![];
Expand Down
12 changes: 11 additions & 1 deletion src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,20 @@ impl Context<'_> {
&self,
hostname: &str,
prompt: &str,
format: FileExportFormat,
format: kittycad::types::FileExportFormat,
) -> Result<TextToCad> {
let client = self.api_client(hostname)?;

let format = match format {
kittycad::types::FileExportFormat::Fbx => FileExportFormat::Fbx,
kittycad::types::FileExportFormat::Glb => FileExportFormat::Glb,
kittycad::types::FileExportFormat::Obj => FileExportFormat::Obj,
kittycad::types::FileExportFormat::Ply => FileExportFormat::Ply,
kittycad::types::FileExportFormat::Stl => FileExportFormat::Stl,
kittycad::types::FileExportFormat::Gltf => FileExportFormat::Gltf,
kittycad::types::FileExportFormat::Step => FileExportFormat::Step,
};

// Create the text-to-cad request.
let mut gen_model: TextToCad = client
.ml()
Expand Down

0 comments on commit 017c260

Please sign in to comment.