Skip to content

Commit

Permalink
Merge pull request #65 from Nixtla/feat/add_token_validator_endpoint
Browse files Browse the repository at this point in the history
feat: add validate token method
  • Loading branch information
AzulGarza authored Aug 7, 2023
2 parents 3f44347 + b4bd506 commit 577fa2c
Show file tree
Hide file tree
Showing 3 changed files with 201 additions and 71 deletions.
245 changes: 176 additions & 69 deletions nbs/timegpt.ipynb

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion nixtlats/_modidx.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@
'nixtlats/timegpt.py'),
'nixtlats.timegpt.TimeGPT.forecast': ('timegpt.html#timegpt.forecast', 'nixtlats/timegpt.py'),
'nixtlats.timegpt.TimeGPT.request_headers': ( 'timegpt.html#timegpt.request_headers',
'nixtlats/timegpt.py')}}}
'nixtlats/timegpt.py'),
'nixtlats.timegpt.TimeGPT.validate_token': ( 'timegpt.html#timegpt.validate_token',
'nixtlats/timegpt.py')}}}
23 changes: 22 additions & 1 deletion nixtlats/timegpt.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/timegpt.ipynb.

# %% auto 0
__all__ = []
__all__ = ['logger']

# %% ../nbs/timegpt.ipynb 5
import logging
import inspect
import json
import requests
from typing import Dict, List, Optional, Union

import pandas as pd

logger = logging.getLogger()

# %% ../nbs/timegpt.ipynb 7
class TimeGPT:
"""
Expand Down Expand Up @@ -48,6 +51,19 @@ def _parse_response(self, response) -> Dict:
raise Exception(response)
return resp

def validate_token(self) -> bool:
"""Returns True if your token is valid."""
response = requests.post(
f"{self.api_url}/validate_token_front",
headers=self.request_headers,
)
valid = True
try:
response = self._parse_response(response)
except:
valid = False
return valid

def _input_size(self, freq: str):
response_input_size = requests.post(
f"{self.api_url}/timegpt_input_size",
Expand Down Expand Up @@ -240,6 +256,11 @@ def forecast(
DataFrame with TimeGPT forecasts for point predictions and probabilistic
predictions (if level is not None).
"""
if not self.validate_token():
raise Exception(
"Token not valid, please go to https://dashboard.nixtla.io/ to get yours"
)

df, X_df, drop_uid = self._validate_inputs(
df=df,
X_df=X_df,
Expand Down

0 comments on commit 577fa2c

Please sign in to comment.