A CLI tool and library for managing and analyzing LLM chats.
Project description
ctk: Conversation Tree Toolkit
ctk (Conversation Tree Toolkit) is a powerful command-line tool designed to manage, analyze, and engage with conversation logs exported from OpenAI's platforms (e.g., ChatGPT). Whether you're looking to filter conversations, perform advanced queries, merge multiple conversation libraries, or leverage Large Language Models (LLMs) for deeper insights, ctk provides a comprehensive suite of tools to streamline your workflow.
Table of Contents
- Features
- Installation
- Configuration
- Usage
- Examples
- Structure of
conversations.json - Notes
- Getting Help
- Contributing
- License
Features
- List Conversations: Display a list of all conversations with selected fields.
- Search with Regex: Filter conversations based on regex patterns applied to specific fields.
- Advanced Queries with JMESPath: Perform complex queries for data retrieval.
- Conversation Details: View detailed information about specific conversations.
- Merge Libraries: Combine multiple conversation libraries using set operations.
- Export Conversations: Export conversations in various formats like JSON, Markdown, or Hugo.
- Interactive Dashboard: Launch a Streamlit-based dashboard for visual exploration.
Installation
Prerequisites
- Python 3.7+
- pip (Python package installer)
Local Development Installation
-
Clone the Repository
git clone https://github.com/queelius/ctk.git cd ctk
-
Create a Virtual Environment (Optional but Recommended)
Using
venv:python3 -m venv ctk-env source ctk-env/bin/activate
Using
conda:conda create --name ctk-env python=3.8 conda activate ctk-env
-
Install Dependencies
pip install -r requirements.txt
-
Make the
ctkCommand AccessibleEnsure that the
ctkscript is executable and added to your PATH. You can achieve this by installing the package or setting up an alias.chmod +x ctk/cli.py ln -s $(pwd)/ctk/cli.py /usr/local/bin/ctk
Alternatively, you can install
ctkas a package if asetup.pyis provided.
End-User Installation Using pypi:
-
Install the Package
pip install conversation_tk
Usage
The ctk tool offers various subcommands to perform different operations on your conversation libraries. The general syntax is:
ctk <command> [options] <arguments>
Available Commands
1. list
Description:
Lists all conversations in the specified library directory.
Usage:
ctk list <libdir> [--indices <indices>] [--fields <fields>]
Arguments:
<libdir>: Path to the conversation library directory.
Options:
--indices: Specify the indices of conversations to list. If omitted, all conversations are listed.--fields: Specify which fields to include in the output (default:title,update_time).
Example:
ctk list ./conversations --fields title update_time model
2. search
Description:
Runs a regex query on the conversations to filter results based on specified patterns.
Usage:
ctk search <libdir> <expression> --fields <fields>
Arguments:
<libdir>: Path to the conversation library directory.<expression>: The regex pattern to search for.
Options:
--fields: One or more JMESPath expressions specifying the fields to apply the regex to (default:title).--json: Output the results in JSON format.
Example:
ctk search ./conversations "C\+\+" --fields title --json
Note: To search for the literal string "C++", ensure you escape the plus signs as shown.
3. jmespath
Description:
Executes a JMESPath query on the conversations for advanced data retrieval.
Usage:
ctk jmespath <libdir> <query>
Arguments:
<libdir>: Path to the conversation library directory.<query>: The JMESPath expression to execute.
Example:
ctk jmespath ./conversations "conversations[?status=='active']"
4. conv
Description:
Prints detailed conversation information based on conversation indices or specific node IDs.
Usage:
ctk conv <libdir> <indices> [--node <node_id>] [--json]
Arguments:
<libdir>: Path to the conversation library directory.<indices>: One or more indices of conversations to display.
Options:
--node: Specify the node ID to indicate the terminal node of a conversation path.--json: Output the conversation in JSON format instead of a formatted table.
Example:
ctk conversation ./conversations 0 1 2 --node node123 --json
5. merge
Description:
Merges multiple ctk libraries into a single library using specified operations.
Usage:
ctk merge <operation> <libdirs> -o <output_dir>
Arguments:
<operation>: Type of merge operation (union,intersection,difference).<libdirs>: List of library directories to merge.
Options:
-o, --output: Specify the output library directory.
Example:
ctk merge union ./lib1 ./lib2 -o ./merged_lib
6. export
Description:
Exports conversations from the library in specified formats.
Usage:
ctk export <libdir> <indices> [--format <format>]
Arguments:
<libdir>: Path to the conversation library directory.<indices>: One or more indices of conversations to export. If omitted, all conversations are exported.
Options:
--format: Output format (json,markdown,hugo). Default isjson.
Example:
ctk export ./conversations 0 1 --format markdown
Examples
-
Listing All Conversations:
ctk list ./conversations
-
Listing Specific Fields:
ctk list ./conversations --fields title update_time model
-
Filtering Conversations with Regex Search:
ctk search ./conversations "C\+\+" --fields title --json
-
Running a JMESPath Query:
ctk jmespath ./conversations "conversations[?status=='active']"
-
Merging Two Libraries with Union Operation:
ctk merge union ./lib1 ./lib2 -o ./merged_lib
-
Exporting Conversations to Markdown:
ctk export ./conversations 0 1 --format markdown
Structure of conversations.json
The ctk library stores conversation data in a JSON file named conversations.json located within your specified library directory (libdir). This file contains structured data representing ChatGPT chat sessions, organized as conversation trees.
Example conversations.json:
[
{
"id": "conversation_1",
"title": "Project Discussion",
"create_time": 1633072800,
"update_time": 1633076400,
"default_model_slug": "gpt-3.5-turbo",
"safe_urls": ["https://example.com"],
"mapping": {
"node_1": {
"text": "Hello, how can I assist you today?",
"payload": {
"message": {
"content": {
"content_type": "text",
"parts": ["Hello, how can I assist you today?"]
},
"author": {
"role": "assistant",
"name": "ChatGPT"
},
"create_time": 1633072800
}
}
},
"node_2": {
"text": "I need help with my project.",
"payload": {
"message": {
"content": {
"content_type": "text",
"parts": ["I need help with my project."]
},
"author": {
"role": "user",
"name": "Alice"
},
"create_time": 1633072860
}
}
}
},
"current_node": "node_2"
}
]
This is a simplified example. The actual structure may vary based on your specific data.
Notes
-
Library Directory (
libdir): Ensure that the specified library directory exists and contains a validconversations.jsonfile before performing operations. -
Indices: Conversation indices start at
0. Use thelistcommand to view available indices before performing operations on specific conversations. -
Regex Patterns: When using regex patterns, escape special characters as needed. For example, to search for "C++", use
C\+\+. -
Conflict Resolution in Merges: When merging libraries, duplicate conversation IDs can be handled using strategies like
skip,overwrite-old, orerrorbased on your requirements. -
JSON Output: Utilize the
--jsonflag in commands likelistandconversationfor machine-readable output, which is useful for further processing or integration with other tools. -
Error Handling: The tool provides informative error messages. Ensure to read them carefully to troubleshoot issues related to missing files, incorrect indices, or invalid configurations.
-
Performance: For large libraries, some operations might take longer. Consider optimizing your queries and using efficient patterns to enhance performance.
Getting Help
For more information on using the ctk tool, access the help documentation for each command using the --help flag. For example:
ctk list --help
This command will display detailed information about the list command, including its usage, arguments, and options.
Contributing
Contributions are welcome! If you'd like to contribute to the ctk project, please follow these steps:
-
Fork the Repository
Click the "Fork" button at the top right of the repository page to create your own fork.
-
Clone Your Fork
git clone https://github.com/queelius/ctk.git cd ctk
-
Create a New Branch
git checkout -b feature/YourFeatureName
-
Make Your Changes
Implement your feature or bug fix.
-
Commit Your Changes
git commit -m "Add feature: YourFeatureName"
-
Push to Your Fork
git push origin feature/YourFeatureName
-
Create a Pull Request
Navigate to the original repository and click the "New Pull Request" button. Provide a clear description of your changes.
Please ensure that your contributions adhere to the project's coding standards and include appropriate tests where applicable.
License
This project is licensed under the MIT License.
Contact
For questions, suggestions, or support, please open an issue on the GitHub repository or contact the maintainer at lex@metafunctor.com.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file conversation_tk-0.6.1.tar.gz.
File metadata
- Download URL: conversation_tk-0.6.1.tar.gz
- Upload date:
- Size: 20.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
904c6b45cf3c548a014b35bb3828e813b7c265dd67e14efe88675d909f9a3951
|
|
| MD5 |
a5e6a6e63995fd04086a028c7120f113
|
|
| BLAKE2b-256 |
76a596fbc10c9d0fa2998b5e4cb7658caa8dd677f3bbdf1c03bd175676d135e7
|
File details
Details for the file conversation_tk-0.6.1-py3-none-any.whl.
File metadata
- Download URL: conversation_tk-0.6.1-py3-none-any.whl
- Upload date:
- Size: 23.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1d00ecdc1d388abb86f0a92d1b012048bc3725752e0da2c9897665231450e474
|
|
| MD5 |
a794b0a4ffb37b6ee87ad7f5b0347c21
|
|
| BLAKE2b-256 |
563af127e84f094ddce5ea4c44c8dc0c3fcd40359ea04be65b3df0b462edbaa7
|