Skip to content

Commit c54d1c9

Browse files
zoo-github-actions-auth[bot]github-actions[bot]jessfraz
authored
Update api spec (#683)
* YOYO NEW API SPEC! * updates Signed-off-by: Jess Frazelle <[email protected]> --------- Signed-off-by: Jess Frazelle <[email protected]> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Jess Frazelle <[email protected]>
1 parent f3f831a commit c54d1c9

File tree

6 files changed

+849
-14
lines changed

6 files changed

+849
-14
lines changed

kittycad.rs.patch.json

+9-1
Original file line numberDiff line numberDiff line change
@@ -259,10 +259,18 @@
259259
"op": "add",
260260
"path": "/paths/~1ml~1text-to-cad~1iteration/post/x-rust",
261261
"value": {
262-
"example": "/// Iterate on a CAD model with a prompt.\n/// \n/// Even if you give specific ranges to edit, the model might change more than just those in order to make the changes you requested without breaking the code.\n/// \n/// You always get the whole code back, even if you only changed a small part of it.\n/// \n/// This operation is performed asynchronously, the `id` of the operation will be returned. You can use the `id` returned from the request to get status information about the async operation from the `/async/operations/{id}` endpoint.\nasync fn example_ml_create_text_to_cad_iteration() -> anyhow::Result<()> {\n let client = kittycad::Client::new_from_env();\n let result: kittycad::types::TextToCadIteration = client\n .ml()\n .create_text_to_cad_iteration(&kittycad::types::TextToCadIterationBody {\n original_source_code: \"some-string\".to_string(),\n prompt: Some(\"some-string\".to_string()),\n source_ranges: vec![kittycad::types::SourceRangePrompt {\n prompt: \"some-string\".to_string(),\n range: kittycad::types::SourceRange {\n end: kittycad::types::SourcePosition {\n column: 4 as u32,\n line: 4 as u32,\n },\n start: kittycad::types::SourcePosition {\n column: 4 as u32,\n line: 4 as u32,\n },\n },\n }],\n })\n .await?;\n println!(\"{:?}\", result);\n Ok(())\n}\n",
262+
"example": "/// Iterate on a CAD model with a prompt.\n/// \n/// Even if you give specific ranges to edit, the model might change more than just those in order to make the changes you requested without breaking the code.\n/// \n/// You always get the whole code back, even if you only changed a small part of it.\n/// \n/// This operation is performed asynchronously, the `id` of the operation will be returned. You can use the `id` returned from the request to get status information about the async operation from the `/async/operations/{id}` endpoint.\n/// \n/// This endpoint will soon be deprecated in favor of the `/ml/text-to-cad/multi-file/iteration` endpoint. In that the endpoint path will remain but it will have the same behavior as `ml/text-to-cad/multi-file/iteration`.\nasync fn example_ml_create_text_to_cad_iteration() -> anyhow::Result<()> {\n let client = kittycad::Client::new_from_env();\n let result: kittycad::types::TextToCadIteration = client\n .ml()\n .create_text_to_cad_iteration(&kittycad::types::TextToCadIterationBody {\n original_source_code: \"some-string\".to_string(),\n prompt: Some(\"some-string\".to_string()),\n source_ranges: vec![kittycad::types::SourceRangePrompt {\n file: Some(\"some-string\".to_string()),\n prompt: \"some-string\".to_string(),\n range: kittycad::types::SourceRange {\n end: kittycad::types::SourcePosition {\n column: 4 as u32,\n line: 4 as u32,\n },\n start: kittycad::types::SourcePosition {\n column: 4 as u32,\n line: 4 as u32,\n },\n },\n }],\n })\n .await?;\n println!(\"{:?}\", result);\n Ok(())\n}\n",
263263
"libDocsLink": "https://docs.rs/kittycad/latest/kittycad/ml/struct.Ml.html#method.create_text_to_cad_iteration"
264264
}
265265
},
266+
{
267+
"op": "add",
268+
"path": "/paths/~1ml~1text-to-cad~1multi-file~1iteration/post/x-rust",
269+
"value": {
270+
"example": "/// Iterate on a CAD model with a prompt.\n/// \n/// This endpoint can iterate on multi-file models.\n/// \n/// Even if you give specific ranges to edit, the model might change more than just those in order to make the changes you requested without breaking the code.\n/// \n/// You always get the whole code back, even if you only changed a small part of it. This endpoint will always return all the code back, including files that were not changed. If your original source code imported a stl/gltf/step/etc file, the output will not include that file since the model will never change non-kcl files. The endpoint will only return the kcl files that were changed.\n/// \n/// This operation is performed asynchronously, the `id` of the operation will be returned. You can use the `id` returned from the request to get status information about the async operation from the `/async/operations/{id}` endpoint.\nasync fn example_ml_create_text_to_cad_multi_file_iteration() -> anyhow::Result<()> {\n let client = kittycad::Client::new_from_env();\n let result: kittycad::types::TextToCadMultiFileIteration = client\n .ml()\n .create_text_to_cad_multi_file_iteration(\n vec![kittycad::types::multipart::Attachment {\n name: \"thing\".to_string(),\n filename: Some(\"myfile.json\".to_string()),\n content_type: Some(\"application/json\".to_string()),\n data: std::fs::read(\"myfile.json\").unwrap(),\n }],\n &kittycad::types::TextToCadMultiFileIterationBody {\n source_ranges: vec![kittycad::types::SourceRangePrompt {\n file: Some(\"some-string\".to_string()),\n prompt: \"some-string\".to_string(),\n range: kittycad::types::SourceRange {\n end: kittycad::types::SourcePosition {\n column: 4 as u32,\n line: 4 as u32,\n },\n start: kittycad::types::SourcePosition {\n column: 4 as u32,\n line: 4 as u32,\n },\n },\n }],\n },\n )\n .await?;\n println!(\"{:?}\", result);\n Ok(())\n}\n",
271+
"libDocsLink": "https://docs.rs/kittycad/latest/kittycad/ml/struct.Ml.html#method.create_text_to_cad_multi_file_iteration"
272+
}
273+
},
266274
{
267275
"op": "add",
268276
"path": "/paths/~1oauth2~1device~1auth/post/x-rust",

kittycad/src/ml.rs

+46-1
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ impl Ml {
245245
}
246246
}
247247

