Skip to content

A curated collection of practical AI projects implementing OCR systems, RAG, AI agents, and other AI use cases.

fix(finagent): remove unresolved merge conflict markers

Rudy Celekli2c60349695e7
diff --git a/ai_agents/finagent/.env.example b/ai_agents/finagent/.env.example
index 0a7f0b1..cf8f5e6 100644
--- a/ai_agents/finagent/.env.example
+++ b/ai_agents/finagent/.env.example
@@ -1,6 +1,3 @@
-<<<<<<< HEAD
-OPENAI_API_KEY=your_openai_api_key_here
-=======
# Mistral API key for the Mistral Small 4 (mistral-small-latest) model used by the financial analysis agents.
# Get one at https://console.mistral.ai/api-keys
MISTRAL_API_KEY=your_mistral_api_key_here
@@ -8,4 +5,3 @@ MISTRAL_API_KEY=your_mistral_api_key_here
# Optional: Firecrawl API key used for enhanced news scraping features.
# Get one at https://firecrawl.dev
FIRECRAWL_API_KEY=your_firecrawl_api_key_here
->>>>>>> 1d1e9f137cfd1123edbae5d8e955ce0b9c7fcf4a
diff --git a/ai_agents/finagent/financial_agents.py b/ai_agents/finagent/financial_agents.py
index d88e016..c9eb02f 100644
--- a/ai_agents/finagent/financial_agents.py
+++ b/ai_agents/finagent/financial_agents.py
@@ -1,17 +1,9 @@
-<<<<<<< HEAD
-=======
"""Multi-agent financial analysis pipeline built on Mistral Small 4 and Yahoo Finance market data."""
->>>>>>> 1d1e9f137cfd1123edbae5d8e955ce0b9c7fcf4a
import os
import re
import json
import yfinance as yf
-<<<<<<< HEAD
-import google.generativeai as genai
-
-def _normalize_period(period: str) -> str:
-=======
from dotenv import load_dotenv
from mistralai.client import Mistral
@@ -19,7 +11,6 @@ load_dotenv()
def _normalize_period(period: str) -> str:
"""Normalizes a user-supplied time period string into a yfinance-compatible period code."""
->>>>>>> 1d1e9f137cfd1123edbae5d8e955ce0b9c7fcf4a
if not period:
return '6mo'
p = str(period).strip().lower()
@@ -32,12 +23,6 @@ def _normalize_period(period: str) -> str:
return p
-<<<<<<< HEAD
-class GeminiAgent:
- def __init__(self, api_key: str, role: str, system_prompt: str):
- genai.configure(api_key=api_key)
- self.model = genai.GenerativeModel('gemini-2.5-flash')
-=======
def _summarize_stock_data(stock_data) -> str:
"""Builds a compact text summary of real OHLCV price data to ground the analysis prompt."""
first = stock_data.iloc[0]
@@ -67,19 +52,11 @@ class MistralAgent:
def __init__(self, api_key: str, role: str, system_prompt: str):
self.client = Mistral(api_key=api_key)
self.model = 'mistral-small-latest'
->>>>>>> 1d1e9f137cfd1123edbae5d8e955ce0b9c7fcf4a
self.role = role
self.system_prompt = system_prompt
def generate(self, prompt: str) -> str:
full_prompt = f"{self.system_prompt}\n\nUser Request: {prompt}"
-<<<<<<< HEAD
- response = self.model.generate_content(full_prompt)
- return response.text
-
-
-class FinancialTools:
-=======
response = self.client.chat.complete(
model=self.model,
messages=[{"role": "user", "content": full_prompt}],
@@ -90,26 +67,18 @@ class FinancialTools:
class FinancialTools:
"""Provides access to the market data needed by the analysis agents."""
->>>>>>> 1d1e9f137cfd1123edbae5d8e955ce0b9c7fcf4a
def get_stock_data(self, symbol: str, period: str = "6mo"):
ticker = yf.Ticker(symbol)
return ticker.history(period=period)
class FinancialAnalysisTeam:
-<<<<<<< HEAD
- def __init__(self, gemini_api_key: str):
- self.tools = FinancialTools()
- self.query_parser = GeminiAgent(
- gemini_api_key,
-=======
"""Coordinates the query parser and market analyst agents to produce a stock analysis."""
def __init__(self, mistral_api_key: str):
self.tools = FinancialTools()
self.query_parser = MistralAgent(
mistral_api_key,
->>>>>>> 1d1e9f137cfd1123edbae5d8e955ce0b9c7fcf4a
"Query Parser",
"""You are a financial query parser. Extract from the user query:
- Stock symbol (ticker)
@@ -117,23 +86,15 @@ class FinancialAnalysisTeam:
- Time period (like 1d, 1mo, 6mo, 1y)
Return a JSON object with keys: symbol, analysis_type, time_period."""
)
-<<<<<<< HEAD
- self.market_analyst = GeminiAgent(
- gemini_api_key,
-=======
self.market_analyst = MistralAgent(
mistral_api_key,
->>>>>>> 1d1e9f137cfd1123edbae5d8e955ce0b9c7fcf4a
"Market Analyst",
"""You are a senior financial analyst. Provide a clear, professional, and actionable analysis for the stock.
Include market trends, price action, risk assessment and investment recommendations."""
)
def parse_query(self, query: str):
-<<<<<<< HEAD
-=======
"""Parses a natural language query into a symbol, analysis type, and time period."""
->>>>>>> 1d1e9f137cfd1123edbae5d8e955ce0b9c7fcf4a
response = self.query_parser.generate(query)
try:
json_match = re.search(r"\{.*\}", response, re.DOTALL)
@@ -152,12 +113,6 @@ Include market trends, price action, risk assessment and investment recommendati
return data
def analyze_market(self, query_info, stock_data) -> str:
-<<<<<<< HEAD
- prompt = (
- f"Analyze the stock symbol {query_info['symbol']} for the period "
- f"{query_info.get('time_period', '6mo')}. Use recent price data and technical indicators "
- f"to provide market trends, risk factors, and recommendations."
-=======
"""Asks the market analyst agent for a written analysis grounded in the fetched stock data."""
data_summary = _summarize_stock_data(stock_data)
prompt = (
@@ -166,15 +121,11 @@ Include market trends, price action, risk assessment and investment recommendati
f"{data_summary}\n\n"
f"Base your trends, risk factors, and recommendations only on this data. "
f"Do not assume any other price information."
->>>>>>> 1d1e9f137cfd1123edbae5d8e955ce0b9c7fcf4a
)
return self.market_analyst.generate(prompt)
def analyze(self, query: str) -> str:
-<<<<<<< HEAD
-=======
"""Runs the full parse, fetch, and analyze pipeline for a query and returns the analysis text."""
->>>>>>> 1d1e9f137cfd1123edbae5d8e955ce0b9c7fcf4a
query_info = self.parse_query(query)
period = _normalize_period(query_info.get("time_period", "6mo"))
stock_data = self.tools.get_stock_data(query_info["symbol"], period)
@@ -186,18 +137,11 @@ Include market trends, price action, risk assessment and investment recommendati
def run_financial_analysis(query: str) -> str:
-<<<<<<< HEAD
- gemini_api_key = os.getenv("GEMINI_API_KEY")
- if not gemini_api_key:
- return "Error: GEMINI_API_KEY environment variable is not set."
- team = FinancialAnalysisTeam(gemini_api_key)
-=======
"""Builds a FinancialAnalysisTeam from the configured Mistral API key and runs the given query."""
mistral_api_key = os.getenv("MISTRAL_API_KEY")
if not mistral_api_key:
return "Error: MISTRAL_API_KEY environment variable is not set."
team = FinancialAnalysisTeam(mistral_api_key)
->>>>>>> 1d1e9f137cfd1123edbae5d8e955ce0b9c7fcf4a
try:
return team.analyze(query)
except Exception as e:
diff --git a/ai_agents/finagent/main.py b/ai_agents/finagent/main.py
index cc82ad0..702e677 100644
--- a/ai_agents/finagent/main.py
+++ b/ai_agents/finagent/main.py
@@ -1,8 +1,3 @@
-<<<<<<< HEAD
-from mcp.server.fastmcp import FastMCP
-from financial_agents import run_financial_analysis
-
-=======
"""MCP server exposing the financial stock analysis tools backed by Mistral Small 4."""
from dotenv import load_dotenv
@@ -10,7 +5,6 @@ from mcp.server.fastmcp import FastMCP
from financial_agents import run_financial_analysis
load_dotenv()
->>>>>>> 1d1e9f137cfd1123edbae5d8e955ce0b9c7fcf4a
# Create FastMCP instance
mcp = FastMCP("financial-analyst")
diff --git a/ai_agents/finagent/requirements.txt b/ai_agents/finagent/requirements.txt
index ed238e8..4daf2c8 100644
--- a/ai_agents/finagent/requirements.txt
+++ b/ai_agents/finagent/requirements.txt
@@ -1,13 +1,4 @@
-<<<<<<< HEAD
-google-generativeai>=0.3.0
-mcp>=0.1.0
-yfinance>=0.2.18
-pandas>=1.5.0
-numpy>=1.21.0
-matplotlib>=3.5.0
-=======
mistralai>=1.0.0
mcp>=0.1.0
yfinance>=0.2.18
->>>>>>> 1d1e9f137cfd1123edbae5d8e955ce0b9c7fcf4a
python-dotenv>=0.19.0
\ No newline at end of file