Skip to content

Commit

Permalink
Update api spec (#262)
Browse files Browse the repository at this point in the history
* YOYO NEW API SPEC!

* I have generated the library!

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
jessfraz and github-actions[bot] authored Oct 17, 2023
1 parent 0525877 commit 4d1edc8
Show file tree
Hide file tree
Showing 6 changed files with 1,416 additions and 459 deletions.
30 changes: 19 additions & 11 deletions kittycad.rs.patch.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,10 @@
},
{
"op": "add",
"path": "/paths/~1ai~1image-to-3d~1{input_format}~1{output_format}/post/x-rust",
"path": "/paths/~1ai~1text-to-cad~1{output_format}/post/x-rust",
"value": {
"example": "/// Generate a 3D model from an image.\n/// \n/// This is an alpha endpoint. It will change in the future. The current output is honestly pretty bad. So if you find this endpoint, you get what you pay for, which currently is nothing. But in the future will be made a lot better.\n/// \n/// **Parameters:**\n/// \n/// - `input_format: crate::types::ImageType`: The format of the image being converted. (required)\n/// - `output_format: crate::types::FileExportFormat`: The format the output file should be converted to. (required)\nasync fn example_ai_create_image_to_3d() -> anyhow::Result<()> {\n let client = kittycad::Client::new_from_env();\n let result: kittycad::types::Mesh = client\n .ai()\n .create_image_to_3d(\n kittycad::types::ImageType::Jpg,\n kittycad::types::FileExportFormat::Stl,\n &bytes::Bytes::from(\"some-string\"),\n )\n .await?;\n println!(\"{:?}\", result);\n Ok(())\n}\n",
"libDocsLink": "https://docs.rs/kittycad/latest/kittycad/ai/struct.Ai.html#method.create_image_to_3d"
}
},
{
"op": "add",
"path": "/paths/~1ai~1text-to-3d~1{output_format}/post/x-rust",
"value": {
"example": "/// Generate a 3D model from text.\n/// \n/// This is an alpha endpoint. It will change in the future. The current output is honestly pretty bad. So if you find this endpoint, you get what you pay for, which currently is nothing. But in the future will be made a lot better.\n/// \n/// **Parameters:**\n/// \n/// - `output_format: crate::types::FileExportFormat`: The format the output file should be converted to. (required)\n/// - `prompt: &'astr`: The prompt for the model. (required)\nasync fn example_ai_create_text_to_3d() -> anyhow::Result<()> {\n let client = kittycad::Client::new_from_env();\n let result: kittycad::types::Mesh = client\n .ai()\n .create_text_to_3d(kittycad::types::FileExportFormat::Stl, \"some-string\")\n .await?;\n println!(\"{:?}\", result);\n Ok(())\n}\n",
"libDocsLink": "https://docs.rs/kittycad/latest/kittycad/ai/struct.Ai.html#method.create_text_to_3d"
"example": "/// Generate a CAD model from text.\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/// This is an alpha endpoint. It will change in the future. The current output is honestly pretty bad. So if you find this endpoint, you get what you pay for, which currently is nothing. But in the future will be made a lot better.\n/// \n/// **Parameters:**\n/// \n/// - `output_format: crate::types::FileExportFormat`: The format the output file should be converted to. (required)\nasync fn example_ai_create_text_to_cad() -> anyhow::Result<()> {\n let client = kittycad::Client::new_from_env();\n let result: kittycad::types::TextToCad = client\n .ai()\n .create_text_to_cad(\n kittycad::types::FileExportFormat::Stl,\n &kittycad::types::TextToCadCreateBody {\n prompt: \"some-string\".to_string(),\n },\n )\n .await?;\n println!(\"{:?}\", result);\n Ok(())\n}\n",
"libDocsLink": "https://docs.rs/kittycad/latest/kittycad/ai/struct.Ai.html#method.create_text_to_cad"
}
},
{
Expand Down Expand Up @@ -543,6 +535,22 @@
"libDocsLink": "https://docs.rs/kittycad/latest/kittycad/users/struct.Users.html#method.get_session_for"
}
},
{
"op": "add",
"path": "/paths/~1user~1text-to-cad/get/x-rust",
"value": {
"example": "/// List text-to-CAD models you've generated.\n/// \n/// This endpoint requires authentication by any KittyCAD user. It returns the text-to-CAD models for the authenticated user.\n/// The 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/// - `page_token: Option<String>`: Token returned by previous call to retrieve the subsequent page\n/// - `sort_by: Option<crate::types::CreatedAtSortMode>`\nasync fn example_ai_list_text_to_cad_models_for_user() -> anyhow::Result<()> {\n let client = kittycad::Client::new_from_env();\n let result: kittycad::types::TextToCadResultsPage = client\n .ai()\n .list_text_to_cad_models_for_user(\n Some(4 as u32),\n Some(\"some-string\".to_string()),\n Some(kittycad::types::CreatedAtSortMode::CreatedAtDescending),\n )\n .await?;\n println!(\"{:?}\", result);\n Ok(())\n}\n\n\n/// - OR -\n\n/// Get a stream of results.\n///\n/// This allows you to paginate through all the items.\nuse futures_util::TryStreamExt;\nasync fn example_ai_list_text_to_cad_models_for_user_stream() -> anyhow::Result<()> {\n let client = kittycad::Client::new_from_env();\n let mut ai = client.ai();\n let mut stream = ai.list_text_to_cad_models_for_user_stream(\n Some(4 as u32),\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",
"libDocsLink": "https://docs.rs/kittycad/latest/kittycad/ai/struct.Ai.html#method.list_text_to_cad_models_for_user"
}
},
{
"op": "add",
"path": "/paths/~1user~1text-to-cad~1{id}/post/x-rust",
"value": {
"example": "/// Give feedback to a specific text-to-CAD response.\n/// \n/// This endpoint requires authentication by any KittyCAD user. The user must be the owner of the text-to-CAD model, in order to give feedback.\n/// \n/// **Parameters:**\n/// \n/// - `feedback: crate::types::AiFeedback`: The feedback. (required)\n/// - `id: uuid::Uuid`: The id of the model to give feedback to. (required)\nuse std::str::FromStr;\nasync fn example_ai_create_text_to_cad_model_feedback() -> anyhow::Result<()> {\n let client = kittycad::Client::new_from_env();\n client\n .ai()\n .create_text_to_cad_model_feedback(\n kittycad::types::AiFeedback::ThumbsDown,\n uuid::Uuid::from_str(\"d9797f8d-9ad6-4e08-90d7-2ec17e13471c\")?,\n )\n .await?;\n Ok(())\n}\n",
"libDocsLink": "https://docs.rs/kittycad/latest/kittycad/ai/struct.Ai.html#method.create_text_to_cad_model_feedback"
}
},
{
"op": "add",
"path": "/paths/~1users/get/x-rust",
Expand Down
147 changes: 126 additions & 21 deletions kittycad/src/ai.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,24 @@ impl Ai {
Self { client }
}

#[doc = "Generate a 3D model from an image.\n\nThis is an alpha endpoint. It will change in the future. The current output is honestly pretty bad. So if you find this endpoint, you get what you pay for, which currently is nothing. But in the future will be made a lot better.\n\n**Parameters:**\n\n- `input_format: crate::types::ImageType`: The format of the image being converted. (required)\n- `output_format: crate::types::FileExportFormat`: The format the output file should be converted to. (required)\n\n```rust,no_run\nasync fn example_ai_create_image_to_3d() -> anyhow::Result<()> {\n let client = kittycad::Client::new_from_env();\n let result: kittycad::types::Mesh = client\n .ai()\n .create_image_to_3d(\n kittycad::types::ImageType::Jpg,\n kittycad::types::FileExportFormat::Stl,\n &bytes::Bytes::from(\"some-string\"),\n )\n .await?;\n println!(\"{:?}\", result);\n Ok(())\n}\n```"]
#[doc = "Generate a CAD model from text.\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.\nThis is an alpha endpoint. It will change in the future. The current output is honestly pretty bad. So if you find this endpoint, you get what you pay for, which currently is nothing. But in the future will be made a lot better.\n\n**Parameters:**\n\n- `output_format: crate::types::FileExportFormat`: The format the output file should be converted to. (required)\n\n```rust,no_run\nasync fn example_ai_create_text_to_cad() -> anyhow::Result<()> {\n let client = kittycad::Client::new_from_env();\n let result: kittycad::types::TextToCad = client\n .ai()\n .create_text_to_cad(\n kittycad::types::FileExportFormat::Stl,\n &kittycad::types::TextToCadCreateBody {\n prompt: \"some-string\".to_string(),\n },\n )\n .await?;\n println!(\"{:?}\", result);\n Ok(())\n}\n```"]
#[tracing::instrument]
pub async fn create_image_to_3d<'a>(
pub async fn create_text_to_cad<'a>(
&'a self,
input_format: crate::types::ImageType,
output_format: crate::types::FileExportFormat,
body: &bytes::Bytes,
) -> Result<crate::types::Mesh, crate::types::error::Error> {
body: &crate::types::TextToCadCreateBody,
) -> Result<crate::types::TextToCad, crate::types::error::Error> {
let mut req = self.client.client.request(
http::Method::POST,
format!(
"{}/{}",
self.client.base_url,
"ai/image-to-3d/{input_format}/{output_format}"
.replace("{input_format}", &format!("{}", input_format))
"ai/text-to-cad/{output_format}"
.replace("{output_format}", &format!("{}", output_format))
),
);
req = req.bearer_auth(&self.client.token);
req = req.body(body.clone());
req = req.json(body);
let resp = req.send().await?;
let status = resp.status();
if status.is_success() {
Expand All @@ -47,24 +45,32 @@ impl Ai {
}
}

#[doc = "Generate a 3D model from text.\n\nThis is an alpha endpoint. It will change in the future. The current output is honestly pretty bad. So if you find this endpoint, you get what you pay for, which currently is nothing. But in the future will be made a lot better.\n\n**Parameters:**\n\n- `output_format: crate::types::FileExportFormat`: The format the output file should be converted to. (required)\n- `prompt: &'astr`: The prompt for the model. (required)\n\n```rust,no_run\nasync fn example_ai_create_text_to_3d() -> anyhow::Result<()> {\n let client = kittycad::Client::new_from_env();\n let result: kittycad::types::Mesh = client\n .ai()\n .create_text_to_3d(kittycad::types::FileExportFormat::Stl, \"some-string\")\n .await?;\n println!(\"{:?}\", result);\n Ok(())\n}\n```"]
#[doc = "List text-to-CAD models you've generated.\n\nThis endpoint requires authentication by any KittyCAD user. It returns the text-to-CAD models for the authenticated user.\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- `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_ai_list_text_to_cad_models_for_user_stream() -> anyhow::Result<()> {\n let client = kittycad::Client::new_from_env();\n let mut ai = client.ai();\n let mut stream = ai.list_text_to_cad_models_for_user_stream(\n Some(4 as u32),\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```"]
#[tracing::instrument]
pub async fn create_text_to_3d<'a>(
pub async fn list_text_to_cad_models_for_user<'a>(
&'a self,
output_format: crate::types::FileExportFormat,
prompt: &'a str,
) -> Result<crate::types::Mesh, crate::types::error::Error> {
limit: Option<u32>,
page_token: Option<String>,
sort_by: Option<crate::types::CreatedAtSortMode>,
) -> Result<crate::types::TextToCadResultsPage, crate::types::error::Error> {
let mut req = self.client.client.request(
http::Method::POST,
format!(
"{}/{}",
self.client.base_url,
"ai/text-to-3d/{output_format}"
.replace("{output_format}", &format!("{}", output_format))
),
http::Method::GET,
format!("{}/{}", self.client.base_url, "user/text-to-cad"),
);
req = req.bearer_auth(&self.client.token);
let query_params = vec![("prompt", prompt.to_string())];
let mut query_params = vec![];
if let Some(p) = limit {
query_params.push(("limit", format!("{}", p)));
}

if let Some(p) = page_token {
query_params.push(("page_token", p));
}

if let Some(p) = sort_by {
query_params.push(("sort_by", format!("{}", p)));
}

req = req.query(&query_params);
let resp = req.send().await?;
let status = resp.status();
Expand All @@ -80,4 +86,103 @@ impl Ai {
Err(crate::types::error::Error::UnexpectedResponse(resp))
}
}

