Skip to content

Commit 6572a92

Browse files
Update api spec (#427)
* YOYO NEW API SPEC! * I have generated the latest API! --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 2bd7360 commit 6572a92

13 files changed

+691
-433
lines changed

kittycad.py.patch.json

Lines changed: 421 additions & 413 deletions
Large diffs are not rendered by default.
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
from typing import Any, Dict, Optional, Union
2+
3+
import httpx
4+
5+
from ...client import Client
6+
from ...models.error import Error
7+
from ...models.kcl_model import KclModel
8+
from ...types import Response
9+
10+
11+
def _get_kwargs(
12+
*,
13+
client: Client,
14+
) -> Dict[str, Any]:
15+
url = "{}/ml/convert/proprietary-to-kcl".format(
16+
client.base_url,
17+
) # noqa: E501
18+
19+
headers: Dict[str, Any] = client.get_headers()
20+
cookies: Dict[str, Any] = client.get_cookies()
21+
22+
return {
23+
"url": url,
24+
"headers": headers,
25+
"cookies": cookies,
26+
"timeout": client.get_timeout(),
27+
}
28+
29+
30+
def _parse_response(*, response: httpx.Response) -> Optional[Union[KclModel, Error]]:
31+
if response.status_code == 201:
32+
response_201 = KclModel(**response.json())
33+
return response_201
34+
if response.status_code == 400:
35+
response_4XX = Error(**response.json())
36+
return response_4XX
37+
if response.status_code == 500:
38+
response_5XX = Error(**response.json())
39+
return response_5XX
40+
return Error(**response.json())
41+
42+
43+
def _build_response(
44+
*, response: httpx.Response
45+
) -> Response[Optional[Union[KclModel, Error]]]:
46+
return Response(
47+
status_code=response.status_code,
48+
content=response.content,
49+
headers=response.headers,
50+
parsed=_parse_response(response=response),
51+
)
52+
53+
54+
def sync_detailed(
55+
*,
56+
client: Client,
57+
) -> Response[Optional[Union[KclModel, Error]]]:
58+
kwargs = _get_kwargs(
59+
client=client,
60+
)
61+
62+
response = httpx.post(
63+
verify=client.verify_ssl,
64+
**kwargs,
65+
)
66+
67+
return _build_response(response=response)
68+
69+
70+
def sync(
71+
*,
72+
client: Client,
73+
) -> Optional[Union[KclModel, Error]]:
74+
"""This endpoint is used to convert a proprietary CAD format to KCL. The file passed MUST have feature tree data.
75+
76+
A STEP file does not have feature tree data, so it will not work. A sldprt file does have feature tree data, so it will work.""" # noqa: E501
77+
78+
return sync_detailed(
79+
client=client,
80+
).parsed
81+
82+
83+
async def asyncio_detailed(
84+
*,
85+
client: Client,
86+
) -> Response[Optional[Union[KclModel, Error]]]:
87+
kwargs = _get_kwargs(
88+
client=client,
89+
)
90+
91+
async with httpx.AsyncClient(verify=client.verify_ssl) as _client:
92+
response = await _client.post(**kwargs)
93+
94+
return _build_response(response=response)
95+
96+
97+
async def asyncio(
98+
*,
99+
client: Client,
100+
) -> Optional[Union[KclModel, Error]]:
101+
"""This endpoint is used to convert a proprietary CAD format to KCL. The file passed MUST have feature tree data.
102+
103+
A STEP file does not have feature tree data, so it will not work. A sldprt file does have feature tree data, so it will work.""" # noqa: E501
104+
105+
return (
106+
await asyncio_detailed(
107+
client=client,
108+
)
109+
).parsed

kittycad/api/modeling/modeling_commands_ws.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,18 @@ def _get_kwargs(
2727
webrtc: bool,
2828
*,
2929
client: Client,
30+
api_call_id: Optional[str] = None,
3031
pool: Optional[str] = None,
3132
replay: Optional[str] = None,
3233
) -> Dict[str, Any]:
3334
url = "{}/ws/modeling/commands".format(client.base_url) # noqa: E501
3435

36+
if api_call_id is not None:
37+
if "?" in url:
38+
url = url + "&api_call_id=" + str(api_call_id)
39+
else:
40+
url = url + "?api_call_id=" + str(api_call_id)
41+
3542
if fps is not None:
3643
if "?" in url:
3744
url = url + "&fps=" + str(fps)
@@ -107,12 +114,14 @@ def sync(
107114
webrtc: bool,
108115
*,
109116
client: Client,
117+
api_call_id: Optional[str] = None,
110118
pool: Optional[str] = None,
111119
replay: Optional[str] = None,
112120
) -> ClientConnectionSync:
113121
"""Pass those commands to the engine via websocket, and pass responses back to the client. Basically, this is a websocket proxy between the frontend/client and the engine.""" # noqa: E501
114122

115123
kwargs = _get_kwargs(
124+
api_call_id=api_call_id,
116125
fps=fps,
117126
pool=pool,
118127
post_effect=post_effect,
@@ -143,12 +152,14 @@ async def asyncio(
143152
webrtc: bool,
144153
*,
145154
client: Client,
155+
api_call_id: Optional[str] = None,
146156
pool: Optional[str] = None,
147157
replay: Optional[str] = None,
148158
) -> ClientConnectionAsync:
149159
"""Pass those commands to the engine via websocket, and pass responses back to the client. Basically, this is a websocket proxy between the frontend/client and the engine.""" # noqa: E501
150160

151161
kwargs = _get_kwargs(
162+
api_call_id=api_call_id,
152163
fps=fps,
153164
pool=pool,
154165
post_effect=post_effect,
@@ -184,6 +195,7 @@ def __init__(
184195
video_res_width: int,
185196
webrtc: bool,
186197
client: Client,
198+
api_call_id: Optional[str] = None,
187199
pool: Optional[str] = None,
188200
replay: Optional[str] = None,
189201
):
@@ -196,6 +208,7 @@ def __init__(
196208
video_res_width,
197209
webrtc,
198210
client=client,
211+
api_call_id=api_call_id,
199212
pool=pool,
200213
replay=replay,
201214
)

kittycad/examples_test.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
)
5757
from kittycad.api.ml import (
5858
create_kcl_code_completions,
59+
create_proprietary_to_kcl,
5960
create_text_to_cad,
6061
create_text_to_cad_iteration,
6162
create_text_to_cad_model_feedback,
@@ -188,6 +189,7 @@
188189
Invoice,
189190
IpAddrInfo,
190191
KclCodeCompletionResponse,
192+
KclModel,
191193
Metadata,
192194
MlPrompt,
193195
MlPromptResultsPage,
@@ -1899,6 +1901,49 @@ async def test_get_ml_prompt_async():
18991901
)
19001902

19011903

1904+
@pytest.mark.skip
1905+
def test_create_proprietary_to_kcl():
1906+
# Create our client.
1907+
client = ClientFromEnv()
1908+
1909+
result: Optional[Union[KclModel, Error]] = create_proprietary_to_kcl.sync(
1910+
client=client,
1911+
)
1912+
1913+
if isinstance(result, Error) or result is None:
1914+
print(result)
1915+
raise Exception("Error in response")
1916+
1917+
body: KclModel = result
1918+
print(body)
1919+
1920+
# OR if you need more info (e.g. status_code)
1921+
response: Response[Optional[Union[KclModel, Error]]] = (
1922+
create_proprietary_to_kcl.sync_detailed(
1923+
client=client,
1924+
)
1925+
)
1926+
1927+
1928+
# OR run async
1929+
@pytest.mark.asyncio
1930+
@pytest.mark.skip
1931+
async def test_create_proprietary_to_kcl_async():
1932+
# Create our client.
1933+
client = ClientFromEnv()
1934+
1935+
result: Optional[Union[KclModel, Error]] = await create_proprietary_to_kcl.asyncio(
1936+
client=client,
1937+
)
1938+
1939+
# OR run async with more info
1940+
response: Response[
1941+
Optional[Union[KclModel, Error]]
1942+
] = await create_proprietary_to_kcl.asyncio_detailed(
1943+
client=client,
1944+
)
1945+
1946+
19021947
@pytest.mark.skip
19031948
def test_create_kcl_code_completions():
19041949
# Create our client.
@@ -7493,6 +7538,7 @@ def test_modeling_commands_ws():
74937538
video_res_height=10,
74947539
video_res_width=10,
74957540
webrtc=False,
7541+
api_call_id=None, # Optional[str]
74967542
pool=None, # Optional[str]
74977543
replay=None, # Optional[str]
74987544
) as websocket:
@@ -7530,6 +7576,7 @@ async def test_modeling_commands_ws_async():
75307576
video_res_height=10,
75317577
video_res_width=10,
75327578
webrtc=False,
7579+
api_call_id=None, # Optional[str]
75337580
pool=None, # Optional[str]
75347581
replay=None, # Optional[str]
75357582
)

