Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dependencies fix #337

Merged
merged 6 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion AMD_requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ matplotlib==3.8.4
mdurl==0.1.2
mpmath==1.3.0
mutagen==1.47.0
networkx==3.3
numpy==1.26.4
onnxruntime==1.17.3
openai
Expand Down
39 changes: 28 additions & 11 deletions App_Function_Libraries/DB/Character_Chat_DB.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,12 +471,13 @@ def get_character_chat_by_id(chat_id: int) -> Optional[Dict]:
return None


def search_character_chats(query: str) -> Tuple[List[Dict], str]:
def search_character_chats(query: str, character_id: Optional[int] = None) -> Tuple[List[Dict], str]:
"""
Search for character chats using FTS5.
Search for character chats using FTS5, optionally filtered by character_id.

Args:
query (str): The search query.
character_id (Optional[int]): The ID of the character to filter chats by.

Returns:
Tuple[List[Dict], str]: A list of matching chats and a status message.
Expand All @@ -487,18 +488,34 @@ def search_character_chats(query: str) -> Tuple[List[Dict], str]:
conn = sqlite3.connect(chat_DB_PATH)
cursor = conn.cursor()
try:
# Use parameterized queries to prevent SQL injection
cursor.execute("""
SELECT CharacterChats.id, CharacterChats.conversation_name, CharacterChats.chat_history
FROM CharacterChats_fts
JOIN CharacterChats ON CharacterChats_fts.rowid = CharacterChats.id
WHERE CharacterChats_fts MATCH ?
ORDER BY rank
""", (query,))
if character_id is not None:
# Search with character_id filter
cursor.execute("""
SELECT CharacterChats.id, CharacterChats.conversation_name, CharacterChats.chat_history
FROM CharacterChats_fts
JOIN CharacterChats ON CharacterChats_fts.rowid = CharacterChats.id
WHERE CharacterChats_fts MATCH ? AND CharacterChats.character_id = ?
ORDER BY rank
""", (query, character_id))
else:
# Search without character_id filter
cursor.execute("""
SELECT CharacterChats.id, CharacterChats.conversation_name, CharacterChats.chat_history
FROM CharacterChats_fts
JOIN CharacterChats ON CharacterChats_fts.rowid = CharacterChats.id
WHERE CharacterChats_fts MATCH ?
ORDER BY rank
""", (query,))

rows = cursor.fetchall()
columns = [description[0] for description in cursor.description]
results = [dict(zip(columns, row)) for row in rows]
status_message = f"Found {len(results)} chat(s) matching '{query}'."

if character_id is not None:
status_message = f"Found {len(results)} chat(s) matching '{query}' for the selected character."
else:
status_message = f"Found {len(results)} chat(s) matching '{query}' across all characters."

return results, status_message
except Exception as e:
logging.error(f"Error searching chats with FTS5: {e}")
Expand Down
1 change: 0 additions & 1 deletion App_Function_Libraries/Gradio_Related.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#########################################
# Gradio UI Functions Library
# I fucking hate Gradio.
# Yea, fuck Gradio. https://github.com/gradio-app/gradio/pull/8263 & https://github.com/gradio-app/gradio/issues/7968
#
#########################################
#
Expand Down
Loading
Loading