248-
#[doc = "Iterate on a CAD model with a prompt.\n\nEven if you give specific ranges to edit, the model might change more than just those in order to make the changes you requested without breaking the code.\n\nYou always get the whole code back, even if you only changed a small part of it.\n\nThis operation is performed asynchronously, the `id` of the operation will be returned. You can use the `id` returned from the request to get status information about the async operation from the `/async/operations/{id}` endpoint.\n\n```rust,no_run\nasync fn example_ml_create_text_to_cad_iteration() -> anyhow::Result<()> {\n let client = kittycad::Client::new_from_env();\n let result: kittycad::types::TextToCadIteration = client\n .ml()\n .create_text_to_cad_iteration(&kittycad::types::TextToCadIterationBody {\n original_source_code: \"some-string\".to_string(),\n prompt: Some(\"some-string\".to_string()),\n source_ranges: vec![kittycad::types::SourceRangePrompt {\n prompt: \"some-string\".to_string(),\n range: kittycad::types::SourceRange {\n end: kittycad::types::SourcePosition {\n column: 4 as u32,\n line: 4 as u32,\n },\n start: kittycad::types::SourcePosition {\n column: 4 as u32,\n line: 4 as u32,\n },\n },\n }],\n })\n .await?;\n println!(\"{:?}\", result);\n Ok(())\n}\n```"]
248+
#[doc = "Iterate on a CAD model with a prompt.\n\nEven if you give specific ranges to edit, the model might change more than just those in order to make the changes you requested without breaking the code.\n\nYou always get the whole code back, even if you only changed a small part of it.\n\nThis operation is performed asynchronously, the `id` of the operation will be returned. You can use the `id` returned from the request to get status information about the async operation from the `/async/operations/{id}` endpoint.\n\nThis endpoint will soon be deprecated in favor of the `/ml/text-to-cad/multi-file/iteration` endpoint. In that the endpoint path will remain but it will have the same behavior as `ml/text-to-cad/multi-file/iteration`.\n\n```rust,no_run\nasync fn example_ml_create_text_to_cad_iteration() -> anyhow::Result<()> {\n let client = kittycad::Client::new_from_env();\n let result: kittycad::types::TextToCadIteration = client\n .ml()\n .create_text_to_cad_iteration(&kittycad::types::TextToCadIterationBody {\n original_source_code: \"some-string\".to_string(),\n prompt: Some(\"some-string\".to_string()),\n source_ranges: vec![kittycad::types::SourceRangePrompt {\n file: Some(\"some-string\".to_string()),\n prompt: \"some-string\".to_string(),\n range: kittycad::types::SourceRange {\n end: kittycad::types::SourcePosition {\n column: 4 as u32,\n line: 4 as u32,\n },\n start: kittycad::types::SourcePosition {\n column: 4 as u32,\n line: 4 as u32,\n },\n },\n }],\n })\n .await?;\n println!(\"{:?}\", result);\n Ok(())\n}\n```"]
249249
#[tracing::instrument]
250250
pub async fn create_text_to_cad_iteration<'a>(
251251
&'a self,
@@ -276,6 +276,51 @@ impl Ml {
276276
}
277277
}
278278

