Skip to content

Commit

Permalink
Update api spec (#297)
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
1 parent e37e238 commit 3ae50a4
Show file tree
Hide file tree
Showing 9 changed files with 603 additions and 8 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.

12 changes: 10 additions & 2 deletions kittycad.rs.patch.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"path": "/info/x-rust",
"value": {
"client": "// Authenticate via an API token.\nlet client = kittycad::Client::new(\"$TOKEN\");\n\n// - OR -\n\n// Authenticate with your token and host parsed from the environment variables:\n// `KITTYCAD_API_TOKEN`.\nlet client = kittycad::Client::new_from_env();",
"install": "[dependencies]\nkittycad = \"0.2.51\""
"install": "[dependencies]\nkittycad = \"0.2.52\""
}
},
{
Expand Down Expand Up @@ -47,11 +47,19 @@
"libDocsLink": "https://docs.rs/kittycad/latest/kittycad/ai/struct.Ai.html#method.get_prompt"
}
},
{
"op": "add",
"path": "/paths/~1ai~1kcl~1completions/post/x-rust",
"value": {
"example": "/// Generate code completions for KCL.\nasync fn example_ai_create_kcl_code_completions() -> anyhow::Result<()> {\n let client = kittycad::Client::new_from_env();\n let result: kittycad::types::KclCodeCompletionResponse = client\n .ai()\n .create_kcl_code_completions(&kittycad::types::KclCodeCompletionRequest {\n extra: kittycad::types::KclCodeCompletionParams {\n language: \"some-string\".to_string(),\n next_indent: 4 as i8,\n prompt_tokens: 4 as i32,\n suffix_tokens: 4 as i32,\n trim_by_indentation: false,\n },\n max_tokens: 4 as i32,\n n: 4 as i16,\n nwo: \"some-string\".to_string(),\n prompt: \"some-string\".to_string(),\n stop: vec![\"some-string\".to_string()],\n stream: false,\n suffix: \"some-string\".to_string(),\n temperature: 3.14 as f64,\n top_p: 3.14 as f64,\n })\n .await?;\n println!(\"{:?}\", result);\n Ok(())\n}\n",
"libDocsLink": "https://docs.rs/kittycad/latest/kittycad/ai/struct.Ai.html#method.create_kcl_code_completions"
}
},
{
"op": "add",
"path": "/paths/~1ai~1text-to-cad~1{output_format}/post/x-rust",
"value": {
"example": "/// Generate a CAD model from text.\n/// \n/// Because our source of truth for the resulting model is a STEP file, you will always have STEP file contents when you list your generated models. Any other formats you request here will also be returned when you list your generated models.\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/// One thing to note, if you hit the cache, this endpoint will return right away. So you only have to wait if the status is not `Completed` or `Failed`.\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",
"example": "/// Generate a CAD model from text.\n/// \n/// Because our source of truth for the resulting model is a STEP file, you will always have STEP file contents when you list your generated models. Any other formats you request here will also be returned when you list your generated models.\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/// One thing to note, if you hit the cache, this endpoint will return right away. So you only have to wait if the status is not `Completed` or `Failed`.\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
2 changes: 1 addition & 1 deletion kittycad/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "kittycad"
description = "A fully generated & opinionated API client for the KittyCAD API."
version = "0.2.51"
version = "0.2.52"
documentation = "https://docs.rs/kittycad"
readme = "README.md"
repository = "https://github.com/KittyCAD/kittycad.rs/tree/main/kittycad"
Expand Down
2 changes: 1 addition & 1 deletion kittycad/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ To install the library, add the following to your `Cargo.toml` file.

```toml
[dependencies]
kittycad = "0.2.51"
kittycad = "0.2.52"
```

## Basic example
Expand Down
33 changes: 32 additions & 1 deletion kittycad/src/ai.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,38 @@ impl Ai {
}
}

#[doc = "Generate a CAD model from text.\n\nBecause our source of truth for the resulting model is a STEP file, you will always have STEP file contents when you list your generated models. Any other formats you request here will also be returned when you list your generated models.\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.\nOne thing to note, if you hit the cache, this endpoint will return right away. So you only have to wait if the status is not `Completed` or `Failed`.\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```"]
#[doc = "Generate code completions for KCL.\n\n```rust,no_run\nasync fn example_ai_create_kcl_code_completions() -> anyhow::Result<()> {\n let client = kittycad::Client::new_from_env();\n let result: kittycad::types::KclCodeCompletionResponse = client\n .ai()\n .create_kcl_code_completions(&kittycad::types::KclCodeCompletionRequest {\n extra: kittycad::types::KclCodeCompletionParams {\n language: \"some-string\".to_string(),\n next_indent: 4 as i8,\n prompt_tokens: 4 as i32,\n suffix_tokens: 4 as i32,\n trim_by_indentation: false,\n },\n max_tokens: 4 as i32,\n n: 4 as i16,\n nwo: \"some-string\".to_string(),\n prompt: \"some-string\".to_string(),\n stop: vec![\"some-string\".to_string()],\n stream: false,\n suffix: \"some-string\".to_string(),\n temperature: 3.14 as f64,\n top_p: 3.14 as f64,\n })\n .await?;\n println!(\"{:?}\", result);\n Ok(())\n}\n```"]
#[tracing::instrument]
pub async fn create_kcl_code_completions<'a>(
&'a self,
body: &crate::types::KclCodeCompletionRequest,
) -> Result<crate::types::KclCodeCompletionResponse, crate::types::error::Error> {
let mut req = self.client.client.request(
http::Method::POST,
format!("{}/{}", self.client.base_url, "ai/kcl/completions"),
);
req = req.bearer_auth(&self.client.token);
req = req.json(body);
let resp = req.send().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 {
let text = resp.text().await.unwrap_or_default();
return Err(crate::types::error::Error::Server {
body: text.to_string(),
status,
});
}
}

