QAway-to commited on
Commit
15e92d0
·
1 Parent(s): f912bc7
Files changed (5) hide show
  1. app.py +1 -1
  2. core/analyzer.py +2 -3
  3. core/chat.py +4 -4
  4. core/comparer.py +4 -4
  5. prompts/system_prompts.py +11 -16
app.py CHANGED
@@ -16,7 +16,7 @@ chatbot = ChatAssistant(llm_service, MODEL_NAME)
16
 
17
  # === Gradio Interface ===
18
  with gr.Blocks(theme=gr.themes.Soft()) as demo:
19
- gr.Markdown("## 🧠 Анализ и сравнение инвестиционных портфелей **TradeLink**")
20
 
21
  with gr.Tab("📊 Анализ1121"):
22
  portfolio_input = gr.Textbox(label="Введите ссылку или portfolioId", placeholder="ea856c1b-...")
 
16
 
17
  # === Gradio Interface ===
18
  with gr.Blocks(theme=gr.themes.Soft()) as demo:
19
+ gr.Markdown("## 🧠 Анализ инвестиционных порфеля")
20
 
21
  with gr.Tab("📊 Анализ1121"):
22
  portfolio_input = gr.Textbox(label="Введите ссылку или portfolioId", placeholder="ea856c1b-...")
core/analyzer.py CHANGED
@@ -3,7 +3,7 @@
3
  Purpose: Handles single-portfolio analysis using LLM. Fetches metrics, builds prompt, streams reasoning.
4
 
5
  🇷🇺 Модуль: analyzer.py
6
- Назначение: анализ одного портфеля с использованием LLM. Получает метрики, формирует промпт, возвращает потоковый ответ.
7
  """
8
 
9
  import asyncio
@@ -39,9 +39,8 @@ class PortfolioAnalyzer:
39
  yield "❗ Не удалось получить данные по метрикам."
40
  return
41
 
42
- # Build prompt text from metrics
43
  metrics_text = ", ".join(f"{k}: {v}" for k, v in metrics.items())
44
- prompt = f"{REFERENCE_PROMPT}\n\nUse this data for analysis:\n{metrics_text}"
45
 
46
  try:
47
  messages = [
 
3
  Purpose: Handles single-portfolio analysis using LLM. Fetches metrics, builds prompt, streams reasoning.
4
 
5
  🇷🇺 Модуль: analyzer.py
6
+ Назначение: анализ одного инвестиционного портфеля с использованием LLM. Получает метрики, формирует промпт, возвращает потоковый ответ.
7
  """
8
 
9
  import asyncio
 
39
  yield "❗ Не удалось получить данные по метрикам."
40
  return
41
 
 
42
  metrics_text = ", ".join(f"{k}: {v}" for k, v in metrics.items())
43
+ prompt = f"{REFERENCE_PROMPT}\n\nИспользуй эти данные для анализа:\n{metrics_text}"
44
 
45
  try:
