This commit resolves all outstanding issues with the AI Insights feature.
- Corrects the transcript formatting logic in to properly handle the database JSON structure, ensuring the AI receives the correct context.
- Fixes the Gemini API client by using the correct model name ('gemini-2.0-flash') and the proper client initialization.
- Updates to securely pass the API key as an environment variable to the container.
- Cleans up the codebase by removing temporary debugging endpoints.
- Adds script for programmatic updates.
- Updates documentation with troubleshooting insights from the implementation process.
49 lines
1.7 KiB
Python
49 lines
1.7 KiB
Python
from sqlalchemy import create_engine
|
|
from sqlalchemy.orm import sessionmaker
|
|
from backend.database import Industry
|
|
from backend.services.classification import ClassificationService
|
|
import logging
|
|
|
|
# Setup DB connection directly to the file
|
|
# Note: We need to use the absolute path that works inside the container or relative if running locally
|
|
# Assuming we run this via 'docker exec' or locally if paths align.
|
|
# For safety, I'll use the path from config but typically inside container it's /app/...
|
|
DB_URL = "sqlite:////app/companies_v3_fixed_2.db"
|
|
|
|
engine = create_engine(DB_URL)
|
|
SessionLocal = sessionmaker(bind=engine)
|
|
db = SessionLocal()
|
|
|
|
def test_logic():
|
|
print("--- DEBUGGING STANDARDIZATION LOGIC ---")
|
|
|
|
industry_name = "Healthcare - Hospital"
|
|
industry = db.query(Industry).filter(Industry.name == industry_name).first()
|
|
|
|
if not industry:
|
|
print(f"ERROR: Industry '{industry_name}' not found!")
|
|
return
|
|
|
|
print(f"Industry: {industry.name}")
|
|
print(f"Search Term: {industry.scraper_search_term}")
|
|
print(f"Standardization Logic (Raw DB Value): '{industry.standardization_logic}'")
|
|
|
|
if not industry.standardization_logic:
|
|
print("CRITICAL: Standardization logic is empty/null! That explains the null result.")
|
|
return
|
|
|
|
# Initialize Service to test the exact method
|
|
service = ClassificationService()
|
|
test_value = 352.0
|
|
|
|
print(f"\nTesting calculation with value: {test_value}")
|
|
|
|
try:
|
|
result = service._parse_standardization_logic(industry.standardization_logic, test_value)
|
|
print(f"Result: {result}")
|
|
except Exception as e:
|
|
print(f"Exception during parsing: {e}")
|
|
|
|
if __name__ == "__main__":
|
|
test_logic()
|