Skip to content

Commit 437b435

Browse files
Include delete API for application and actual request timestamp (#34)
* Include delete and actual request timestamp * Include actual time response and delete application * Set actual request as not required * Update status type --------- Co-authored-by: Ramon Marques <ramon.marques@toptal.com>
1 parent 5a4cf51 commit 437b435

File tree

9 files changed

+194
-6
lines changed

9 files changed

+194
-6
lines changed

aimon/_base_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
import sys
34
import json
45
import time
56
import uuid
@@ -1982,7 +1983,6 @@ def get_python_version() -> str:
19821983

19831984
def get_architecture() -> Arch:
19841985
try:
1985-
python_bitness, _ = platform.architecture()
19861986
machine = platform.machine().lower()
19871987
except Exception:
19881988
return "unknown"
@@ -1998,7 +1998,7 @@ def get_architecture() -> Arch:
19981998
return "x64"
19991999

20002000
# TODO: untested
2001-
if python_bitness == "32bit":
2001+
if sys.maxsize <= 2**32:
20022002
return "x32"
20032003

20042004
if machine:

aimon/_models.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,8 @@ def is_basemodel(type_: type) -> bool:
380380

381381
def is_basemodel_type(type_: type) -> TypeGuard[type[BaseModel] | type[GenericModel]]:
382382
origin = get_origin(type_) or type_
383+
if not inspect.isclass(origin):
384+
return False
383385
return issubclass(origin, BaseModel) or issubclass(origin, GenericModel)
384386

385387

aimon/decorators/analyze.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,10 +191,13 @@ def _run_production_analysis(self, func, args, kwargs):
191191
"output": result_dict['generated_text'],
192192
"context_docs": _context,
193193
"user_query": result_dict["user_query"] if 'user_query' in result_dict else "No User Query Specified",
194-
"prompt": result_dict['prompt'] if 'prompt' in result_dict else "No Prompt Specified"
194+
"prompt": result_dict['prompt'] if 'prompt' in result_dict else "No Prompt Specified",
195195
}
196196
if 'instructions' in result_dict:
197197
aimon_payload['instructions'] = result_dict['instructions']
198+
if 'actual_request_timestamp' in result_dict:
199+
aimon_payload["actual_request_timestamp"] = result_dict['actual_request_timestamp']
200+
198201
aimon_payload['config'] = self.config
199202
aimon_response = self.client.analyze.create(body=[aimon_payload])
200203
return result + (aimon_response,)

aimon/resources/applications/applications.py

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

88
import httpx
99

