57 lines
1.7 KiB
Python
57 lines
1.7 KiB
Python
import json
|
|
|
|
from ai import prompts
|
|
from cashflow_model import FinancialModel
|
|
from engine.forecast import ForecastService
|
|
|
|
|
|
class AssistantError(Exception):
|
|
pass
|
|
|
|
|
|
class AssistantService:
|
|
def __init__(self, model: FinancialModel):
|
|
self.model = model
|
|
|
|
def analyze(self, months: int = 12) -> dict:
|
|
forecast_service = ForecastService(self.model)
|
|
forecast_result = forecast_service.forecast_cashflow(months)
|
|
summary = forecast_service.summary(months)
|
|
|
|
prompt = prompts.format_context(
|
|
model_json=json.dumps(self.model.to_dict(), indent=2, ensure_ascii=False),
|
|
forecast_json=json.dumps(forecast_result, indent=2, ensure_ascii=False),
|
|
months=months,
|
|
)
|
|
|
|
return {
|
|
"prompt": prompt,
|
|
"summary": summary,
|
|
"forecast": forecast_result,
|
|
"ai_response": None,
|
|
}
|
|
|
|
def advice(self, question: str, months: int = 12) -> dict:
|
|
forecast_service = ForecastService(self.model)
|
|
forecast_result = forecast_service.forecast_cashflow(months)
|
|
|
|
prompt = prompts.ADVICE_PROMPT.format(
|
|
model_json=json.dumps(self.model.to_dict(), indent=2, ensure_ascii=False),
|
|
forecast_json=json.dumps(forecast_result, indent=2, ensure_ascii=False),
|
|
question=question,
|
|
)
|
|
|
|
return {
|
|
"prompt": prompt,
|
|
"ai_response": None,
|
|
}
|
|
|
|
def compare_scenarios(self, scenarios_json: str) -> dict:
|
|
prompt = prompts.SCENARIO_COMPARISON_PROMPT.format(
|
|
scenarios_json=scenarios_json,
|
|
)
|
|
return {
|
|
"prompt": prompt,
|
|
"ai_response": None,
|
|
}
|