#[doc = "List text-to-CAD models you've generated.\n\nThis endpoint requires authentication by any KittyCAD user. It returns the text-to-CAD models for the authenticated user.\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- `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_ai_list_text_to_cad_models_for_user_stream() -> anyhow::Result<()> {\n let client = kittycad::Client::new_from_env();\n let mut ai = client.ai();\n let mut stream = ai.list_text_to_cad_models_for_user_stream(\n Some(4 as u32),\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```"]
#[tracing::instrument]
#[cfg(not(feature = "js"))]
pub fn list_text_to_cad_models_for_user_stream<'a>(
&'a self,
limit: Option<u32>,
sort_by: Option<crate::types::CreatedAtSortMode>,
) -> impl futures::Stream<Item = Result<crate::types::TextToCad, crate::types::error::Error>>
+ Unpin
+ '_ {
use futures::{StreamExt, TryFutureExt, TryStreamExt};

use crate::types::paginate::Pagination;
self.list_text_to_cad_models_for_user(limit, None, sort_by)
.map_ok(move |result| {
let items = futures::stream::iter(result.items().into_iter().map(Ok));
let next_pages =
futures::stream::try_unfold(result, move |new_result| async move {
if new_result.has_more_pages() {
async {
let mut req = self.client.client.request(
http::Method::GET,
format!("{}/{}", self.client.base_url, "user/text-to-cad"),
);
req = req.bearer_auth(&self.client.token);
let mut request = req.build()?;
request = new_result.next_page(request)?;
let resp = self.client.client.execute(request).await?;
let status = resp.status();
if status.is_success() {
let text = resp.text().await.unwrap_or_default();
serde_json::from_str(&text).map_err(|err| {
crate::types::error::Error::from_serde_error(
format_serde_error::SerdeError::new(
text.to_string(),
err,
),
status,
)
})
} else {
Err(crate::types::error::Error::UnexpectedResponse(resp))
}
}
.map_ok(|result: crate::types::TextToCadResultsPage| {
Some((
futures::stream::iter(result.items().into_iter().map(Ok)),
result,
))
})
.await
} else {
Ok(None)
}
})
.try_flatten();
items.chain(next_pages)
})
.try_flatten_stream()
.boxed()
}

