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: add validate token method #65

Merged
merged 1 commit into from
Aug 7, 2023
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
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