Skip to content

Commit

Permalink
feat: replace token by api_key and environment by base_url (#275)
Browse files Browse the repository at this point in the history
  • Loading branch information
AzulGarza authored Apr 2, 2024
1 parent dc8b72c commit d1f5268
Show file tree
Hide file tree
Showing 10 changed files with 304 additions and 143 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ jobs:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: [3.9, '3.10']
env:
TIMEGPT_TOKEN: ${{ secrets.TIMEGPT_TOKEN }}
TIMEGPT_API_URL: ${{ secrets.TIMEGPT_API_URL }}
TIMEGPT_CUSTOM_URL_TOKEN: ${{ secrets.TIMEGPT_CUSTOM_URL_TOKEN }}
TIMEGPT_CUSTOM_URL: ${{ secrets.TIMEGPT_CUSTOM_URL }}
NIXTLA_API_KEY: ${{ secrets.NIXTLA_API_KEY }}
NIXTLA_BASE_URL: ${{ secrets.NIXTLA_BASE_URL }}
NIXTLA_API_KEY_CUSTOM: ${{ secrets.NIXTLA_API_KEY_CUSTOM }}
NIXTLA_BASE_URL_CUSTOM: ${{ secrets.NIXTLA_BASE_URL_CUSTOM }}
API_KEY_FRED: ${{ secrets.API_KEY_FRED }}
steps:
- name: Clone repo
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/models-performance.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
strategy:
fail-fast: false
env:
TIMEGPT_TOKEN: ${{ secrets.TIMEGPT_TOKEN }}
NIXTLA_API_KEY: ${{ secrets.NIXTLA_API_KEY }}
PLOTS_REPO_URL: https://github.com/Nixtla/nixtla/blob/docs-figs-model-performance
steps:
- name: Clone repo
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ df = pd.read_csv('https://raw.githubusercontent.com/Nixtla/transfer-learning-tim

from nixtlats import TimeGPT
timegpt = TimeGPT(
# defaults to os.environ.get("TIMEGPT_TOKEN")
token = 'my_token_provided_by_nixtla'
# defaults to os.environ.get("NIXTLA_API_KEY")
api_key = 'my_api_key_provided_by_nixtla'
)
fcst_df = timegpt.forecast(df, h=24, level=[80, 90])
```
Expand Down
4 changes: 2 additions & 2 deletions action_files/models_performance/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def evaluate_timegpt(self, model: str) -> Tuple[pd.DataFrame, pd.DataFrame]:
init_time = time()
# A: this sould be replaced with
# cross validation
timegpt = TimeGPT(token=os.environ["TIMEGPT_TOKEN"])
timegpt = TimeGPT()
fcst_df = timegpt.forecast(
df=self.df_train,
X_df=self.df_test.drop(columns=self.target_col)
Expand Down Expand Up @@ -200,7 +200,7 @@ def evaluate_benchmark_performace(self) -> Tuple[pd.DataFrame, pd.DataFrame]:

def plot_and_save_forecasts(self, cv_df: pd.DataFrame, plot_dir: str) -> str:
"""Plot ans saves forecasts, returns the path of the plot"""
timegpt = TimeGPT(token=os.environ["TIMEGPT_TOKEN"])
timegpt = TimeGPT()
df = self.df.copy()
df[self.time_col] = pd.to_datetime(df[self.time_col])
if not self.has_id_col:
Expand Down
24 changes: 12 additions & 12 deletions nbs/distributed.timegpt.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,14 @@
"\n",
" def __init__(\n",
" self, \n",
" token: Optional[str] = None, \n",
" environment: Optional[str] = None,\n",
" api_key: Optional[str] = None, \n",
" base_url: Optional[str] = None,\n",
" max_retries: int = 6,\n",
" retry_interval: int = 10,\n",
" max_wait_time: int = 60,\n",
" ):\n",
" self.token = token\n",
" self.environment = environment\n",
" self.api_key = api_key\n",
" self.base_url = base_url\n",
" self.max_retries = max_retries\n",
" self.retry_interval = retry_interval\n",
" self.max_wait_time = max_wait_time\n",
Expand Down Expand Up @@ -164,7 +164,7 @@
" finetune_steps: int = 0,\n",
" finetune_loss: str = 'default',\n",
" clean_ex_first: bool = True,\n",
" validate_token: bool = False,\n",
" validate_api_key: bool = False,\n",
" add_history: bool = False,\n",
" date_features: Union[bool, List[str]] = False,\n",
" date_features_to_one_hot: Union[bool, List[str]] = True,\n",
Expand All @@ -182,7 +182,7 @@
" finetune_steps=finetune_steps,\n",
" finetune_loss=finetune_loss,\n",
" clean_ex_first=clean_ex_first,\n",
" validate_token=validate_token,\n",
" validate_api_key=validate_api_key,\n",
" add_history=add_history,\n",
" date_features=date_features,\n",
" date_features_to_one_hot=date_features_to_one_hot,\n",
Expand Down Expand Up @@ -214,7 +214,7 @@
" target_col: str = 'y',\n",
" level: Union[int, float] = 99,\n",
" clean_ex_first: bool = True,\n",
" validate_token: bool = False,\n",
" validate_api_key: bool = False,\n",
" date_features: Union[bool, List[str]] = False,\n",
" date_features_to_one_hot: Union[bool, List[str]] = True,\n",
" model: str = 'timegpt-1',\n",
Expand All @@ -227,7 +227,7 @@
" target_col=target_col,\n",
" level=level,\n",
" clean_ex_first=clean_ex_first,\n",
" validate_token=validate_token,\n",
" validate_api_key=validate_api_key,\n",
" date_features=date_features,\n",
" date_features_to_one_hot=date_features_to_one_hot,\n",
" model=model,\n",
Expand Down Expand Up @@ -257,7 +257,7 @@
" finetune_steps: int = 0,\n",
" finetune_loss: str = 'default',\n",
" clean_ex_first: bool = True,\n",
" validate_token: bool = False,\n",
" validate_api_key: bool = False,\n",
" date_features: Union[bool, List[str]] = False,\n",
" date_features_to_one_hot: Union[bool, List[str]] = True,\n",
" model: str = 'timegpt-1',\n",
Expand All @@ -276,7 +276,7 @@
" finetune_steps=finetune_steps,\n",
" finetune_loss=finetune_loss,\n",
" clean_ex_first=clean_ex_first,\n",
" validate_token=validate_token,\n",
" validate_api_key=validate_api_key,\n",
" date_features=date_features,\n",
" date_features_to_one_hot=date_features_to_one_hot,\n",
" model=model,\n",
Expand All @@ -303,8 +303,8 @@
" def _instantiate_timegpt(self):\n",
" from nixtlats.timegpt import _TimeGPT\n",
" timegpt = _TimeGPT(\n",
" token=self.token, \n",
" environment=self.environment,\n",
" api_key=self.api_key, \n",
" base_url=self.base_url,\n",
" max_retries=self.max_retries,\n",
" retry_interval=self.retry_interval,\n",
" max_wait_time=self.max_wait_time,\n",
Expand Down
6 changes: 3 additions & 3 deletions nbs/index.ipynb

Large diffs are not rendered by default.

Loading

0 comments on commit d1f5268

Please sign in to comment.