|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import json |
|
import logging |
|
import tempfile |
|
from typing import List, Tuple, IO, Union |
|
|
|
|
|
from App_Function_Libraries.DB.DB_Manager import db, search_db, DatabaseError, get_media_content |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def save_chat_history(history: List[Tuple[str, str]]) -> str: |
|
|
|
with tempfile.NamedTemporaryFile(mode='w', delete=False, suffix='.json') as temp_file: |
|
json.dump(history, temp_file) |
|
return temp_file.name |
|
|
|
|
|
def load_chat_history(file: IO[str]) -> List[Tuple[str, str]]: |
|
|
|
return json.load(file) |
|
|
|
|
|
def search_database(query: str) -> List[Tuple[int, str]]: |
|
|
|
results = search_db(query, ["title", "content"], "", page=1, results_per_page=10) |
|
return [(result['id'], result['title']) for result in results] |
|
|
|
|
|
def get_existing_files() -> List[Tuple[int, str]]: |
|
|
|
with db.get_connection() as conn: |
|
cursor = conn.cursor() |
|
cursor.execute("SELECT id, title FROM Media ORDER BY title") |
|
return cursor.fetchall() |
|
|
|
|
|
|
|
|
|
|
|
|