-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfix_titles.py
More file actions
27 lines (23 loc) · 940 Bytes
/
Copy pathfix_titles.py
File metadata and controls
27 lines (23 loc) · 940 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
from backend.database import SessionLocal, text
from sqlalchemy.orm import sessionmaker
def fix_broken_titles():
db = SessionLocal()
try:
# Find titles starting with "Error calling LLM" or "Request timed out"
query = text("SELECT id, title FROM chat_sessions WHERE title LIKE 'Error calling LLM%' OR title LIKE '%Request timed out%'")
params = {}
result = db.execute(query, params).fetchall()
print(f"Found {len(result)} broken titles.")
for row in result:
print(f"Fixing Session {row[0]}: {row[1]}")
update_query = text("UPDATE chat_sessions SET title = 'New Chat' WHERE id = :id")
db.execute(update_query, {'id': row[0]})
db.commit()
print("Done.")
except Exception as e:
print(f"Error: {e}")
db.rollback()
finally:
db.close()
if __name__ == "__main__":
fix_broken_titles()