46
  messages = [
core/chat.py CHANGED
@@ -1,14 +1,14 @@
1
  """
2
  🇬🇧 Module: chat.py
3
- Purpose: General chat interface for user questions about TradeLink and its ecosystem.
4
 
5
  🇷🇺 Модуль: chat.py
6
- Назначение: общий чат-помощник для ответов на вопросы о платформе TradeLink.
7
  """
8
 
9
  from typing import Generator
10
  from services.llm_client import llm_service
11
- from prompts.system_prompts import TRADELINK_CONTEXT
12
 
13
 
14
  class ChatAssistant:
@@ -21,7 +21,7 @@ class ChatAssistant:
21
  def run(self, user_input: str) -> Generator[str, None, None]:
22
  """Stream chat responses."""
23
  messages = [
24
- {"role": "system", "content": TRADELINK_CONTEXT},
25
  {"role": "user", "content": user_input},
26
  ]
27
 
 
1
  """
2
  🇬🇧 Module: chat.py
3
+ Purpose: General chat interface for user questions about investments or portfolios.
4
 
5
  🇷🇺 Модуль: chat.py
6
+ Назначение: общий чат-помощник для ответов на вопросы об инвестициях и портфелях.
7
  """
8
 
9
  from typing import Generator
10
  from services.llm_client import llm_service
11
+ from prompts.system_prompts import GENERAL_CONTEXT
12
 
13
 
14
  class ChatAssistant:
 
21
  def run(self, user_input: str) -> Generator[str, None, None]:
22
  """Stream chat responses."""
23
  messages = [
24
+ {"role": "system", "content": GENERAL_CONTEXT},
25
  {"role": "user", "content": user_input},
26
  ]
27
 
core/comparer.py CHANGED
@@ -3,7 +3,7 @@
3
  Purpose: Compares two portfolios using LLM. Fetches metrics for both and builds a unified comparison prompt.
4
 
5
  🇷🇺 Модуль: comparer.py
6
- Назначение: сравнение двух портфелей с помощью LLM. Получает метрики обоих портфелей, формирует промпт и возвращает потоковый результат.
7
  """
8
 
9
  import asyncio
@@ -50,9 +50,9 @@ class PortfolioComparer:
50
 
51
  prompt = (
52
  f"{REFERENCE_COMPARISON_PROMPT}\n"
53
- f"Use this data for comparison:\n"
54
- f"Portfolio A: {m1_text}\n"
55
- f"Portfolio B: {m2_text}"
56
  )
57
 
58
  try:
 
3
  Purpose: Compares two portfolios using LLM. Fetches metrics for both and builds a unified comparison prompt.
4
 
5
  🇷🇺 Модуль: comparer.py
6
+ Назначение: сравнение двух инвестиционных портфелей с помощью LLM. Получает метрики обоих портфелей, формирует промпт и возвращает потоковый результат.
7
  """
8
 
9
  import asyncio
 
50
 
51
  prompt = (
52
  f"{REFERENCE_COMPARISON_PROMPT}\n"
53
+ f"Используй эти данные для сравнения:\n"
54
+ f"Портфель A: {m1_text}\n"
55
+ f"Портфель B: {m2_text}"
56
  )
57
 
58
  try:
prompts/system_prompts.py CHANGED
@@ -1,27 +1,22 @@
1
  """
2
  🇬🇧 Module: system_prompts.py
3
- Purpose: Contains system-level contexts and role descriptions for the LLM (e.g., TradeLink assistant persona).
4
 
5
  🇷🇺 Модуль: system_prompts.py
6
- Назначение: содержит системные контексты и описания ролей для LLM (например, контекст ассистента TradeLink).
7
  """
8
 
9
- TRADELINK_CONTEXT = (
10
- "You are a professional assistant representing the TradeLink platform. "
11
- "TradeLink helps users analyze cryptocurrency portfolios, verify trader performance, "
12
- "and provide transparent investment insights.\n\n"
13
- "Always answer concisely and factually, from the perspective of the TradeLink team. "
14
- "If a question is not related to TradeLink, politely state that it is outside your scope."
15
- )
16
-
17
  ANALYSIS_SYSTEM_PROMPT = (
18
- "You are a financial analyst specializing in interpreting portfolio metrics. "
19
- "Your job is to provide clear, professional commentary on each metric's significance, "
20
- "strengths, and weaknesses."
21
  )
22
 
23
  COMPARISON_SYSTEM_PROMPT = (
24
- "You are a senior investment advisor comparing two portfolios. "
25
- "Provide an objective and structured analysis highlighting differences, "
26
- "advantages, and potential risks of each."
 
 
 
 
27
  )
 
1
  """
2
  🇬🇧 Module: system_prompts.py
3
+ Purpose: Stores system-level instructions for LLM.
4
 
5
  🇷🇺 Модуль: system_prompts.py
6
+ Назначение: хранит системные инструкции для LLM.
7
  """
8
 
 
 
 
 
 
 
 
 
9
  ANALYSIS_SYSTEM_PROMPT = (
10
+ "You are a financial assistant. Analyze the investment portfolio data provided, "
11
+ "explain the portfolio's key strengths, risks, and possible improvements."
 
12
  )
13
 
14
  COMPARISON_SYSTEM_PROMPT = (
15
+ "You are a financial analyst comparing two investment portfolios. "
16
+ "Compare them based on risk, performance, and diversification."
17
+ )
18
+
19
+ GENERAL_CONTEXT = (
20
+ "You are an intelligent assistant specializing in investment portfolios, finance, "
21
+ "and market analysis. Answer clearly, concisely, and professionally."
22
  )