#[doc = "Give feedback to a specific text-to-CAD response.\n\nThis endpoint requires \
authentication by any KittyCAD user. The user must be the owner of the text-to-CAD \
model, in order to give feedback.\n\n**Parameters:**\n\n- `feedback: \
crate::types::AiFeedback`: The feedback. (required)\n- `id: uuid::Uuid`: The id of \
the model to give feedback to. (required)\n\n```rust,no_run\nuse \
std::str::FromStr;\nasync fn example_ai_create_text_to_cad_model_feedback() -> \
anyhow::Result<()> {\n let client = kittycad::Client::new_from_env();\n \
client\n .ai()\n .create_text_to_cad_model_feedback(\n \
kittycad::types::AiFeedback::ThumbsDown,\n \
uuid::Uuid::from_str(\"d9797f8d-9ad6-4e08-90d7-2ec17e13471c\")?,\n )\n \
.await?;\n Ok(())\n}\n```"]
#[tracing::instrument]
pub async fn create_text_to_cad_model_feedback<'a>(
&'a self,
feedback: crate::types::AiFeedback,
id: uuid::Uuid,
) -> Result<(), crate::types::error::Error> {
let mut req = self.client.client.request(
http::Method::POST,
format!(
"{}/{}",
self.client.base_url,
"user/text-to-cad/{id}".replace("{id}", &format!("{}", id))
),
);
req = req.bearer_auth(&self.client.token);
let query_params = vec![("feedback", format!("{}", feedback))];
req = req.query(&query_params);
let resp = req.send().await?;
let status = resp.status();
if status.is_success() {
Ok(())
} else {
Err(crate::types::error::Error::UnexpectedResponse(resp))
}
}
}
Loading

0 comments on commit 4d1edc8

Please sign in to comment.