kittycad/models/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@
176176
from .kcl_code_completion_params import KclCodeCompletionParams
177177
from .kcl_code_completion_request import KclCodeCompletionRequest
178178
from .kcl_code_completion_response import KclCodeCompletionResponse
179+
from .kcl_model import KclModel
179180
from .leaf_node import LeafNode
180181
from .length_unit import LengthUnit
181182
from .loft import Loft
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
from typing import List
1+
from typing import List, Optional
22

33
from pydantic import BaseModel, ConfigDict
44

55

66
class BooleanIntersection(BaseModel):
77
"""The response from the 'BooleanIntersection'."""
88

9-
extra_solid_ids: List[str]
9+
extra_solid_ids: Optional[List[str]] = None
1010

1111
model_config = ConfigDict(protected_namespaces=())

kittycad/models/boolean_subtract.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
from typing import List
1+
from typing import List, Optional
22

33
from pydantic import BaseModel, ConfigDict
44

55

66
class BooleanSubtract(BaseModel):
77
"""The response from the 'BooleanSubtract'."""
88

9-
extra_solid_ids: List[str]
9+
extra_solid_ids: Optional[List[str]] = None
1010

1111
model_config = ConfigDict(protected_namespaces=())

kittycad/models/boolean_union.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
from typing import List
1+
from typing import List, Optional
22

33
from pydantic import BaseModel, ConfigDict
44

55

66
class BooleanUnion(BaseModel):
77
"""The response from the 'BooleanUnion'."""
88

9-
extra_solid_ids: List[str]
9+
extra_solid_ids: Optional[List[str]] = None
1010

1111
model_config = ConfigDict(protected_namespaces=())

kittycad/models/component_transform.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88

99
class ComponentTransform(BaseModel):
10-
"""Container that holds a translate, rotate and scale."""
10+
"""Container that holds a translate, rotate and scale. Defaults to no change, everything stays the same (i.e. the identity function)."""
1111

1212
rotate_angle_axis: Optional[TransformByForPoint4d] = None
1313

kittycad/models/kcl_model.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from pydantic import BaseModel, ConfigDict
2+
3+
4+
class KclModel(BaseModel):
5+
"""The response containing the KCL code."""
6+
7+
code: str
8+
9+
model_config = ConfigDict(protected_namespaces=())

0 commit comments

Comments
 (0)