Skip to content

Commit 730e664

Browse files
authored
Merge pull request #54 from rmusser01/dev
Sync
2 parents ea76b0e + cc01b54 commit 730e664

File tree

9 files changed

+499
-148
lines changed

9 files changed

+499
-148
lines changed

README.md

Lines changed: 189 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -18,38 +18,143 @@ Current status: Working/In-Progress
1818
- If you are in the root directory of the repository: `python3 -m tldw_chatbook.app`
1919

2020
## Current Features
21-
- Connect to multiple LLM providers (Local: Llama.cpp, Ollama, Kobold.cpp, vLLM, Aphrodite, Custom-OpenAI API endpoint ; Commercial: OpenAI, Anthropic, Cohere, Deepseek, Google, Groq, Mistral, OpenRouter)
22-
- Character Card functionality (Persona/Character/Chatbot support + ingestion of character cards into the DB)
23-
- Conversation history management
24-
- Notes and keyword management
25-
- Textual TUI interface
21+
- Textual TUI interface
2622
- Configuration via `config.toml`
2723
- Default `config.toml` stored at `~/.config/tldw_cli/config.toml`
2824
- Default user DB stored at `~/.share/tldw_cli/`
2925
- Environment variable support for API keys
30-
- Inspiration from Elia Chat Widgets
3126
- Launch with `python3 -m tldw_chatbook.app` (working on pip packaging)
27+
- Inspiration from [Elia Chat](https://github.com/darrenburns/elia)
28+
29+
<details>
30+
<summary> Chat Features </summary>
31+
32+
- tldw_chatbook's current feature set relating to chat functionality includes:
33+
- Connect to multiple LLM providers
34+
- (Local: Llama.cpp, Ollama, Kobold.cpp, vLLM, Aphrodite, Custom-OpenAI API endpoint
35+
- Commercial: OpenAI, Anthropic, Cohere, Deepseek, Google, Groq, Mistral, OpenRouter)
36+
- Support for 'ranking' conversation replies (Thumbs up/down)
37+
- Character Card functionality
38+
- Persona/Character/Chatbot support
39+
- Ingestion of character cards into the DB
40+
- Searching + Loading + applying character cards to the current conversation
41+
- Support for 'character' chat functionality (e.g., ability to chat with a character, like a chatbot)
42+
- Conversation history management
43+
- Can search conversations by title, keywords, or contents
44+
- Can load conversations from the DB for continuation or editing
45+
- Can edit messages in conversations, or conversations in general (titles/keywords/contents)
46+
- Chat-Specific features, Support for:
47+
- Streaming responses from LLMs
48+
- Re-generating responses
49+
- 'generate a question/answer' functionality
50+
- 'Ephemeral' conversations are default (conversations are not saved to the Database unless explicitly saved)
51+
- Stripping thinking blocks from responses
52+
- Full OpenAI API support for chat completions
53+
- Prompt-Related Features:
54+
- Save prompts to the prompts Database, one at a time or in bulk
55+
- Edit/Clone/Delete prompts in the prompts Database
56+
- Searching for Prompts via Title/Keyword, and then load ingested Prompts into the current conversation
57+
- Support for searchingloading/editing/saving Notes from the Notes Database.
58+
</details>
59+
60+
<details>
61+
<summary> Notes & Media Features </summary>
62+
63+
- Notes
64+
- Create, edit, and delete notes
65+
- Search notes by title, keywords, or contents
66+
- Load notes into the current conversation
67+
- Save notes to the Notes Database
68+
69+
- Media (WIP)
70+
- Full Media DB support
71+
- Ingest media files into the Media DB
72+
- Search media files by title, keywords, or contents
73+
- Load media files into the current conversation
74+
- Save media files to the Media Database via tldw API or local processing
75+
-
76+
</details>
77+
78+
79+
<details>
80+
<summary> Local LLM Inference </summary>
81+
82+
- Local LLM Inference (WIP)
83+
- Support for local LLM inference via llama.cpp, Ollama, Kobold.cpp, Ooba, vLLM, Aphrodite, and Custom user-defined OpenAI API endpoints
84+
- Support for managing a local Ollama instance via HTTP API
85+
- Support for managed local LLM inference via Llama.cpp & Llamafile
86+
- Support for managed local LLM inference via vLLM (e.g., Mistral, Llama 3, etc.)
87+
- Support for managed local LLM inference via mlx-lm
88+
- Support for managed local LLM inference via OnnxRuntime
89+
- Support for downloading models from Hugging Face and other sources
90+
91+
</details>
92+
3293
3394
### Planned Features
34-
- Conversation Forking + History Management thereof (Already implemented, but needs more testing/UI buildout)
35-
- Improved notes and keyword management (Support for syncing notes from a local folder/file - think Obsidian)
36-
- Additional LLM provider support (e.g., more local providers, more commercial providers)
37-
- More robust configuration options (e.g., more environment variable support, more config.toml options)
38-
- Enhanced character chat functionality (e.g., ASCII art for pictures, 'Generate Character' functionality)
39-
- Improved conversation history management (e.g., exporting conversations, better search functionality)
40-
- Support for 'ranking' conversation replies (create your own conversational datasets, e.g., for training or fine-tuning models)
41-
- Workflows - e.g., Ability to create structured workflows, like a task list or a series of steps to follow, with the ability to execute them in order with checkpoints after each step. (Agents?)
42-
- Agentic functionality (e.g., ability to create agents that can perform tasks based on conversation history or notes, think workflow automation with checkpoints)
43-
- First goal will be the groundwork/framework for building it out more, and then for coding, something like Aider?
44-
- Separate from the workflows, which are more like structured task lists or steps to follow. Agentic functionality will be more about creating workflows, but not-fully structured, that adapt based on the 'agents' decisions.
45-
- Mindmap functionality (e.g., ability to create mindmaps from conversation history or notes)
46-
- Support for more media types (e.g., images, audio, video - Ingestion thereof)
47-
- Support for Server Syncing (e.g., ability to sync conversations, notes, characters, Media DB and prompts across devices)
48-
- Support for RAG (Retrieval-Augmented Generation) functionality (e.g., ability to retrieve relevant information from conversations, notes, characters, Media DB and prompts)
49-
- Support for Web Search (e.g., ability to search the web for relevant information based on conversation history or notes)
50-
- Already implemented, but needs more testing/UI buildout
51-
- Support for audio playback + Generation (e.g., ability to play audio files, generate audio from text - longer term goal, has to run outside of the TUI)
52-
- Also Support for image generation and video playback + Generation (e.g., ability to play video files, generate video from text - longer term goal, has to run outside of the TUI)
95+
<details>
96+
<summary> Future Features </summary>
97+
98+
- **General**
99+
- Web Search functionality (e.g., ability to search the web for relevant information based on conversation history or notes or query)
100+
- Additional LLM provider support (e.g., more local providers, more commercial providers)
101+
- More robust configuration options (e.g., more environment variable support, more config.toml options)
102+
103+
- **Chat**
104+
- Conversation Forking + History Management thereof (Already implemented, but needs more testing/UI buildout)
105+
- Enhanced character chat functionality (e.g., ASCII art for pictures, 'Generate Character' functionality, backgrounds)
106+
- Improved conversation history management (e.g., exporting conversations, better search functionality)
107+
108+
- **Notes-related**
109+
- Improved notes and keyword management (Support for syncing notes from a local folder/file - think Obsidian)
110+
111+
- **Media-related**
112+
113+
- **Search Related**
114+
- Improved search functionality (e.g., more robust search options, better search results)
115+
- Support for searching across conversations, notes, characters, and media files
116+
- Support for websearch (code is in place, but needs more testing/UI buildout)
117+
- Support for RAG (Retrieval-Augmented Generation) functionality (e.g., ability to retrieve relevant information from conversations, notes, characters, media files and prompts)
118+
119+
- **Tools & Settings**
120+
- Support for DB backup management/restore
121+
- General settings management (e.g., ability to change application settings, like theme, font size, etc.)
122+
- Support for user preferences (e.g., ability to set user preferences, like default LLM provider, default character, etc.)
123+
- Support for user profiles (e.g., ability to create and manage user profiles, tied into preference sets)
124+
125+
- **LLM Management**
126+
- Cleanup and bugfixes
127+
128+
- **Stats**
129+
- I imagine this page as a dashboard that shows various statistics about the user's conversations, notes, characters, and media files.
130+
- Something fun and lighthearted, but also useful for the user to see how they are using the application.
131+
- This data will not be stored in the DB, but rather generated on-the-fly from the existing data.
132+
- This data will also not be uploaded to any external service, but rather kept local to the user's machine.
133+
- This is not meant for serious analytics, but rather for fun and lighthearted use. (As in it stays local.)
134+
135+
- **Evals**
136+
- Self-explanatory
137+
- Support for evaluating LLMs based on user-defined criteria.
138+
- Support for RAG evals.
139+
- Jailbreaks?
140+
141+
- **Coding**
142+
- Why not, right?
143+
- Build out a take on the agentic coder, will be a longer-term goal, but will be a fun addition.
144+
145+
- **Workflows**
146+
- Workflows - e.g., Ability to create structured workflows, like a task list or a series of steps to follow, with the ability to execute them in order with checkpoints after each step. (Agents?)
147+
- Agentic functionality (e.g., ability to create agents that can perform tasks based on conversation history or notes, think workflow automation with checkpoints)
148+
- First goal will be the groundwork/framework for building it out more, and then for coding, something like Aider?
149+
- Separate from the workflows, which are more like structured task lists or steps to follow. Agentic functionality will be more about creating workflows, but not-fully structured, that adapt based on the 'agents' decisions.
150+
151+
- **Other Features**
152+
- Support for Server Syncing (e.g., ability to sync conversations, notes, characters, Media DB and prompts across devices)
153+
- Support for audio playback + Generation (e.g., ability to play audio files, generate audio from text - longer term goal, has to run outside of the TUI)
154+
- Mindmap functionality (e.g., ability to create mindmaps from conversation history or notes)
155+
156+
</details>
157+
53158
54159
### Getting Started
55160
- **Via pip**
@@ -84,24 +189,66 @@ Current status: Working/In-Progress
84189
- Each database is created on first run if it doesn't already exist.
85190

86191
### Project Structure
192+
<details>
193+
<summary>Here's a brief overview of the main directories in the project:</summary>
87194
88-
Here's a brief overview of the main directories in the project:
89-
90-
* **`tldw_chatbook/`**: Contains the core source code of the application.
91-
* **`app.py`**: Main application entry point.
92-
* **`Screens/`**: Application screens (main views).
93-
* **`Widgets/`**: Reusable TUI components.
94-
* **`UI/`**: More complex UI structures and panels.
95-
* **`Chat/`**: Logic for chat functionalities and LLM interactions.
96-
* **`DB/`**: Database interaction modules.
97-
* **`LLM_Calls/`**: Modules for calling LLM APIs.
98-
* **`Notes/`**: Notes management logic.
99-
* **`Event_Handlers/`**: Application event handling.
100-
* **`Docs/`**: Project documentation (WIP)
101-
* **`Tests/`**: Contains all automated tests.
102-
* **`css/`**: Stylesheets for the Textual TUI.
103-
* **`static/`**: Static assets like images.
104-
* **`Helper_Scripts/`**: Utility scripts for various tasks.
195+
```
196+
└── ./
197+
└── tldw_chatbook
198+
├── assets
199+
│ └── Static Assets
200+
├── Character_Chat
201+
│ └── Libaries relating to character chat functionality/interactions
202+
├── Chat
203+
│ └── Libraries relating to chat functionality/orchestrations
204+
├── Chunking
205+
│ └── Libaries relating to chunking text for LLMs
206+
├── css
207+
│ └── CSS files for the Textual TUI
208+
├── DB
209+
│ └── Core Database Libraries
210+
├── Embeddings
211+
│ └── Embeddings Generation & ChromaDB Libraries
212+
├── Event_Handlers
213+
│ ├── Chat_Events
214+
│ │ └── Handle all chat-related events
215+
│ ├── LLM_Management_Events
216+
│ │ └── Handle all LLM management-related events
217+
│ └── Event Handling for all pages is done here
218+
├── LLM_Calls
219+
│ └── Libraries for calling LLM APIs (Local and Commercial)
220+
├── Local_Inference
221+
│ └── Libraries for managing local inference of LLMs (e.g., Llama.cpp, llamafile, vLLM, etc.)
222+
├── Metrics
223+
│ └── Library for instrumentation/tracking (local) metrics
224+
├── Notes
225+
│ └── Libraries for managing notes interactions and storage
226+
├── Prompt_Management
227+
│ └── Libraries for managing prompts interactions and storage + Prompt Engineering
228+
├── RAG_Search
229+
│ └── Libraries for RAG (Retrieval-Augmented Generation) search functionality
230+
├── Screens
231+
│ └── First attempt at Unifying the screens into a single directory
232+
├── Third_Party
233+
│ └── All third-party libraries that are not part of the main application
234+
├── tldw_api
235+
│ └── Code for interacting with the tldw API (e.g., for media ingestion/processing/web search)
236+
├── TTS
237+
│ └── Libraries for Text-to-Speech functionality
238+
├── UI
239+
│ └── Libraries containing all screens and panels for the Textual TUI
240+
├── Utils
241+
│ └── All utility libraries that are standalone
242+
├── Web_Scraping
243+
│ └── Libraries for web scraping functionality (e.g., for web search, RAG, etc.)
244+
├── Widgets
245+
│ └── Reusable TUI components/widgets
246+
├── app.py - Main application entry point (its big...)
247+
├── config.py - Configuration management library
248+
├── Constants.py - Constants used throughout the application (Some default values, Config file template, CSS template)
249+
└── Logging_Config.py - Logging configuration for the application
250+
```
251+
</details>
105252
106253
### Inspiration
107254
https://github.com/darrenburns/elia

tldw_chatbook/DB/ChaChaNotes_DB.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,6 +1042,61 @@ def close_connection(self):
10421042
if hasattr(self._local, 'conn'):
10431043
self._local.conn = None
10441044

1045+
def backup_database(self, backup_file_path: str) -> bool:
1046+
"""
1047+
Creates a backup of the current database to the specified file path.
1048+
1049+
Args:
1050+
backup_file_path (str): The path to save the backup database file.
1051+
1052+
Returns:
1053+
bool: True if the backup was successful, False otherwise.
1054+
"""
1055+
logger.info(f"Starting database backup from '{self.db_path_str}' to '{backup_file_path}'")
1056+
# src_conn is managed by get_connection and should not be closed by this method directly
1057+
# backup_conn is local to this method and must be closed
1058+
backup_conn: Optional[sqlite3.Connection] = None
1059+
try:
1060+
# Ensure the backup file path is not the same as the source for file-based DBs
1061+
if not self.is_memory_db and self.db_path.resolve() == Path(backup_file_path).resolve():
1062+
logger.error("Backup path cannot be the same as the source database path.")
1063+
raise ValueError("Backup path cannot be the same as the source database path.")
1064+
1065+
src_conn = self.get_connection()
1066+
1067+
# Ensure parent directory for backup_file_path exists
1068+
backup_db_path_obj = Path(backup_file_path)
1069+
backup_db_path_obj.parent.mkdir(parents=True, exist_ok=True)
1070+
1071+
backup_conn = sqlite3.connect(str(backup_db_path_obj)) # Use string path for connect
1072+
1073+
logger.debug(f"Source DB connection: {src_conn}")
1074+
logger.debug(f"Backup DB connection: {backup_conn} to file {str(backup_db_path_obj)}")
1075+
1076+
# Perform the backup
1077+
src_conn.backup(backup_conn, pages=0, progress=None)
1078+
1079+
logger.info(f"Database backup successful from '{self.db_path_str}' to '{str(backup_db_path_obj)}'")
1080+
return True
1081+
except ValueError as ve: # Catch specific ValueError for path mismatch first
1082+
logger.error(f"ValueError during database backup: {ve}", exc_info=True)
1083+
return False
1084+
except sqlite3.Error as e:
1085+
logger.error(f"SQLite error during database backup: {e}", exc_info=True)
1086+
return False
1087+
except Exception as e:
1088+
logger.error(f"Unexpected error during database backup: {e}", exc_info=True)
1089+
return False
1090+
finally:
1091+
if backup_conn:
1092+
try:
1093+
backup_conn.close()
1094+
logger.debug("Closed backup database connection.")
1095+
except sqlite3.Error as e:
1096+
logger.warning(f"Error closing backup database connection: {e}")
1097+
# Source connection (src_conn) is managed by the thread-local mechanism
1098+
# and should not be closed here to allow continued use of the DB instance.
1099+
10451100
# --- Query Execution ---
10461101
def execute_query(self, query: str, params: Optional[Union[tuple, Dict[str, Any]]] = None, *, commit: bool = False,
10471102
script: bool = False) -> sqlite3.Cursor:

0 commit comments

Comments
 (0)