testing new features

This commit is contained in:
2026-07-22 12:12:09 +03:00
parent 3cc8e94863
commit 9ed71cbc58
15 changed files with 1201 additions and 40 deletions
+15 -2
View File
@@ -1,7 +1,7 @@
import json
from ai import prompts
from cashflow_model import FinancialModel
from cashflow_model import CurrencyConverter, FinancialModel
from engine.forecast import ForecastService
@@ -10,8 +10,15 @@ class AssistantError(Exception):
class AssistantService:
def __init__(self, model: FinancialModel):
def __init__(
self,
model: FinancialModel,
converter: CurrencyConverter | None = None,
display_currency: str | None = None,
):
self.model = model
self.converter = converter or CurrencyConverter(model.exchange_rates)
self.display_currency = display_currency or model.base_currency
def analyze(self, months: int = 12) -> dict:
forecast_service = ForecastService(self.model)
@@ -22,6 +29,8 @@ class AssistantService:
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,
base_currency=self.model.base_currency,
display_currency=self.display_currency,
)
return {
@@ -39,6 +48,8 @@ class AssistantService:
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,
base_currency=self.model.base_currency,
display_currency=self.display_currency,
)
return {
@@ -49,6 +60,8 @@ class AssistantService:
def compare_scenarios(self, scenarios_json: str) -> dict:
prompt = prompts.SCENARIO_COMPARISON_PROMPT.format(
scenarios_json=scenarios_json,
base_currency=self.model.base_currency,
display_currency=self.display_currency,
)
return {
"prompt": prompt,
+21 -1
View File
@@ -7,6 +7,10 @@ ANALYZE_PROMPT = """
### Прогноз на {months} месяцев:
{forecast_json}
### Валюта:
Базовая валюта модели: {base_currency}
Отображаемая валюта: {display_currency}
Дай анализ по пунктам:
1. Общее финансовое состояние
2. Тренд денежного потока (рост/падение)
@@ -23,6 +27,10 @@ ADVICE_PROMPT = """
### Прогноз:
{forecast_json}
### Валюта:
Базовая валюта модели: {base_currency}
Отображаемая валюта: {display_currency}
Вопрос пользователя: {question}
Ответь как опытный финансовый консультант.
@@ -34,13 +42,25 @@ SCENARIO_COMPARISON_PROMPT = """
### Результаты сценариев:
{scenarios_json}
### Валюта:
Базовая валюта модели: {base_currency}
Отображаемая валюта: {display_currency}
Дай рекомендацию: какой сценарий наиболее вероятен и почему.
"""
def format_context(model_json: str, forecast_json: str, months: int = 12) -> str:
def format_context(
model_json: str,
forecast_json: str,
months: int = 12,
base_currency: str = "RUB",
display_currency: str = "RUB",
) -> str:
return ANALYZE_PROMPT.format(
model_json=model_json,
forecast_json=forecast_json,
months=months,
base_currency=base_currency,
display_currency=display_currency,
)