testing new features

This commit is contained in:
2026-07-22 12:40:42 +03:00
parent 3cc8e94863
commit e9c7120323
21 changed files with 1614 additions and 293 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,
+13 -38
View File
@@ -1,46 +1,21 @@
ANALYZE_PROMPT = """
Ты — финансовый AI-ассистент. Проанализируй финансовую модель пользователя.
from cli.i18n import t
### Модель (JSON):
{model_json}
### Прогноз на {months} месяцев:
{forecast_json}
Дай анализ по пунктам:
1. Общее финансовое состояние
2. Тренд денежного потока (рост/падение)
3. Достаточность ликвидности
4. Рекомендации по улучшению
"""
ADVICE_PROMPT = """
Ты — финансовый AI-ассистент. Дай персональные рекомендации.
### Модель:
{model_json}
### Прогноз:
{forecast_json}
Вопрос пользователя: {question}
Ответь как опытный финансовый консультант.
"""
SCENARIO_COMPARISON_PROMPT = """
Ты — финансовый AI-ассистент. Сравни сценарии прогноза.
### Результаты сценариев:
{scenarios_json}
Дай рекомендацию: какой сценарий наиболее вероятен и почему.
"""
ANALYZE_PROMPT = t("prompt.analyze")
ADVICE_PROMPT = t("prompt.advice")
SCENARIO_COMPARISON_PROMPT = t("prompt.scenario_comparison")
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,
)