279+
#[doc = "Iterate on a CAD model with a prompt.\n\nThis endpoint can iterate on multi-file models.\n\nEven if you give specific ranges to edit, the model might change more than just those in order to make the changes you requested without breaking the code.\n\nYou always get the whole code back, even if you only changed a small part of it. This endpoint will always return all the code back, including files that were not changed. If your original source code imported a stl/gltf/step/etc file, the output will not include that file since the model will never change non-kcl files. The endpoint will only return the kcl files that were changed.\n\nThis operation is performed asynchronously, the `id` of the operation will be returned. You can use the `id` returned from the request to get status information about the async operation from the `/async/operations/{id}` endpoint.\n\n```rust,no_run\nasync fn example_ml_create_text_to_cad_multi_file_iteration() -> anyhow::Result<()> {\n let client = kittycad::Client::new_from_env();\n let result: kittycad::types::TextToCadMultiFileIteration = client\n .ml()\n .create_text_to_cad_multi_file_iteration(\n vec![kittycad::types::multipart::Attachment {\n name: \"thing\".to_string(),\n filename: Some(\"myfile.json\".to_string()),\n content_type: Some(\"application/json\".to_string()),\n data: std::fs::read(\"myfile.json\").unwrap(),\n }],\n &kittycad::types::TextToCadMultiFileIterationBody {\n source_ranges: vec![kittycad::types::SourceRangePrompt {\n file: Some(\"some-string\".to_string()),\n prompt: \"some-string\".to_string(),\n range: kittycad::types::SourceRange {\n end: kittycad::types::SourcePosition {\n column: 4 as u32,\n line: 4 as u32,\n },\n start: kittycad::types::SourcePosition {\n column: 4 as u32,\n line: 4 as u32,\n },\n },\n }],\n },\n )\n .await?;\n println!(\"{:?}\", result);\n Ok(())\n}\n```"]
280+
#[tracing::instrument]
281+
pub async fn create_text_to_cad_multi_file_iteration<'a>(
282+
&'a self,
283+
attachments: Vec<crate::types::multipart::Attachment>,
284+
body: &crate::types::TextToCadMultiFileIterationBody,
285+
) -> Result<crate::types::TextToCadMultiFileIteration, crate::types::error::Error> {
286+
let mut req = self.client.client.request(
287+
http::Method::POST,
288+
format!(
289+
"{}/{}",
290+
self.client.base_url, "ml/text-to-cad/multi-file/iteration"
291+
),
292+
);
293+
req = req.bearer_auth(&self.client.token);
294+
use std::convert::TryInto;
295+
let mut form = reqwest::multipart::Form::new();
296+
let mut json_part = reqwest::multipart::Part::text(serde_json::to_string(&body)?);
297+
json_part = json_part.file_name(format!("{}.json", "texttocadmultifileiterationbody"));
298+
json_part = json_part.mime_str("application/json")?;
299+
form = form.part("texttocadmultifileiterationbody", json_part);
300+
for attachment in attachments {
301+
form = form.part(attachment.name.clone(), attachment.try_into()?);
302+
}
303+
304+
req = req.multipart(form);
305+
let resp = req.send().await?;
306+
let status = resp.status();
307+
if status.is_success() {
308+
let text = resp.text().await.unwrap_or_default();
309+
serde_json::from_str(&text).map_err(|err| {
310+
crate::types::error::Error::from_serde_error(
311+
format_serde_error::SerdeError::new(text.to_string(), err),
312+
status,
313+
)
314+
})
315+
} else {
316+
let text = resp.text().await.unwrap_or_default();
317+
Err(crate::types::error::Error::Server {
318+
body: text.to_string(),
319+
status,
320+
})
321+
}
322+
}
323+
279324
#[doc = "List text-to-CAD models you've generated.\n\nThis will always return the STEP file contents as well as the format the user originally requested.\n\nThis endpoint requires authentication by any Zoo user. It returns the text-to-CAD models for the authenticated user.\n\nThe text-to-CAD models are returned in order of creation, with the most recently created text-to-CAD models first.\n\n**Parameters:**\n\n- `limit: Option<u32>`: Maximum number of items returned by a single call\n- `no_models: Option<bool>`: If we should return the model file contents or just the metadata.\n- `page_token: Option<String>`: Token returned by previous call to retrieve the subsequent page\n- `sort_by: Option<crate::types::CreatedAtSortMode>`\n\n```rust,no_run\nuse futures_util::TryStreamExt;\nasync fn example_ml_list_text_to_cad_models_for_user_stream() -> anyhow::Result<()> {\n let client = kittycad::Client::new_from_env();\n let mut ml = client.ml();\n let mut stream = ml.list_text_to_cad_models_for_user_stream(\n Some(4 as u32),\n Some(false),\n Some(kittycad::types::CreatedAtSortMode::CreatedAtDescending),\n );\n loop {\n match stream.try_next().await {\n Ok(Some(item)) => {\n println!(\"{:?}\", item);\n }\n Ok(None) => {\n break;\n }\n Err(err) => {\n return Err(err.into());\n }\n }\n }\n\n Ok(())\n}\n```"]
280325
#[tracing::instrument]
281326
pub async fn list_text_to_cad_models_for_user<'a>(

kittycad/src/tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ async fn test_create_file_volume() {
7474
.await
7575
.unwrap();
7676

77-
assert_eq!(result.volume.map(|x| x.round()), Some(54.0));
77+
assert_eq!(result.volume.map(|x| (x * 1000000.0).round()), Some(0.0));
7878

7979
assert_eq!(result.src_format, crate::types::FileImportFormat::Obj);
8080
assert_eq!(result.status, crate::types::ApiCallStatus::Completed);

0 commit comments

Comments
 (0)