10-
from ...types import application_create_params, application_retrieve_params
10+
from ...types import application_create_params, application_delete_params, application_retrieve_params
1111
from ..._types import NOT_GIVEN, Body, Query, Headers, NotGiven
1212
from ..._utils import (
1313
maybe_transform,
@@ -41,6 +41,7 @@
4141
from .production.production import ProductionResource, AsyncProductionResource
4242
from .evaluations.evaluations import EvaluationsResource, AsyncEvaluationsResource
4343
from ...types.application_create_response import ApplicationCreateResponse
44+
from ...types.application_delete_response import ApplicationDeleteResponse
4445
from ...types.application_retrieve_response import ApplicationRetrieveResponse
4546

4647
__all__ = ["ApplicationsResource", "AsyncApplicationsResource"]
@@ -166,6 +167,56 @@ def retrieve(
166167
cast_to=ApplicationRetrieveResponse,
167168
)
168169

170+
def delete(
171+
self,
172+
*,
173+
name: str,
174+
stage: str,
175+
version: str,
176+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
177+
# The extra values given here take precedence over values defined on the client or passed to this method.
178+
extra_headers: Headers | None = None,
179+
extra_query: Query | None = None,
180+
extra_body: Body | None = None,
181+
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
182+
) -> ApplicationDeleteResponse:
183+
"""
184+
Delete an application by name, stage, and version
185+
186+
Args:
187+
name: The name of the application to delete
188+
189+
stage: The stage of the application (e.g., production, evaluation)
190+
191+
version: The version of the application to delete
192+
193+
extra_headers: Send extra headers
194+
195+
extra_query: Add additional query parameters to the request
196+
197+
extra_body: Add additional JSON properties to the request
198+
199+
timeout: Override the client-level default timeout for this request, in seconds
200+
"""
201+
return self._delete(
202+
"/v1/application",
203+
options=make_request_options(
204+
extra_headers=extra_headers,
205+
extra_query=extra_query,
206+
extra_body=extra_body,
207+
timeout=timeout,
208+
query=maybe_transform(
209+
{
210+
"name": name,
211+
"stage": stage,
212+
"version": version,
213+
},
214+
application_delete_params.ApplicationDeleteParams,
215+
),
216+
),
217+
cast_to=ApplicationDeleteResponse,
218+
)
219+
169220

170221
class AsyncApplicationsResource(AsyncAPIResource):
171222
@cached_property
@@ -287,6 +338,56 @@ async def retrieve(
287338
cast_to=ApplicationRetrieveResponse,
288339
)
289340

341+
async def delete(
342+
self,
343+
*,
344+
name: str,
345+
stage: str,
346+
version: str,
347+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
348+
# The extra values given here take precedence over values defined on the client or passed to this method.
349+
extra_headers: Headers | None = None,
350+
extra_query: Query | None = None,
351+
extra_body: Body | None = None,
352+
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
353+
) -> ApplicationDeleteResponse:
354+
"""
355+
Delete an application by name, stage, and version
356+
357+
Args:
358+
name: The name of the application to delete
359+
360+
stage: The stage of the application (e.g., production, evaluation)
361+
362+
version: The version of the application to delete
363+
364+
extra_headers: Send extra headers
365+
366+
extra_query: Add additional query parameters to the request
367+
368+
extra_body: Add additional JSON properties to the request
369+
370+
timeout: Override the client-level default timeout for this request, in seconds
371+
"""
372+
return await self._delete(
373+
"/v1/application",
374+
options=make_request_options(
375+
extra_headers=extra_headers,
376+
extra_query=extra_query,
377+
extra_body=extra_body,
378+
timeout=timeout,
379+
query=await async_maybe_transform(
380+
{
381+
"name": name,
382+
"stage": stage,
383+
"version": version,
384+
},
385+
application_delete_params.ApplicationDeleteParams,
386+
),
387+
),
388+
cast_to=ApplicationDeleteResponse,
389+
)
390+
290391

291392
class ApplicationsResourceWithRawResponse:
292393
def __init__(self, applications: ApplicationsResource) -> None:
@@ -298,6 +399,9 @@ def __init__(self, applications: ApplicationsResource) -> None:
298399
self.retrieve = to_raw_response_wrapper(
299400
applications.retrieve,
300401
)
402+
self.delete = to_raw_response_wrapper(
403+
applications.delete,
404+
)
301405

302406
@cached_property
303407
def evaluations(self) -> EvaluationsResourceWithRawResponse:
@@ -318,6 +422,9 @@ def __init__(self, applications: AsyncApplicationsResource) -> None:
318422
self.retrieve = async_to_raw_response_wrapper(
319423
applications.retrieve,
320424
)
425+
self.delete = async_to_raw_response_wrapper(
426+
applications.delete,
427+
)
321428

322429
@cached_property
323430
def evaluations(self) -> AsyncEvaluationsResourceWithRawResponse:
@@ -338,6 +445,9 @@ def __init__(self, applications: ApplicationsResource) -> None:
338445
self.retrieve = to_streamed_response_wrapper(
339446
applications.retrieve,
340447
)
448+
self.delete = to_streamed_response_wrapper(
449+
applications.delete,
450+
)
341451

342452
@cached_property
343453
def evaluations(self) -> EvaluationsResourceWithStreamingResponse:
@@ -358,6 +468,9 @@ def __init__(self, applications: AsyncApplicationsResource) -> None:
358468
self.retrieve = async_to_streamed_response_wrapper(
359469
applications.retrieve,
360470
)
471+
self.delete = async_to_streamed_response_wrapper(
472+
applications.delete,
473+
)
361474

362475
@cached_property
363476
def evaluations(self) -> AsyncEvaluationsResourceWithStreamingResponse:

aimon/types/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@
1919
from .model_retrieve_response import ModelRetrieveResponse as ModelRetrieveResponse
2020
from .evaluation_create_params import EvaluationCreateParams as EvaluationCreateParams
2121
from .application_create_params import ApplicationCreateParams as ApplicationCreateParams
22+
from .application_delete_params import ApplicationDeleteParams as ApplicationDeleteParams
2223
from .inference_detect_response import InferenceDetectResponse as InferenceDetectResponse
2324
from .evaluation_create_response import EvaluationCreateResponse as EvaluationCreateResponse
2425
from .evaluation_retrieve_params import EvaluationRetrieveParams as EvaluationRetrieveParams
2526
from .application_create_response import ApplicationCreateResponse as ApplicationCreateResponse
27+
from .application_delete_response import ApplicationDeleteResponse as ApplicationDeleteResponse
2628
from .application_retrieve_params import ApplicationRetrieveParams as ApplicationRetrieveParams
2729
from .evaluation_retrieve_response import EvaluationRetrieveResponse as EvaluationRetrieveResponse
2830
from .application_retrieve_response import ApplicationRetrieveResponse as ApplicationRetrieveResponse

aimon/types/analyze_create_params.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22

33
from __future__ import annotations
44

5-
from typing import List, Iterable, Optional
6-
from typing_extensions import Required, TypedDict
5+
from typing import List, Union, Iterable, Optional
6+
from datetime import datetime
7+
from typing_extensions import Required, Annotated, TypedDict
8+
9+
from .._utils import PropertyInfo
710

811
__all__ = ["AnalyzeCreateParams", "Body"]
912

@@ -25,6 +28,9 @@ class Body(TypedDict, total=False):
2528

2629
version: Required[str]
2730

31+
actual_request_timestamp: Annotated[Union[str, datetime], PropertyInfo(format="iso8601")]
32+
"""The timestamp when the actual request was made"""
33+
2834
evaluation_id: Optional[str]
2935

3036
evaluation_run_id: Optional[str]

aimon/types/analyze_create_response.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@
99

1010
class AnalyzeCreateResponse(BaseModel):
1111
message: Optional[str] = None
12+
13+
status: int
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
from __future__ import annotations
4+
5+
from typing_extensions import Required, TypedDict
6+
7+
__all__ = ["ApplicationDeleteParams"]
8+
9+
10+
class ApplicationDeleteParams(TypedDict, total=False):
11+
name: Required[str]
12+
"""The name of the application to delete"""
13+
14+
stage: Required[str]
15+
"""The stage of the application (e.g., production, evaluation)"""
16+
17+
version: Required[str]
18+
"""The version of the application to delete"""
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
from typing import Optional
4+
from datetime import datetime
5+
6+
from pydantic import Field as FieldInfo
7+
8+
from .._models import BaseModel
9+
10+
__all__ = ["ApplicationDeleteResponse", "Application"]
11+
12+
13+
class Application(BaseModel):
14+
api_model_name: str = FieldInfo(alias="model_name")
15+
16+
name: str
17+
18+
type: str
19+
20+
id: Optional[str] = None
21+
22+
company_id: Optional[str] = None
23+
24+
context_source_id: Optional[str] = None
25+
26+
last_query_timestamp: Optional[datetime] = None
27+
28+
metadata: Optional[object] = None
29+
30+
api_model_id: Optional[str] = FieldInfo(alias="model_id", default=None)
31+
32+
stage: Optional[str] = None
33+
34+
user_id: Optional[str] = None
35+
36+
version: Optional[str] = None
37+
38+
39+
class ApplicationDeleteResponse(BaseModel):
40+
application: Optional[Application] = None
41+
42+
message: Optional[str] = None

0 commit comments

Comments
 (0)