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: usage method #548

Merged
merged 3 commits into from
Dec 2, 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
6 changes: 3 additions & 3 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ concurrency:
env:
NIXTLA_API_KEY: ${{ secrets.NIXTLA_DEV_API_KEY }}
NIXTLA_BASE_URL: ${{ secrets.NIXTLA_DEV_BASE_URL }}
NIXTLA_API_KEY_CUSTOM: ${{ secrets.NIXTLA_DEV_API_KEY }}
NIXTLA_BASE_URL_CUSTOM: ${{ secrets.NIXTLA_DEV_BASE_URL }}
NIXTLA_API_KEY_CUSTOM: ${{ secrets.NIXTLA_API_KEY_CUSTOM }}
NIXTLA_BASE_URL_CUSTOM: ${{ secrets.NIXTLA_BASE_URL_CUSTOM }}
Comment on lines +16 to +17
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool

API_KEY_FRED: ${{ secrets.API_KEY_FRED }}

jobs:
Expand Down Expand Up @@ -82,4 +82,4 @@ jobs:
run: pip install uv && uv pip install --system ".[dev]"

- name: Run tests
run: nbdev_test --timing --do_print --n_workers 0 --skip_file_re "computing_at_scale|distributed"
run: nbdev_test --timing --do_print --n_workers 0 --skip_file_re "computing_at_scale|distributed"
3 changes: 2 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ repos:
rev: v0.2.1
hooks:
- id: ruff
files: 'nixtla'

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.10.1
hooks:
- id: mypy
args: [--ignore-missing-imports]
exclude: "setup.py"
files: 'nixtla'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool

2 changes: 1 addition & 1 deletion action_files/models_performance/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ def evaluate_benchmark_performace(self) -> Tuple[pd.DataFrame, pd.DataFrame]:
h=self.h,
n_windows=self.n_windows,
step_size=self.h,
).reset_index()
)
total_time = time() - init_time
cv_model_df = cv_model_df.rename(
columns={value: key for key, value in renamer.items()}
Expand Down
26 changes: 26 additions & 0 deletions nbs/src/nixtla_client.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -964,6 +964,16 @@
" or 'Forecasting! :)' in validation.get('detail', '')\n",
" )\n",
"\n",
" def usage(self) -> dict[str, dict[str, int]]:\n",
" if self._is_azure:\n",
" raise NotImplementedError('usage is not implemented for Azure deployments')\n",
" with httpx.Client(**self._client_kwargs) as client:\n",
" resp = client.get('/usage')\n",
" body = resp.json()\n",
" if resp.status_code != 200:\n",
" raise ApiError(status_code=resp.status_code, body=body)\n",
" return body\n",
"\n",
" def _distributed_forecast(\n",
" self,\n",
" df: DistributedDFType,\n",
Expand Down Expand Up @@ -2222,6 +2232,22 @@
"nixtla_client.validate_api_key()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#| hide\n",
"# usage endpoint\n",
"client2 = NixtlaClient(\n",
" base_url=os.environ['NIXTLA_BASE_URL_CUSTOM'],\n",
" api_key=os.environ['NIXTLA_API_KEY_CUSTOM'],\n",
")\n",
"usage = client2.usage()\n",
"assert sorted(usage.keys()) == ['minute', 'month']"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down
2 changes: 2 additions & 0 deletions nixtla/_modidx.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@
'nixtla/nixtla_client.py'),
'nixtla.nixtla_client.NixtlaClient.plot': ( 'src/nixtla_client.html#nixtlaclient.plot',
'nixtla/nixtla_client.py'),
'nixtla.nixtla_client.NixtlaClient.usage': ( 'src/nixtla_client.html#nixtlaclient.usage',
'nixtla/nixtla_client.py'),
'nixtla.nixtla_client.NixtlaClient.validate_api_key': ( 'src/nixtla_client.html#nixtlaclient.validate_api_key',
'nixtla/nixtla_client.py'),
'nixtla.nixtla_client._array_tails': ( 'src/nixtla_client.html#_array_tails',
Expand Down
10 changes: 10 additions & 0 deletions nixtla/nixtla_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -893,6 +893,16 @@ def validate_api_key(self, log: bool = True) -> bool:
"message", ""
) == "success" or "Forecasting! :)" in validation.get("detail", "")

def usage(self) -> dict[str, dict[str, int]]:
if self._is_azure:
raise NotImplementedError("usage is not implemented for Azure deployments")
with httpx.Client(**self._client_kwargs) as client:
resp = client.get("/usage")
body = resp.json()
if resp.status_code != 200:
raise ApiError(status_code=resp.status_code, body=body)
return body

def _distributed_forecast(
self,
df: DistributedDFType,
Expand Down