Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Use pydantic codegen to generate types from OpenAPI Scope3AI #6

Merged
merged 4 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,16 @@ $ 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 \
&& uv run ruff format scope3ai/api/typesgen.py
```
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
Loading