Carchi is a tool for saving your ChatGPT conversations for backup and personal data analytics. It also enables you to search through your conversations using PostgreSQL's full-text searching features.
Carchi operates in two modes: archive
and server
.
In archive
mode, Carchi imports conversation data from a provided ZIP file into a database. The input data is structured in JSON format based on the data export from the ChatGPT web application.
In server
mode, Carchi starts a web server to provide a user interface for querying and analyzing the saved conversations.
In archive
mode, the program reads the input from a ZIP file provided as a command-line argument. The ZIP file should contain a JSON file named "conversations.json". The input data is parsed into a slice of Conversation
objects, and these objects are inserted into the database.
In server
mode, the program starts a web server to provide an interactive user interface. The user can use this interface to query and analyze the saved conversations.
The program expects the input data to have a specific structure. Here is the definition of the conversation data:
- A
Conversation
has anId
,Title
,CreateTime
,UpdateTime
,Mapping
,ModerationResults
,CurrentNode
, andPluginIds
.
- The
Mapping
field contains a map ofNode
objects. - Each
Node
has anId
, an optionalMessage
, an optionalParent
, and a list ofChildren
node ids.
- A
NodeMessage
has aId
,Author
,CreateTime
,UpdateTime
,Content
,EndTurn
,Weight
,Metadata
andRecipient
.
- The
Content
of aNodeMessage
has aContentType
and a list ofParts
.
When running in archive
mode:
-
The program starts by reading the input from a ZIP file provided as a command-line argument. The ZIP file should contain a JSON file named "conversations.json".
-
The program then parses the input data into a slice of
Conversation
objects. -
A connection to the database is opened.
-
The program starts a database transaction and prepares SQL statements for inserting conversations, nodes, and messages.
-
For each
Conversation
, the program executes the conversation statement to insert a row into the conversation table in the database. -
For each
Node
in theMapping
field of theConversation
, the program executes the node statement to insert a row into the node table. If theNode
has aMessage
, the program also executes the message statement to insert a row into the message table. -
Finally, the transaction is committed to the database.
When running in server
mode, the program starts a web server. The user can use the web interface to search through and analyze the stored conversations.
The program uses custom error types to provide detailed information about any errors that occur during execution. For example, an error might occur when reading the ZIP file, parsing the JSON data, connecting to the database, preparing the SQL statements, executing the SQL statements, or committing the transaction.
Each error is associated with an action, such as "reading zip file" or "executing conversation statement". If an error occurs, the program logs the error and exits.