Skip to content

Commit

Permalink
feat: autogen types from openapi scope3ai yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
tito committed Dec 17, 2024
1 parent bc36d55 commit 43393da
Show file tree
Hide file tree
Showing 10 changed files with 905 additions and 369 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,15 @@ $ export UV_ENV_FILE=.env
$ uv sync --all-extras --all-groups
$ uv run python -m examples.openai-sync-chat
```

## Update typesgen.py

```bash
$ uv run datamodel-codegen \
--input tests/api-mocks/aiapi.yaml \
--input-file-type openapi \
--output scope3ai/api/typesgen.py \
--output-model-type pydantic_v2.BaseModel \
--use-schema-description \
--allow-extra-fields
```
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,6 @@ tests = [
"pytest>=8.3.4",
"pytest-docker>=3.1.1",
]
openapi = [
"datamodel-code-generator>=0.26.4",
]
30 changes: 15 additions & 15 deletions scope3ai/api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@

from .defaults import DEFAULT_API_URL
from .types import (
GpuResponse,
GPU,
ImpactRequest,
ImpactRequestRow,
ImpactRow,
ImpactResponse,
ModelFamily,
Family,
ModelResponse,
NodeCloud,
CloudProvider,
NodeResponse,
NodeService,
ManagedServiceProvider,
)


Expand Down Expand Up @@ -53,7 +53,7 @@ def client(self) -> Union[httpx.Client, httpx.AsyncClient]:
class ClientCommands:
def model(
self,
family: Optional[ModelFamily] = None,
family: Optional[Family] = None,
with_response: Optional[bool] = True,
) -> ModelResponse:
"""
Expand All @@ -73,21 +73,21 @@ def model(
def gpu(
self,
with_response: Optional[bool] = True,
) -> GpuResponse:
) -> GPU:
"""
List GPUs
"""
return self.execute_request(
"/gpu",
method="GET",
response_model=GpuResponse,
response_model=GPU,
with_response=with_response,
)

def node(
self,
service: Optional[NodeService] = None,
cloud: Optional[NodeCloud] = None,
service: Optional[ManagedServiceProvider] = None,
cloud: Optional[CloudProvider] = None,
with_response: Optional[bool] = True,
) -> NodeResponse:
"""
Expand All @@ -108,7 +108,7 @@ def node(

def impact(
self,
rows: List[ImpactRequestRow],
rows: List[ImpactRow],
debug: Optional[bool] = None,
with_response: Optional[bool] = True,
) -> ImpactResponse:
Expand Down Expand Up @@ -201,17 +201,17 @@ async def execute_request(

funcs_to_test = [
["model", {}],
["model", {"family": ModelFamily.CLAUDE}],
["model", {"family": Family.claud}],
["gpu", {}],
["node", {}],
["node", {"cloud": NodeCloud.AWS}],
# ["node", {"service": NodeService.AZURE_ML}],
["node", {"cloud": CloudProvider.aws}],
# ["node", {"service": ManagedServiceProvider.azure_ml}],
["impact", {"rows": []}],
[
"impact",
{
"rows": [
ImpactRequestRow(
ImpactRow(
model=Model(id="gpt_4o"),
input_tokens=1000,
output_tokens=200,
Expand Down
Loading

0 comments on commit 43393da

Please sign in to comment.