conversation-tk 0.3.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,604 @@
1
+ Metadata-Version: 2.2
2
+ Name: conversation-tk
3
+ Version: 0.3.0
4
+ Summary: A CLI tool and library for managing and analyzing chat logs.
5
+ Author-email: Alex Example <alex@example.com>
6
+ Requires-Python: >=3.7
7
+ Description-Content-Type: text/markdown
8
+ Requires-Dist: jmespath>=1.0.0
9
+ Requires-Dist: streamlit>=1.0.0
10
+
11
+ ```markdown
12
+ # `ctk`: Conversation Tree Toolkit
13
+
14
+ **`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.
15
+
16
+ ## Table of Contents
17
+
18
+ - [Features](#features)
19
+ - [Installation](#installation)
20
+ - [Configuration](#configuration)
21
+ - [Usage](#usage)
22
+ - [Available Commands](#available-commands)
23
+ - [`list`](#1-list)
24
+ - [`search`](#2-search)
25
+ - [`jmespath`](#3-jmespath)
26
+ - [`conversation`](#4-conversation)
27
+ - [`merge`](#5-merge)
28
+ - [`export`](#6-export)
29
+ - [`dash`](#7-dash)
30
+ - [`llm`](#8-llm)
31
+ - [Examples](#examples)
32
+ - [Structure of `conversations.json`](#structure-of-conversationsjson)
33
+ - [Response Format for LLM Queries](#response-format-for-llm-queries)
34
+ - [Notes](#notes)
35
+ - [Getting Help](#getting-help)
36
+ - [Contributing](#contributing)
37
+ - [License](#license)
38
+
39
+ ---
40
+
41
+ ## Features
42
+
43
+ - **List Conversations**: Display a list of all conversations with selected fields.
44
+ - **Search with Regex**: Filter conversations based on regex patterns applied to specific fields.
45
+ - **Advanced Queries with JMESPath**: Perform complex queries for data retrieval.
46
+ - **Conversation Details**: View detailed information about specific conversations.
47
+ - **Merge Libraries**: Combine multiple conversation libraries using set operations.
48
+ - **Export Conversations**: Export conversations in various formats like JSON, Markdown, or Hugo.
49
+ - **Interactive Dashboard**: Launch a Streamlit-based dashboard for visual exploration.
50
+ - **LLM Integration**: Engage with Large Language Models to perform tasks like summarization or analysis on your conversation data.
51
+
52
+ ---
53
+
54
+ ## Installation
55
+
56
+ ### Prerequisites
57
+
58
+ - **Python 3.7+**
59
+ - **pip** (Python package installer)
60
+
61
+ ### Local Development Installation
62
+
63
+ 1. **Clone the Repository**
64
+
65
+ ```bash
66
+ git clone https://github.com/queelius/ctk.git
67
+ cd ctk
68
+ ```
69
+
70
+ 2. **Create a Virtual Environment (Optional but Recommended)**
71
+
72
+ Using `venv`:
73
+
74
+ ```bash
75
+ python3 -m venv ctk-env
76
+ source ctk-env/bin/activate
77
+ ```
78
+
79
+ Using `conda`:
80
+
81
+ ```bash
82
+ conda create --name ctk-env python=3.8
83
+ conda activate ctk-env
84
+ ```
85
+
86
+ 3. **Install Dependencies**
87
+
88
+ ```bash
89
+ pip install -r requirements.txt
90
+ ```
91
+
92
+ 4. **Make the `ctk` Command Accessible**
93
+
94
+ Ensure that the `ctk` script is executable and added to your PATH. You can achieve this by installing the package or setting up an alias.
95
+
96
+ ```bash
97
+ chmod +x ctk/cli.py
98
+ ln -s $(pwd)/ctk/cli.py /usr/local/bin/ctk
99
+ ```
100
+
101
+ *Alternatively, you can install `ctk` as a package if a `setup.py` is provided.*
102
+
103
+ ---
104
+
105
+ ### End-User Installation Using `pypi`:
106
+
107
+ 1. **Install the Package**
108
+
109
+ ```bash
110
+ pip install ctk
111
+ ```
112
+
113
+ ## Configuration
114
+
115
+ Before using the `llm` command, you need to configure the LLM settings.
116
+
117
+ 1. **Create Configuration File**
118
+
119
+ Create a file named `.ctkrc` in your home directory:
120
+
121
+ ```bash
122
+ touch ~/.ctkrc
123
+ ```
124
+
125
+ 2. **Add LLM Configuration**
126
+
127
+ Open `.ctkrc` with your preferred text editor and add the following:
128
+
129
+ ```ini
130
+ [llm]
131
+ endpoint = https://api.openai.com/v1/engines/davinci/completions
132
+ api_key = YOUR_API_KEY
133
+ model = gpt-3.5-turbo
134
+ ```
135
+
136
+ - **endpoint**: The API endpoint for the language model service.
137
+ - **api_key**: Your API key for authenticating with the language model service.
138
+ - **model**: The specific language model to use (e.g., `gpt-3.5-turbo`).
139
+
140
+ **Note:** Replace `YOUR_API_KEY` with your actual API key.
141
+
142
+ ---
143
+
144
+ ## Usage
145
+
146
+ The `ctk` tool offers various subcommands to perform different operations on your conversation libraries. The general syntax is:
147
+
148
+ ```bash
149
+ ctk <command> [options] <arguments>
150
+ ```
151
+
152
+ ### Available Commands
153
+
154
+ #### 1. `list`
155
+
156
+ **Description:**
157
+ Lists all conversations in the specified library directory.
158
+
159
+ **Usage:**
160
+
161
+ ```bash
162
+ ctk list <libdir> [--indices <indices>] [--fields <fields>]
163
+ ```
164
+
165
+ **Arguments:**
166
+ - `<libdir>`: Path to the conversation library directory.
167
+
168
+ **Options:**
169
+ - `--indices`: Specify the indices of conversations to list. If omitted, all conversations are listed.
170
+ - `--fields`: Specify which fields to include in the output (default: `title`, `update_time`).
171
+
172
+ **Example:**
173
+
174
+ ```bash
175
+ ctk list ./conversations --fields title update_time model
176
+ ```
177
+
178
+ ---
179
+
180
+ #### 2. `search`
181
+
182
+ **Description:**
183
+ Runs a regex query on the conversations to filter results based on specified patterns.
184
+
185
+ **Usage:**
186
+
187
+ ```bash
188
+ ctk search <libdir> <expression> --fields <fields>
189
+ ```
190
+
191
+ **Arguments:**
192
+ - `<libdir>`: Path to the conversation library directory.
193
+ - `<expression>`: The regex pattern to search for.
194
+
195
+ **Options:**
196
+ - `--fields`: One or more JMESPath expressions specifying the fields to apply the regex to (default: `title`).
197
+ - `--json`: Output the results in JSON format.
198
+
199
+ **Example:**
200
+
201
+ ```bash
202
+ ctk search ./conversations "C\+\+" --fields title --json
203
+ ```
204
+
205
+ *Note: To search for the literal string "C++", ensure you escape the plus signs as shown.*
206
+
207
+ ---
208
+
209
+ #### 3. `jmespath`
210
+
211
+ **Description:**
212
+ Executes a JMESPath query on the conversations for advanced data retrieval.
213
+
214
+ **Usage:**
215
+
216
+ ```bash
217
+ ctk jmespath <libdir> <query>
218
+ ```
219
+
220
+ **Arguments:**
221
+ - `<libdir>`: Path to the conversation library directory.
222
+ - `<query>`: The JMESPath expression to execute.
223
+
224
+ **Example:**
225
+
226
+ ```bash
227
+ ctk jmespath ./conversations "conversations[?status=='active']"
228
+ ```
229
+
230
+ ---
231
+
232
+ #### 4. `conversation`
233
+
234
+ **Description:**
235
+ Prints detailed conversation information based on conversation indices or specific node IDs.
236
+
237
+ **Usage:**
238
+
239
+ ```bash
240
+ ctk conversation <libdir> <indices> [--node <node_id>] [--json]
241
+ ```
242
+
243
+ **Arguments:**
244
+ - `<libdir>`: Path to the conversation library directory.
245
+ - `<indices>`: One or more indices of conversations to display.
246
+
247
+ **Options:**
248
+ - `--node`: Specify the node ID to indicate the terminal node of a conversation path.
249
+ - `--json`: Output the conversation in JSON format instead of a formatted table.
250
+
251
+ **Example:**
252
+
253
+ ```bash
254
+ ctk conversation ./conversations 0 1 2 --node node123 --json
255
+ ```
256
+
257
+ ---
258
+
259
+ #### 5. `merge`
260
+
261
+ **Description:**
262
+ Merges multiple `ctk` libraries into a single library using specified operations.
263
+
264
+ **Usage:**
265
+
266
+ ```bash
267
+ ctk merge <operation> <libdirs> -o <output_dir>
268
+ ```
269
+
270
+ **Arguments:**
271
+ - `<operation>`: Type of merge operation (`union`, `intersection`, `difference`).
272
+ - `<libdirs>`: List of library directories to merge.
273
+
274
+ **Options:**
275
+ - `-o, --output`: Specify the output library directory.
276
+
277
+ **Example:**
278
+
279
+ ```bash
280
+ ctk merge union ./lib1 ./lib2 -o ./merged_lib
281
+ ```
282
+
283
+ ---
284
+
285
+ #### 6. `export`
286
+
287
+ **Description:**
288
+ Exports conversations from the library in specified formats.
289
+
290
+ **Usage:**
291
+
292
+ ```bash
293
+ ctk export <libdir> <indices> [--format <format>]
294
+ ```
295
+
296
+ **Arguments:**
297
+ - `<libdir>`: Path to the conversation library directory.
298
+ - `<indices>`: One or more indices of conversations to export. If omitted, all conversations are exported.
299
+
300
+ **Options:**
301
+ - `--format`: Output format (`json`, `markdown`, `hugo`). Default is `json`.
302
+
303
+ **Example:**
304
+
305
+ ```bash
306
+ ctk export ./conversations 0 1 --format markdown
307
+ ```
308
+
309
+ ---
310
+
311
+ #### 7. `dash`
312
+
313
+ **Description:**
314
+ Launches a Streamlit-based dashboard for interactive exploration of the conversation library.
315
+
316
+ **Usage:**
317
+
318
+ ```bash
319
+ ctk dash <libdir>
320
+ ```
321
+
322
+ **Arguments:**
323
+ - `<libdir>`: Path to the conversation library directory.
324
+
325
+ **Example:**
326
+
327
+ ```bash
328
+ ctk dash ./conversations
329
+ ```
330
+
331
+ ---
332
+
333
+ #### 8. `llm`
334
+
335
+ **Description:**
336
+ Runs a language model query on the conversation library to perform tasks like summarization, analysis, or generating insights.
337
+
338
+ **Usage:**
339
+
340
+ ```bash
341
+ ctk llm <libdir> <query> [--json]
342
+ ```
343
+
344
+ **Arguments:**
345
+ - `<libdir>`: Path to the conversation library directory.
346
+ - `<query>`: The query or prompt to send to the language model.
347
+
348
+ **Options:**
349
+ - `--json`: Output the results in JSON format.
350
+
351
+ **Example:**
352
+
353
+ ```bash
354
+ ctk llm ./conversations "Provide a summary of conversation 0."
355
+ ```
356
+
357
+ *Note: Ensure that the `.ctkrc` configuration file is properly set up with your LLM API credentials.*
358
+
359
+ ---
360
+
361
+ ## Examples
362
+
363
+ 1. **Listing All Conversations:**
364
+
365
+ ```bash
366
+ ctk list ./conversations
367
+ ```
368
+
369
+ 2. **Listing Specific Fields:**
370
+
371
+ ```bash
372
+ ctk list ./conversations --fields title update_time model
373
+ ```
374
+
375
+ 3. **Filtering Conversations with Regex Search:**
376
+
377
+ ```bash
378
+ ctk search ./conversations "C\+\+" --fields title --json
379
+ ```
380
+
381
+ 4. **Running a JMESPath Query:**
382
+
383
+ ```bash
384
+ ctk jmespath ./conversations "conversations[?status=='active']"
385
+ ```
386
+
387
+ 5. **Merging Two Libraries with Union Operation:**
388
+
389
+ ```bash
390
+ ctk merge union ./lib1 ./lib2 -o ./merged_lib
391
+ ```
392
+
393
+ 6. **Exporting Conversations to Markdown:**
394
+
395
+ ```bash
396
+ ctk export ./conversations 0 1 --format markdown
397
+ ```
398
+
399
+ 7. **Launching the Dashboard:**
400
+
401
+ ```bash
402
+ ctk dash ./conversations
403
+ ```
404
+
405
+ 8. **Running a Language Model Query:**
406
+
407
+ ```bash
408
+ ctk llm ./conversations "Provide a summary of conversation 0."
409
+ ```
410
+
411
+ ---
412
+
413
+ ## Structure of `conversations.json`
414
+
415
+ 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.
416
+
417
+ ### Example `conversations.json`:
418
+
419
+ ```json
420
+ [
421
+ {
422
+ "id": "conversation_1",
423
+ "title": "Project Discussion",
424
+ "create_time": 1633072800,
425
+ "update_time": 1633076400,
426
+ "default_model_slug": "gpt-3.5-turbo",
427
+ "safe_urls": ["https://example.com"],
428
+ "mapping": {
429
+ "node_1": {
430
+ "text": "Hello, how can I assist you today?",
431
+ "payload": {
432
+ "message": {
433
+ "content": {
434
+ "content_type": "text",
435
+ "parts": ["Hello, how can I assist you today?"]
436
+ },
437
+ "author": {
438
+ "role": "assistant",
439
+ "name": "ChatGPT"
440
+ },
441
+ "create_time": 1633072800
442
+ }
443
+ }
444
+ },
445
+ "node_2": {
446
+ "text": "I need help with my project.",
447
+ "payload": {
448
+ "message": {
449
+ "content": {
450
+ "content_type": "text",
451
+ "parts": ["I need help with my project."]
452
+ },
453
+ "author": {
454
+ "role": "user",
455
+ "name": "Alice"
456
+ },
457
+ "create_time": 1633072860
458
+ }
459
+ }
460
+ }
461
+ },
462
+ "current_node": "node_2"
463
+ }
464
+ ]
465
+ ```
466
+
467
+ *This is a simplified example. The actual structure may vary based on your specific data.*
468
+
469
+ ---
470
+
471
+ ## Response Format for LLM Queries
472
+
473
+ When using the `llm` command to interact with a Large Language Model, the expected response format is JSON. This structured format ensures that the `ctk` tool can parse and execute the appropriate commands based on your query.
474
+
475
+ ### General Format:
476
+
477
+ ```json
478
+ {
479
+ "command": "command_name",
480
+ "args": ["<libdir>", "<args>"]
481
+ }
482
+ ```
483
+
484
+ ### Examples
485
+
486
+ **Example 1: Finding Starred Conversations**
487
+
488
+ *Query: "Find conversations that are starred."*
489
+
490
+ **Response:**
491
+
492
+ ```json
493
+ {
494
+ "command": "jmespath",
495
+ "args": ["./conversations", "conversations[?starred]"]
496
+ }
497
+ ```
498
+
499
+ **Example 2: Listing Titles and URLs of Starred Conversations**
500
+
501
+ *Query: "Find conversations that are starred and only show me the title and URL."*
502
+
503
+ **Response:**
504
+
505
+ ```json
506
+ {
507
+ "command": "jmespath",
508
+ "args": ["./conversations", "conversations[?starred].[title, url]"]
509
+ }
510
+ ```
511
+
512
+ ---
513
+
514
+ ## Notes
515
+
516
+ - **Library Directory (`libdir`)**: Ensure that the specified library directory exists and contains a valid `conversations.json` file before performing operations.
517
+
518
+ - **Indices**: Conversation indices start at `0`. Use the `list` command to view available indices before performing operations on specific conversations.
519
+
520
+ - **Regex Patterns**: When using regex patterns, escape special characters as needed. For example, to search for "C++", use `C\+\+`.
521
+
522
+ - **Conflict Resolution in Merges**: When merging libraries, duplicate conversation IDs can be handled using strategies like `skip`, `overwrite-old`, or `error` based on your requirements.
523
+
524
+ - **JSON Output**: Utilize the `--json` flag in commands like `list` and `conversation` for machine-readable output, which is useful for further processing or integration with other tools.
525
+
526
+ - **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.
527
+
528
+ - **Performance**: For large libraries, some operations might take longer. Consider optimizing your queries and using efficient patterns to enhance performance.
529
+
530
+ ---
531
+
532
+ ## Getting Help
533
+
534
+ For more information on using the `ctk` tool, access the help documentation for each command using the `--help` flag. For example:
535
+
536
+ ```bash
537
+ ctk list --help
538
+ ```
539
+
540
+ This command will display detailed information about the `list` command, including its usage, arguments, and options.
541
+
542
+ ---
543
+
544
+ ## Contributing
545
+
546
+ Contributions are welcome! If you'd like to contribute to the `ctk` project, please follow these steps:
547
+
548
+ 1. **Fork the Repository**
549
+
550
+ Click the "Fork" button at the top right of the repository page to create your own fork.
551
+
552
+ 2. **Clone Your Fork**
553
+
554
+ ```bash
555
+ git clone https://github.com/yourusername/ctk.git
556
+ cd ctk
557
+ ```
558
+
559
+ 3. **Create a New Branch**
560
+
561
+ ```bash
562
+ git checkout -b feature/YourFeatureName
563
+ ```
564
+
565
+ 4. **Make Your Changes**
566
+
567
+ Implement your feature or bug fix.
568
+
569
+ 5. **Commit Your Changes**
570
+
571
+ ```bash
572
+ git commit -m "Add feature: YourFeatureName"
573
+ ```
574
+
575
+ 6. **Push to Your Fork**
576
+
577
+ ```bash
578
+ git push origin feature/YourFeatureName
579
+ ```
580
+
581
+ 7. **Create a Pull Request**
582
+
583
+ Navigate to the original repository and click the "New Pull Request" button. Provide a clear description of your changes.
584
+
585
+ **Please ensure that your contributions adhere to the project's coding standards and include appropriate tests where applicable.**
586
+
587
+ ---
588
+
589
+ ## License
590
+
591
+ This project is licensed under the [MIT License](LICENSE).
592
+
593
+ ---
594
+
595
+ ## Acknowledgements
596
+
597
+ - Developed using Python and leveraging powerful libraries like `argparse`, `jmespath`, `rich`, `requests`, `networkx`, and `pyvis`.
598
+ - Inspired by the need to efficiently manage and analyze conversation logs from AI platforms.
599
+
600
+ ---
601
+
602
+ ## Contact
603
+
604
+ For questions, suggestions, or support, please open an issue on the [GitHub repository](https://github.com/queelius/ctk/issues) or contact the maintainer at [your.email@example.com](mailto:lex@metafunctor.com).
@@ -0,0 +1,17 @@
1
+ ctk/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ ctk/cli.py,sha256=Fud4l0WLBLETb2ubaUVxF5yytaQzQQKTztUqcDp2Pl0,17796
3
+ ctk/config.py,sha256=BecBfz249ovY2kiAAfV93aG1p4gKcsxZ8GOD_rtGviA,1023
4
+ ctk/llm.py,sha256=yqbcST7KkMfsNYoO6YsAfdYosR5flbdRKf__V0ulDdQ,1271
5
+ ctk/merge.py,sha256=tdqwEDcZ5wB23IYf3Vm0BiUfWC9BlwPcdlW9qH9U580,4152
6
+ ctk/utils.py,sha256=ltlGAXk2KoXahEnR863Jj0-FMz2NJhQVT9yLqv1nb20,11432
7
+ ctk/vis.py,sha256=602bOW_rE6W7Zw_VngWrVG6RhwQJzmjDjFMfUZyEfeM,4827
8
+ ctk/streamlit/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
9
+ ctk/streamlit/app.py,sha256=XCcZLHjJ-3EVkn07v37OGpTuHv1L3R9F56kmqmr_Txs,4106
10
+ ctk/streamlit/display.py,sha256=cf_ChK8If_I4OyWuGUFdJsjgTeB1ylA8c5gbond3gMw,8504
11
+ ctk/streamlit/filters.py,sha256=5vwHWkXGlxpMFwloZlUN6IpYk-JPBdYR7xZIRWOcK2Y,6736
12
+ ctk/streamlit/utils.py,sha256=28XmNnUssTcnScGFKL86KEOykOZZDk0C4oEPM95nI3w,2073
13
+ conversation_tk-0.3.0.dist-info/METADATA,sha256=HdYVfdw5H5jQS-cYpo2XzwtvmJ7BfgbYzoi5KBTyDxg,14828
14
+ conversation_tk-0.3.0.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
15
+ conversation_tk-0.3.0.dist-info/entry_points.txt,sha256=q_qod5rMQgSmIdlRvUZpPvb53EgnGm_RoHQofLaFsZc,37
16
+ conversation_tk-0.3.0.dist-info/top_level.txt,sha256=wvEh92Wdfnd_oJqtSJTVuTFVMvkZmA550QiIG5k3oac,4
17
+ conversation_tk-0.3.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (75.8.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ ctk = ctk.cli:main
@@ -0,0 +1 @@
1
+ ctk
ctk/__init__.py ADDED
File without changes