Skip to content

Commit

Permalink
Merge pull request #93 from Nixtla/feat/compat_endppoint
Browse files Browse the repository at this point in the history
feat: add custom url option
  • Loading branch information
AzulGarza authored Aug 26, 2023
2 parents ed7aa41 + 75b1faa commit 666c3d5
Show file tree
Hide file tree
Showing 5 changed files with 256 additions and 120 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ jobs:
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 }}
API_KEY_FRED: ${{ secrets.API_KEY_FRED }}
run: nbdev_test

Expand Down Expand Up @@ -85,5 +87,7 @@ jobs:
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 }}
API_KEY_FRED: ${{ secrets.API_KEY_FRED }}
run: nbdev_test --skip_file_glob "*distributed*"
95 changes: 73 additions & 22 deletions nbs/distributed.timegpt.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"#| default_exp distributed.timegpt"
Expand All @@ -12,7 +14,9 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"#| hide \n",
Expand All @@ -23,7 +27,9 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"#| export\n",
Expand All @@ -40,7 +46,9 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"#| export\n",
Expand All @@ -49,6 +57,7 @@
" def forecast(\n",
" self,\n",
" token: str,\n",
" environment,\n",
" df: fugue.AnyDataFrame,\n",
" h: int,\n",
" freq: Optional[str] = None, \n",
Expand Down Expand Up @@ -100,26 +109,27 @@
" fcst_df = fa.transform(\n",
" df,\n",
" self._forecast,\n",
" params=dict(token=token, kwargs=kwargs,),\n",
" params=dict(token=token, environment=environment, kwargs=kwargs,),\n",
" schema=schema,\n",
" engine=engine,\n",
" partition=partition,\n",
" as_fugue=True,\n",
" )\n",
" return fa.get_native_as_df(fcst_df)\n",
"\n",
" def _instantiate_timegpt(self, token: str):\n",
" def _instantiate_timegpt(self, token: str, environment: str):\n",
" from nixtlats.timegpt import _TimeGPT\n",
" timegpt = _TimeGPT(token=token)\n",
" timegpt = _TimeGPT(token=token, environment=environment)\n",
" return timegpt\n",
"\n",
" def _forecast(\n",
" self, \n",
" df: pd.DataFrame, \n",
" token: str,\n",
" environment: str,\n",
" kwargs,\n",
" ) -> pd.DataFrame:\n",
" timegpt = self._instantiate_timegpt(token)\n",
" timegpt = self._instantiate_timegpt(token, environment)\n",
" return timegpt._forecast(df=df, **kwargs)\n",
" \n",
" @staticmethod\n",
Expand All @@ -135,7 +145,9 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"#| hide\n",
Expand All @@ -151,7 +163,9 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"#| hide\n",
Expand All @@ -164,6 +178,7 @@
" ):\n",
" fcst_df = distributed_timegpt.forecast(\n",
" token=os.environ['TIMEGPT_TOKEN'], \n",
" environment=None,\n",
" df=df, \n",
" h=horizon,\n",
" id_col=id_col,\n",
Expand All @@ -184,7 +199,9 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"#| hide\n",
Expand All @@ -197,6 +214,7 @@
" ):\n",
" fcst_df = distributed_timegpt.forecast(\n",
" token=os.environ['TIMEGPT_TOKEN'], \n",
" environment=None,\n",
" df=df, \n",
" h=horizon, \n",
" num_partitions=1,\n",
Expand All @@ -207,6 +225,7 @@
" fcst_df = fa.as_pandas(fcst_df)\n",
" fcst_df_2 = distributed_timegpt.forecast(\n",
" token=os.environ['TIMEGPT_TOKEN'], \n",
" environment=None,\n",
" df=df, \n",
" h=horizon, \n",
" num_partitions=2,\n",
Expand All @@ -224,7 +243,9 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"#| hide\n",
Expand All @@ -237,7 +258,9 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"#| hide\n",
Expand All @@ -250,7 +273,9 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"#| hide\n",
Expand All @@ -260,7 +285,9 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"#| hide\n",
Expand All @@ -284,7 +311,9 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"#| hide\n",
Expand All @@ -294,7 +323,9 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"#| hide\n",
Expand All @@ -315,7 +346,9 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"#| hide\n",
Expand All @@ -325,7 +358,9 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"#| hide\n",
Expand All @@ -345,7 +380,9 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"#| hide\n",
Expand All @@ -356,7 +393,9 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"#| hide\n",
Expand All @@ -377,9 +416,21 @@
],
"metadata": {
"kernelspec": {
"display_name": "python3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.12"
}
},
"nbformat": 4,
Expand Down
Loading

0 comments on commit 666c3d5

Please sign in to comment.