Skip to content
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: 5 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,10 @@ $ uv run python -m examples.openai-sync-chat

## Update typesgen.py

The `typesgen.py` script is derivated from the `aiapi.yaml`.
This script will download the latest YAML file, patch it if necessary
and generate the `typesgen.py` file.

```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
$ uv run tools/sync-api.py
```
4 changes: 2 additions & 2 deletions examples/api-async.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ async def list_gpus():


async def send_impact():
from scope3ai.api.types import ImpactRow, Model
from scope3ai.api.types import ImpactRow

print("Sending impact")
impact = ImpactRow(model=Model(id="gpt_4o"), input_tokens=100, output_tokens=100)
impact = ImpactRow(model_id="gpt_4o", input_tokens=100, output_tokens=100)
response = await client.impact(rows=[impact])
print(response)

Expand Down
4 changes: 2 additions & 2 deletions examples/api-sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ def list_gpus():


def send_impact():
from scope3ai.api.types import ImpactRow, Model
from scope3ai.api.types import ImpactRow

print("Sending impact")
impact = ImpactRow(model=Model(id="gpt_4o"), input_tokens=100, output_tokens=100)
impact = ImpactRow(model="gpt_4o", input_tokens=100, output_tokens=100)
response = client.impact(rows=[impact])
print(response)

Expand Down
33 changes: 20 additions & 13 deletions scope3ai/api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@

from .defaults import DEFAULT_API_URL
from .types import (
GPU,
Family,
GPUResponse,
ImpactRequest,
ImpactRow,
ImpactResponse,
Family,
ImpactRow,
ModelResponse,
CloudProvider,
NodeResponse,
ManagedServiceProvider,
)


Expand Down Expand Up @@ -73,31 +71,40 @@ def model(
def gpu(
self,
with_response: Optional[bool] = True,
) -> GPU:
) -> GPUResponse:
"""
List GPUs
"""
return self.execute_request(
"/gpu",
method="GET",
response_model=GPU,
response_model=GPUResponse,
with_response=with_response,
)

def node(
self,
service: Optional[ManagedServiceProvider] = None,
cloud: Optional[CloudProvider] = None,
service: Optional[str] = None,
cloud: Optional[str] = None,
custom: Optional[bool] = None,
gpu: Optional[str] = None,
instance: Optional[str] = None,
with_response: Optional[bool] = True,
) -> NodeResponse:
"""
List nodes
"""
params = {}
if service:
params["service"] = service.value
if cloud:
params["cloud"] = cloud.value
if service is not None:
params["service"] = service
if cloud is not None:
params["cloud"] = cloud
if custom is not None:
params["custom"] = custom
if gpu is not None:
params["gpu"] = gpu
if instance is not None:
params["instance"] = instance
return self.execute_request(
"/node",
method="GET",
Expand Down
1 change: 1 addition & 0 deletions scope3ai/api/tracer.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import List, Optional

from .typesgen import ImpactResponse, ModeledRow


Expand Down
8 changes: 0 additions & 8 deletions scope3ai/api/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from .tracer import Tracer
from .typesgen import (
GPU,
CloudProvider,
CountryCode,
DataType,
DebugInfo,
Expand All @@ -21,13 +20,10 @@
ImpactBigQueryError,
ImpactBigQueryRequest,
ImpactBigQueryResponse,
ImpactLogRequest,
ImpactLogRow,
ImpactMetrics,
ImpactRequest,
ImpactResponse,
ImpactRow,
ManagedServiceProvider,
Model,
ModeledRow,
ModelResponse,
Expand Down Expand Up @@ -93,22 +89,18 @@ async def await_impact(self, timeout: Optional[float] = None):
"Details",
"Error",
"GPU",
"ManagedServiceProvider",
"Image",
"CloudProvider",
"Task",
"Family",
"DataType",
"CountryCode",
"RegionCode",
"GPUResponse",
"ImpactLogRow",
"Model",
"GridMix",
"Node",
"ModelResponse",
"NodeResponse",
"ImpactLogRequest",
"ImpactRow",
"DebugInfo",
"ImpactRequest",
Expand Down
Loading
Loading