|
| 1 | +from __future__ import annotations |
| 2 | + |
| 3 | +from typing import List |
| 4 | + |
| 5 | +from ai21.clients.common.beta.assistant.routes import BaseRoutes |
| 6 | +from ai21.clients.studio.resources.studio_resource import ( |
| 7 | + AsyncStudioResource, |
| 8 | + StudioResource, |
| 9 | +) |
| 10 | +from ai21.models.responses.route_response import RouteResponse, ListRouteResponse |
| 11 | +from ai21.types import NotGiven |
| 12 | + |
| 13 | + |
| 14 | +class AssistantRoutes(StudioResource, BaseRoutes): |
| 15 | + def create( |
| 16 | + self, |
| 17 | + *, |
| 18 | + assistant_id: str, |
| 19 | + plan_id: str, |
| 20 | + name: str, |
| 21 | + description: str, |
| 22 | + examples: List[str], |
| 23 | + **kwargs, |
| 24 | + ) -> RouteResponse: |
| 25 | + body = self._create_body( |
| 26 | + plan_id=plan_id, |
| 27 | + name=name, |
| 28 | + description=description, |
| 29 | + examples=examples, |
| 30 | + **kwargs, |
| 31 | + ) |
| 32 | + |
| 33 | + return self._post(path=f"/assistants/{assistant_id}/{self._module_name}", body=body, response_cls=RouteResponse) |
| 34 | + |
| 35 | + def list( |
| 36 | + self, |
| 37 | + *, |
| 38 | + assistant_id: str, |
| 39 | + name: str | NotGiven = NotGiven, |
| 40 | + ) -> ListRouteResponse: |
| 41 | + params = self._create_body(name=name) |
| 42 | + |
| 43 | + return self._get( |
| 44 | + path=f"/assistants/{assistant_id}/{self._module_name}", params=params, response_cls=ListRouteResponse |
| 45 | + ) |
| 46 | + |
| 47 | + def retrieve( |
| 48 | + self, |
| 49 | + *, |
| 50 | + assistant_id: str, |
| 51 | + route_id: str, |
| 52 | + ) -> RouteResponse: |
| 53 | + return self._get(path=f"/assistants/{assistant_id}/{self._module_name}/{route_id}", response_cls=RouteResponse) |
| 54 | + |
| 55 | + def modify( |
| 56 | + self, |
| 57 | + *, |
| 58 | + assistant_id: str, |
| 59 | + route_id: str, |
| 60 | + description: str | NotGiven = NotGiven, |
| 61 | + examples: List[str] | NotGiven = NotGiven, |
| 62 | + ) -> RouteResponse: |
| 63 | + body = self._create_body( |
| 64 | + description=description, |
| 65 | + examples=examples, |
| 66 | + ) |
| 67 | + |
| 68 | + return self._patch( |
| 69 | + path=f"/assistants/{assistant_id}/{self._module_name}/{route_id}", body=body, response_cls=RouteResponse |
| 70 | + ) |
| 71 | + |
| 72 | + def delete( |
| 73 | + self, |
| 74 | + *, |
| 75 | + assistant_id: str, |
| 76 | + route_id: str, |
| 77 | + ): |
| 78 | + return self._delete(path=f"/assistants/{assistant_id}/{self._module_name}/{route_id}") |
| 79 | + |
| 80 | + |
| 81 | +class AsyncAssistantRoutes(AsyncStudioResource, BaseRoutes): |
| 82 | + async def create( |
| 83 | + self, |
| 84 | + *, |
| 85 | + assistant_id: str, |
| 86 | + plan_id: str, |
| 87 | + name: str, |
| 88 | + description: str, |
| 89 | + examples: List[str], |
| 90 | + **kwargs, |
| 91 | + ) -> RouteResponse: |
| 92 | + body = self._create_body( |
| 93 | + plan_id=plan_id, |
| 94 | + name=name, |
| 95 | + description=description, |
| 96 | + examples=examples, |
| 97 | + **kwargs, |
| 98 | + ) |
| 99 | + |
| 100 | + return await self._post( |
| 101 | + path=f"/assistants/{assistant_id}/{self._module_name}", body=body, response_cls=RouteResponse |
| 102 | + ) |
| 103 | + |
| 104 | + async def list( |
| 105 | + self, |
| 106 | + *, |
| 107 | + assistant_id: str, |
| 108 | + name: str | NotGiven = NotGiven, |
| 109 | + ) -> ListRouteResponse: |
| 110 | + params = self._create_body(name=name) |
| 111 | + |
| 112 | + return await self._get( |
| 113 | + path=f"/assistants/{assistant_id}/{self._module_name}", params=params, response_cls=ListRouteResponse |
| 114 | + ) |
| 115 | + |
| 116 | + async def retrieve( |
| 117 | + self, |
| 118 | + *, |
| 119 | + assistant_id: str, |
| 120 | + route_id: str, |
| 121 | + ) -> RouteResponse: |
| 122 | + return await self._get( |
| 123 | + path=f"/assistants/{assistant_id}/{self._module_name}/{route_id}", response_cls=RouteResponse |
| 124 | + ) |
| 125 | + |
| 126 | + async def modify( |
| 127 | + self, |
| 128 | + *, |
| 129 | + assistant_id: str, |
| 130 | + route_id: str, |
| 131 | + description: str | NotGiven = NotGiven, |
| 132 | + examples: List[str] | NotGiven = NotGiven, |
| 133 | + ) -> RouteResponse: |
| 134 | + body = self._create_body( |
| 135 | + description=description, |
| 136 | + examples=examples, |
| 137 | + ) |
| 138 | + |
| 139 | + return await self._patch( |
| 140 | + path=f"/assistants/{assistant_id}/{self._module_name}/{route_id}", body=body, response_cls=RouteResponse |
| 141 | + ) |
| 142 | + |
| 143 | + async def delete( |
| 144 | + self, |
| 145 | + *, |
| 146 | + assistant_id: str, |
| 147 | + route_id: str, |
| 148 | + ): |
| 149 | + return await self._delete(path=f"/assistants/{assistant_id}/{self._module_name}/{route_id}") |
0 commit comments