#[doc = "Generate a CAD model from text.\n\nBecause our source of truth for the resulting model is a STEP file, you will always have STEP file contents when you list your generated models. Any other formats you request here will also be returned when you list your generated models.\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.\nOne thing to note, if you hit the cache, this endpoint will return right away. So you only have to wait if the status is not `Completed` or `Failed`.\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_text_to_cad<'a>(
&'a self,
Expand Down
2 changes: 1 addition & 1 deletion kittycad/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
//!
//! ```toml
//! [dependencies]
//! kittycad = "0.2.51"
//! kittycad = "0.2.52"
//! ```
//!
//! ## Basic example
Expand Down
157 changes: 157 additions & 0 deletions kittycad/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6952,6 +6952,163 @@ impl tabled::Tabled for JetstreamStats {
}
}

#[doc = "Extra params for the completions."]
#[derive(
serde :: Serialize, serde :: Deserialize, PartialEq, Debug, Clone, schemars :: JsonSchema,
)]
pub struct KclCodeCompletionParams {
#[doc = "The language of the code."]
pub language: String,
#[doc = "The next indent of the code."]
pub next_indent: i8,
#[doc = "The prompt tokens for the completions."]
pub prompt_tokens: i32,
#[doc = "The suffix tokens for the completions."]
pub suffix_tokens: i32,
#[doc = "If we should trim by indentation."]
pub trim_by_indentation: bool,
}

impl std::fmt::Display for KclCodeCompletionParams {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
write!(
f,
"{}",
serde_json::to_string_pretty(self).map_err(|_| std::fmt::Error)?
)
}
}

#[cfg(feature = "tabled")]
impl tabled::Tabled for KclCodeCompletionParams {
const LENGTH: usize = 5;
fn fields(&self) -> Vec<std::borrow::Cow<'static, str>> {
vec![
self.language.clone().into(),
format!("{:?}", self.next_indent).into(),
format!("{:?}", self.prompt_tokens).into(),
format!("{:?}", self.suffix_tokens).into(),
format!("{:?}", self.trim_by_indentation).into(),
]
}

