ChatGPT Shell is a command-line interface for interacting with the ChatGPT API, built with Java, Spring Boot, Spring Shell, and H2 Database. It allows users to send messages, receive AI-generated responses, and manage chat conversations.
- Customizable terminal prompt
 - Spring Shell-based application for an enhanced command-line experience
 - Store and manage chat conversations in a local H2 Database
 
- Java 17
 - Maven (Optional)
 
Before running the application, make sure to set the required configuration values:
openai.api-key: Set this to your OpenAI API key.chat.gpt.model: Set this to the desired GPT model (e.g.,gpt_3_5_turbo).chat.gpt.system-message: Set this to the initial system message for the assistant (optional).spring.datasource.url: Set this to your H2 database URL (default isjdbc:h2:file:${user.home}/.chatgptshell/data/chatgptdb) (optional).spring.datasource.username: Set this to your H2 database username (default ischatgptshell) (optional).spring.datasource.password: Set this to your H2 database password (default ispassword) (optional).
You can set these values in the application.properties file or as environment variables. When setting the system message using an environment variable, make sure to enclose the message in double quotes, like this:
export CHAT_GPT_SYSTEM_MESSAGE="You are ChatGPT, a large language model trained by OpenAI. Answer as concisely as possible."Clone the repository:
git clone https://github.com/shahabkondri/chat-gpt-shell.git
cd chat-gpt-shellTo build the project, run:
./mvnw clean packageTo run the application:
java -jar target/chat-gpt-shell-1.0.5.jarNative builds offer faster startup times, lower memory footprint, and easier distribution. To create a native build, install GraalVM and use it as your JDK. Then, run the following command:
./mvnw clean -Pnative native:compileThis will produce a standalone executable optimized for your platform. Once compiled, you can run the native executable:
./target/chat-gpt-shellAfter starting the application, you will see a terminal prompt:
:> Enter your message and press Enter to send it to the ChatGPT API. The AI-generated response will be displayed in the terminal.
:> tell me a joke.To access other commands, start your input with a colon (':') character, for example :help to display the available commands or :exit to quit the application.
To set or update a system message that helps define the behavior of the ChatGPT assistant, use the :system command followed by the message. For example:
:> :system You are an AI trained to assist with programming questions.The system message is added or updated at the beginning of the messages list to ensure its influence on the assistant's behavior.
To manage conversations, use the :conversation command with the following options:
- Without any options, it displays the current active conversation ID and title.
 - With the 
--alloption, it displays all stored conversations. - With the 
--loadoption followed by aconversation ID, it loads a previous conversation. - With the 
--newoption, it starts a new conversation. - With the 
--deleteoption followed by aconversation ID, it deletes a previous conversation. - With the 
--delete-alloption, it deletes all stored conversation. 
For example:
:> :conversation
:> :conversation --all
:> :conversation --load 1234
:> :conversation --new
:> :conversation --delete 1234
:> :conversation --delete-allThis project is licensed under the MIT License. See the LICENCE file for details.
Feel free to submit issues and enhancement requests on the GitHub issue tracker.