Skip to content

Commit

Permalink
v0.1.13
Browse files Browse the repository at this point in the history
  • Loading branch information
datarobot-devinfragit7 committed Dec 18, 2024
1 parent f27689d commit 2f30945
Show file tree
Hide file tree
Showing 13 changed files with 597 additions and 5,561 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ venv
.DS_Store
frontend/dynamic_app_settings.json
frontend/metadata.yaml
frontend/train_model_output.*.yaml
forecastic/train_model_output.*.yaml
notebooks/prep_scoring_data_output.*.yaml
e2e/test_results/*

Expand Down
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

## [0.1.13] - 2024-12-18

### Changed
- App backend no longer depends on the current working dir to read yaml settings
- Default scoring data is a 6 month period

### Fixed
- Removed duplicative plotting call from streamlit frontend
- Minor formatting issue in streamlit date picker font
- quickstart now asks you to change the default project name
- quickstart now prints the application URL
- quickstart.py now supports multiline values correctly, even with multiple comments

## [0.1.12] - 2024-12-12

### Fixed
Expand Down
10 changes: 4 additions & 6 deletions __main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from forecastic.resources import (
ScoringDataset,
app_env_name,
app_settings_path,
scoring_dataset_env_name,
time_series_deployment_env_name,
)
Expand All @@ -43,7 +44,6 @@
from infra.settings_llm_credential import credential, credential_args
from infra.settings_main import (
model_training_nb,
model_training_output_file,
scoring_prep_nb,
scoring_prep_output_file,
)
Expand All @@ -52,14 +52,12 @@

check_feature_flags(pathlib.Path("infra/feature_flag_requirements.yaml"))

if not model_training_output_file.exists():
if not app_settings_path.exists():
pulumi.info("Executing model training notebook...")
run_notebook(model_training_nb)
else:
pulumi.info(
f"Using existing model training outputs in '{model_training_output_file}'"
)
with open(model_training_output_file) as f:
pulumi.info(f"Using existing model training outputs in '{app_settings_path}'")
with open(app_settings_path) as f:
model_training_output = AppSettings(**yaml.safe_load(f))


Expand Down
5,490 changes: 0 additions & 5,490 deletions assets/store_sales_predict.csv

Large diffs are not rendered by default.

66 changes: 29 additions & 37 deletions forecastic/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
import datetime as dt
import functools
import json
import subprocess
import sys
from importlib import resources
from typing import Any, List, Optional, Tuple
from urllib.parse import urljoin

Expand All @@ -37,7 +37,12 @@

from forecastic.credentials import AzureOpenAICredentials
from forecastic.i18n import gettext
from forecastic.resources import Application, ScoringDataset, TimeSeriesDeployment
from forecastic.resources import (
Application,
ScoringDataset,
TimeSeriesDeployment,
app_settings_file_name,
)
from forecastic.schema import (
AppRuntimeAttributes,
AppSettings,
Expand All @@ -48,26 +53,15 @@
PredictionRow,
)


def get_stack_suffix() -> str:
try:
return (
"."
+ subprocess.check_output(
["pulumi", "stack", "--show-name", "--non-interactive"],
text=True,
stderr=subprocess.STDOUT,
).strip()
)
except Exception:
pass
return ""


app_settings_file_name = f"train_model_output{get_stack_suffix()}.yaml"
try:
with open(app_settings_file_name) as f:
app_settings = AppSettings(**yaml.safe_load(f))
# Load static settings w/o making assumptions about working directory
app_settings = AppSettings(
**yaml.safe_load(
resources.files(__name__.split(".")[0])
.joinpath(app_settings_file_name)
.read_text()
)
)

time_series_deployment_id = TimeSeriesDeployment().id
scoring_dataset_id = ScoringDataset().id
Expand Down Expand Up @@ -307,13 +301,14 @@ def _format_predictions(predictions: list[dict[str, Any]]) -> list[dict[Any, Any
data = pd.DataFrame(predictions)

target = dr.Project.get(app_settings.project_id).target # type: ignore[attr-defined]
multiseries_id_column = app_settings.multiseries_id_column
date_id = app_settings.datetime_partition_column
prediction_interval = f"{app_settings.prediction_interval:.0f}"
percentile_prefix = f"PREDICTION_{prediction_interval}_PERCENTILE"

data["timestamp"] = data[date_id]
data["prediction"] = data[f"{target}_PREDICTION"]
data["seriesId"] = target
data["seriesId"] = data[multiseries_id_column]
data["forecastDistance"] = data["FORECAST_DISTANCE"]
data["forecastPoint"] = data["FORECAST_POINT"]

Expand Down Expand Up @@ -432,7 +427,6 @@ def get_forecast_as_plotly_json(

fig.update_xaxes(
color="#404040",
title_font_family="Gravitas One",
title_text=datetime_partition_column,
showgrid=False,
linecolor="#adadad",
Expand Down Expand Up @@ -642,21 +636,19 @@ def _get_completion(
return str(resp.choices[0].message.content)


def share_access(emails: List[str]) -> tuple[str, int]:
def share_access(emails: List[str]) -> None:
"""Share application with other users."""
client = dr.Client() # type: ignore[attr-defined]
try:
application_id = Application().id
except ValidationError:
return "Application ID not found. Have you deployed it with pulumi up?", 500
try:
url = f"customApplications/{application_id}/sharedRoles"
roles = [
{"role": "CONSUMER", "shareRecipientType": "user", "username": email}
for email in emails
]
payload = {"operation": "updateRoles", "roles": roles}
client.patch(url, json=payload)
return "Success", 200
except Exception as e:
return str(e), 500
except ValidationError as e:
raise ValidationError(
"Application ID not found. Have you deployed it with pulumi up?"
) from e
url = f"customApplications/{application_id}/sharedRoles"
roles = [
{"role": "CONSUMER", "shareRecipientType": "user", "username": email}
for email in emails
]
payload = {"operation": "updateRoles", "roles": roles}
client.patch(url, json=payload)
Loading

0 comments on commit 2f30945

Please sign in to comment.