fn headers() -> Vec<std::borrow::Cow<'static, str>> {
vec![
"language".into(),
"next_indent".into(),
"prompt_tokens".into(),
"suffix_tokens".into(),
"trim_by_indentation".into(),
]
}
}

#[doc = "A request to generate KCL code completions."]
#[derive(
serde :: Serialize, serde :: Deserialize, PartialEq, Debug, Clone, schemars :: JsonSchema,
)]
pub struct KclCodeCompletionRequest {
#[doc = "Extra parameters for the completions."]
pub extra: KclCodeCompletionParams,
#[doc = "The maximum number of tokens that can be generated for the completions. The total \
length of input tokens and generated tokens is limited by the model’s context length."]
pub max_tokens: i32,
#[doc = "How many completion choices to generate for each input message."]
pub n: i16,
#[doc = "New workflows. This does not do anything yet. But we wanted the same API as GitHub \
Copilot."]
pub nwo: String,
#[doc = "The prompt for the model."]
pub prompt: String,
#[doc = "Up to 4 sequences where the API will stop generating further tokens."]
pub stop: Vec<String>,
#[doc = "If set, partial message deltas will be sent, like in ChatGPT or OpenAPI. Tokens will \
be sent as data-only server-sent events as they become available, with the stream \
terminated by a data: [DONE] message."]
pub stream: bool,
#[doc = "The suffix for the model."]
pub suffix: String,
#[doc = "The temperature for the model."]
pub temperature: f64,
#[doc = "The top p for the model."]
pub top_p: f64,
}

impl std::fmt::Display for KclCodeCompletionRequest {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
write!(
f,
"{}",
serde_json::to_string_pretty(self).map_err(|_| std::fmt::Error)?
)
}
}

#[cfg(feature = "tabled")]
impl tabled::Tabled for KclCodeCompletionRequest {
const LENGTH: usize = 10;
fn fields(&self) -> Vec<std::borrow::Cow<'static, str>> {
vec![
format!("{:?}", self.extra).into(),
format!("{:?}", self.max_tokens).into(),
format!("{:?}", self.n).into(),
self.nwo.clone().into(),
self.prompt.clone().into(),
format!("{:?}", self.stop).into(),
format!("{:?}", self.stream).into(),
self.suffix.clone().into(),
format!("{:?}", self.temperature).into(),
format!("{:?}", self.top_p).into(),
]
}

fn headers() -> Vec<std::borrow::Cow<'static, str>> {
vec![
"extra".into(),
"max_tokens".into(),
"n".into(),
"nwo".into(),
"prompt".into(),
"stop".into(),
"stream".into(),
"suffix".into(),
"temperature".into(),
"top_p".into(),
]
}
}

#[doc = "A response with KCL code completions."]
#[derive(
serde :: Serialize, serde :: Deserialize, PartialEq, Debug, Clone, schemars :: JsonSchema,
)]
pub struct KclCodeCompletionResponse {
#[doc = "The completions."]
pub completions: Vec<String>,
}

impl std::fmt::Display for KclCodeCompletionResponse {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
write!(
f,
"{}",
serde_json::to_string_pretty(self).map_err(|_| std::fmt::Error)?
)
}
}

#[cfg(feature = "tabled")]
impl tabled::Tabled for KclCodeCompletionResponse {
const LENGTH: usize = 1;
fn fields(&self) -> Vec<std::borrow::Cow<'static, str>> {
vec![format!("{:?}", self.completions).into()]
}

fn headers() -> Vec<std::borrow::Cow<'static, str>> {
vec!["completions".into()]
}
}

#[doc = "Leaf node information."]
#[derive(
serde :: Serialize, serde :: Deserialize, PartialEq, Debug, Clone, schemars :: JsonSchema,
Expand Down
Loading

0 comments on commit 3ae50a4

Please sign in to comment.