Implement optimized database schema and AI prompt - removed title field, summary to fact, removed financial_impact and main_points
This commit is contained in:
parent
9344a69636
commit
332f49eeee
@ -41,29 +41,22 @@ class AIEndpointClient:
|
||||
|
||||
def extract_facts(self, text_content: str, prompt: str, model: str = "gpt-oss") -> Dict[str, Any]:
|
||||
"""Extract facts from text using AI"""
|
||||
# Default prompt from requirements
|
||||
# Default prompt from requirements - optimized for facts extraction
|
||||
default_prompt = """Extract key facts from the following article in structured JSON format.
|
||||
Return only valid JSON without any additional text.
|
||||
|
||||
Article Title: {title}
|
||||
Article Content: {article_content[:3000]}...
|
||||
|
||||
Extract the following information:
|
||||
1. Main topic/subject
|
||||
2. Key entities (companies, people, locations, organizations)
|
||||
3. Financial impact or implications
|
||||
4. Key dates or time periods mentioned
|
||||
5. Summary of main points
|
||||
1. Key entities (companies, people, locations, organizations)
|
||||
2. Key dates or time periods mentioned
|
||||
3. Main facts from the article
|
||||
|
||||
Format the response as a JSON object with these fields:
|
||||
{
|
||||
"title": "{title}",
|
||||
"summary": "brief summary",
|
||||
"main_topic": "main topic",
|
||||
"fact": "main fact extracted from the article",
|
||||
"key_entities": ["entity1", "entity2"],
|
||||
"financial_impact": "positive/negative/neutral",
|
||||
"key_dates": ["date1", "date2"],
|
||||
"main_points": ["point1", "point2", "point3"]
|
||||
"key_dates": ["date1", "date2"]
|
||||
}"""
|
||||
|
||||
# Use provided prompt or default
|
||||
|
||||
@ -29,13 +29,9 @@ class DatabaseManager:
|
||||
CREATE TABLE IF NOT EXISTS facts (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
table_name TEXT NOT NULL,
|
||||
title TEXT,
|
||||
summary TEXT,
|
||||
main_topic TEXT,
|
||||
fact TEXT,
|
||||
key_entities TEXT,
|
||||
financial_impact TEXT,
|
||||
key_dates TEXT,
|
||||
main_points TEXT,
|
||||
file_path TEXT,
|
||||
extracted_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
processed BOOLEAN DEFAULT FALSE
|
||||
@ -125,22 +121,16 @@ class DatabaseManager:
|
||||
# Convert lists to JSON strings for storage
|
||||
key_entities = str(fact_data.get('key_entities', []))
|
||||
key_dates = str(fact_data.get('key_dates', []))
|
||||
main_points = str(fact_data.get('main_points', []))
|
||||
|
||||
cursor.execute('''
|
||||
INSERT INTO facts (
|
||||
table_name, title, summary, main_topic, key_entities,
|
||||
financial_impact, key_dates, main_points, file_path
|
||||
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
table_name, fact, key_entities, key_dates, file_path
|
||||
) VALUES (?, ?, ?, ?, ?)
|
||||
''', (
|
||||
table_name,
|
||||
fact_data.get('title'),
|
||||
fact_data.get('summary'),
|
||||
fact_data.get('main_topic'),
|
||||
fact_data.get('fact'),
|
||||
key_entities,
|
||||
fact_data.get('financial_impact'),
|
||||
key_dates,
|
||||
main_points,
|
||||
fact_data.get('file_path')
|
||||
))
|
||||
|
||||
@ -166,8 +156,7 @@ class DatabaseManager:
|
||||
with self.get_connection() as conn:
|
||||
cursor = conn.cursor()
|
||||
cursor.execute('''
|
||||
SELECT id, table_name, title, summary, main_topic, key_entities,
|
||||
financial_impact, key_dates, main_points, file_path, extracted_at
|
||||
SELECT id, table_name, fact, key_entities, key_dates, file_path, extracted_at
|
||||
FROM facts
|
||||
WHERE table_name = ?
|
||||
ORDER BY extracted_at DESC
|
||||
@ -185,8 +174,6 @@ class DatabaseManager:
|
||||
fact['key_entities'] = eval(fact['key_entities'])
|
||||
if fact['key_dates']:
|
||||
fact['key_dates'] = eval(fact['key_dates'])
|
||||
if fact['main_points']:
|
||||
fact['main_points'] = eval(fact['main_points'])
|
||||
facts.append(fact)
|
||||
|
||||
return facts
|
||||
@ -196,8 +183,7 @@ class DatabaseManager:
|
||||
with self.get_connection() as conn:
|
||||
cursor = conn.cursor()
|
||||
cursor.execute('''
|
||||
SELECT id, table_name, title, summary, main_topic, key_entities,
|
||||
financial_impact, key_dates, main_points, file_path, extracted_at
|
||||
SELECT id, table_name, fact, key_entities, key_dates, file_path, extracted_at
|
||||
FROM facts
|
||||
WHERE id = ?
|
||||
''', (fact_id,))
|
||||
@ -211,8 +197,6 @@ class DatabaseManager:
|
||||
fact['key_entities'] = eval(fact['key_entities'])
|
||||
if fact['key_dates']:
|
||||
fact['key_dates'] = eval(fact['key_dates'])
|
||||
if fact['main_points']:
|
||||
fact['main_points'] = eval(fact['main_points'])
|
||||
return fact
|
||||
return None
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user