Giter Club home page Giter Club logo

diehard073055 / rust-chatgpt-cli Goto Github PK

View Code? Open in Web Editor NEW
7.0 5.0 1.0 5.08 MB

Rust ChatGPT CLI is a user-friendly terminal interface for OpenAI's GPT chatbot. Start conversations, manage ongoing chats, and send text from files to the chatbot with simple commands. Seamlessly integrate GPT-based AI into your command-line workflow.

License: MIT License

Rust 93.85% Shell 6.15%
chatgpt openai openai-api rust rust-cli rust-client rust-lang chatgpt-app chatgpt-bot chatgpt-cli chatgpt-client-rust command-line

rust-chatgpt-cli's Introduction

Rust ChatGPT CLI

wakatime

In use

rust-chatgpt-cli

rust-chatgpt-cli is a command-line interface (CLI) application that allows you to interact with OpenAI's ChatGPT API. You can start new conversations, list and delete existing ones, and process chatbot prompts.

Usage Instructions

Prerequisites

  • Rust installed on your system
  • OpenAI API Key

Getting Started

Build and Run

  1. Clone this repository:
git clone https://github.com/yourusername/rust-chatgpt-cli.git
  1. Set your OpenAI API key as an environment variable:
export OPENAI_KEY=your_openai_key
  1. Navigate to the project directory:
cd rust-chatgpt-cli
  1. Build the project:
cargo build --release
  1. Run the application:
./target/release/rust-chatgpt-cli [FLAGS] [OPTIONS]

Flags and Options

  • -n, --new-conversation: Start a new conversation
  • -l, --list: List all conversations
  • -d, --del INDEX: Delete a conversation by its index
  • prompt: Enter your prompt (can be a single or multiple words)

Examples

All the features with (๐Ÿšง) are under still under construction.

  1. Start a new conversation (๐Ÿšง):
./target/release/rust-chatgpt-cli -n What is the meaning of life?
  1. List all conversations (๐Ÿšง):
./target/release/rust-chatgpt-cli -l
  1. Delete a conversation by index (๐Ÿšง):
./target/release/rust-chatgpt-cli -d 2
  1. Provide a prompt:
./target/release/rust-chatgpt-cli Tell me a joke.
  1. Use stdin for the prompt:
echo "What is your favorite color?" | ./target/release/rust-chatgpt-cli
  1. Use a file to build your prompt, then pipe it to chatgpt.
$ cat > prompt
You are a computer science lecturer at a university.
You excel at explaining programming concepts to student.

Could you please explain what a hashtable is?
^C
$ cat prompt | ./target/release/rust-chatgpt-cli

Note: (๐Ÿšง) You can combine the -n flag with a prompt to start a new conversation with the given prompt.

Contributing

Please feel free to open an issue or submit a pull request with your contributions.

License

This project is licensed under the MIT License - see the LICENSE file for details.

rust-chatgpt-cli's People

Contributors

diehard073055 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

estkae

rust-chatgpt-cli's Issues

Generate unique and descriptive names for conversation files

Description:

Implement a method to generate unique and descriptive names for conversation files, which will be used to save the conversations. Ensure that the generated names are human-readable and convey meaningful information about the conversation, such as the date and time the conversation was started.

Implement file input support

Enable users to send the contents of a file to the ChatGPT API using the cat file_with_contents | chatgpt new command.

Add error handling and user input validation

Improve error handling by incorporating the error types provided by the chatgpt_rs library. Validate user input, ensuring that it meets the requirements for interacting with the OpenAI API.

Improve output handling in rust-chatgpt-cli

Currently, the CLI app only prints out the debug messages. We should enhance the output processing to provide a more user-friendly. This includes parsing the response and presenting only the message content.

Implement conversation persistence and management

Implement conversation persistence using the chatgpt_rs library's built-in support for saving and loading conversation history. Allow users to manage multiple conversations, switch between them, and delete them as needed.

UX Improvement: Simplify Conversation Management

Description:

I would like to propose a change to the current user experience of the rust-chatgpt-cli to make conversation management more user-friendly. The current design requires users to provide a conversation index each time they want to continue an ongoing conversation, which can be cumbersome.

Proposed Changes:

  1. chatgpt new will behave mostly the same, to create a new conversation instance and set it as the currently selected conversation:
chatgpt new "question to ask chatgpt"
cat file | chatgpt new
  1. Add a chatgpt status command to show the currently selected conversation, the number of ongoing conversations, total tokens used this month, and accumulated cost for the month:
chatgpt status
  1. When a user asks a question with chatgpt, assume they want to continue with the currently selected conversation by default. If there's no conversation selected, create a new one:
chatgpt "ask a question"
  1. chatgpt list dose not change, lists all conversations, allowing users to select the desired conversation:
chatgpt list
  1. Add a chatgpt del command to delete a specific conversation:
chatgpt del <conversation index>

I believe these changes will simplify conversation management and make the rust-chatgpt-cli more user-friendly. Please consider implementing these enhancements. Thank you!

Refactor basic_query to support testing with a mock client

Description

To improve the testability of the basic_query function in the ChatGPT module, we need to refactor it to accept a ChatGPTClient object. This will enable the use of a mock client during testing, while the actual client will be used during normal usage.

Tasks

  1. Create a MockChatGPTClient struct that implements the ChatGPTClient trait. The mock client should return pre-defined responses for testing purposes instead of making actual API calls.

  2. Update the basic_query function signature to accept a ChatGPTClient object as a parameter.

  3. Update the test module to use the MockChatGPTClient for testing the basic_query function.

  4. Update the main.rs file to pass the default client when calling the basic_query function.

Acceptance Criteria

  • The basic_query function accepts a ChatGPTClient object as a parameter.
  • A MockChatGPTClient struct is implemented for testing purposes.
  • A test for basic_query function is added that uses the MockChatGPTClient.
  • The main.rs file is updated to pass the default client when calling basic_query.

Utilize chatgpt_rs library to complete the ChatGPT CLI application

Description

The goal of this issue is to use the existing chatgpt_rs library to complete the ChatGPT CLI application. The chatgpt_rs library provides a Rust implementation for interacting with the ChatGPT API.

The following tasks should be completed:

  • 1. Add the chatgpt_rs library as a dependency in the Cargo.toml file.
  • 2. Study the chatgpt_rs library's usage and API, including authentication, sending messages, and receiving responses.
  • 3. Implement the core functionality of the ChatGPT CLI application using the chatgpt_rs library:
    • Start a new conversation.
    • List all available conversations.
    • Continue an ongoing conversation.
    • Delete an ongoing conversation.
  • 4. Handle errors and edge cases gracefully.
  • 5. Test the application thoroughly to ensure it works as expected.

Once these tasks are completed, the ChatGPT CLI application should be able to interact with the ChatGPT API using the chatgpt_rs library.

Research existing ChatGPT API implementations in Rust and design the application

Description

The goal of this issue is to research existing ChatGPT API implementations in Rust, such as chatgpt_rs, and use the insights gained to design the application.

Here's the class diagram for the chatgpt_rs implementation:

classDiagram
    class ChatGPT {
        +new(api_key: String) -> Result<ChatGPT>
        +new_with_config(api_key: String, config: ModelConfiguration) -> Result<ChatGPT>
        -client: reqwest::Client
        -config: ModelConfiguration
    }

    class ModelConfiguration {
        +api_url: Url
        +engine: ChatGPTEngine
        +temperature: f32
        +max_tokens: Option<u32>
    }

    class ModelConfigurationBuilder {
        +api_url(url: &str) -> &mut Self
        +engine(engine: ChatGPTEngine) -> &mut Self
        +temperature(temp: f32) -> &mut Self
        +max_tokens(tokens: u32) -> &mut Self
        +build() -> Result<ModelConfiguration>
    }

    class Conversation {
        +client: ChatGPT
        +history: Vec<ChatMessage>
        +new(client: ChatGPT, first_message: String) -> Self
        +new_with_history(client: ChatGPT, history: Vec<ChatMessage>) -> Self
        +rollback() -> Option<ChatMessage>
        +send_message<S: Into<String>>(message: S) -> crate::Result<CompletionResponse>
        +send_message_streaming<S: Into<String>>(message: S) -> crate::Result<impl Stream<Item = ResponseChunk>>
        +save_history_json<P: AsRef<Path>>(to: P) -> crate::Result<()>
        +save_history_postcard<P: AsRef<Path>>(to: P) -> crate::Result<()>
    }

    class ChatMessage {
        +role: Role
        +content: String
        +from_response_chunks(chunks: Vec<ResponseChunk>) -> Vec<Self>
    }

    class CompletionResponse {
        +message_choices: Vec<MessageChoice>
        +tokens_usage: TokenUsage
    }

    class MessageChoice {
        +message: ChatMessage
    }

    class TokenUsage {
        +prompt_tokens: u32
        +completion_tokens: u32
        +total_tokens: u32
    }

    class Error {
        // Enum variants and their corresponding error messages
    }

    ChatGPT -- ModelConfiguration : has one >
    ChatGPT -- Conversation : creates >
    ChatGPT -- ChatMessage : interacts with >
    ChatGPT -- CompletionResponse : interacts with >
    ChatGPT -- Error : may return >
    ModelConfiguration -- ModelConfigurationBuilder : creates >
    Conversation -- ChatMessage : has many >
    CompletionResponse -- MessageChoice : has many >
    MessageChoice -- ChatMessage : has one >
    TokenUsage -- CompletionResponse : has one >

Please study these implementations, and use the information gathered to come up with a design for the application.

Provide example Bash scripts for automation tasks

To demonstrate the versatility of the rust-chatgpt-cli, we should provide example Bash scripts that automate various tasks using the CLI app. These tasks can include:

  • Generating Git commit messages
  • Creating Git PR descriptions
  • Requesting code reviews from ChatGPT

These example scripts will serve as a starting point for users who want to leverage the power of ChatGPT in their development workflows.

Read a directory containing conversation files and sort them

Description:

Develop a functionality to read a directory containing conversation files, parse the files, and sort the conversations based on certain criteria (e.g., date created, conversation length, etc.). This feature will allow users to organize and manage their conversations more effectively.

Testing and documentation

Test the application thoroughly, ensuring that all features work as expected with the integrated chatgpt_rs library. Update the README and any relevant documentation to reflect the new implementation.

Add the ability to create a new conversation and update the file

Description:

Add the ability to create a new conversation. For every prompt input, the application should read the conversation file, append the new message to the conversation list, and save the updated file. This feature will enable users to maintain ongoing conversations and easily update conversation files with new inputs and responses.

Implement a feature to list all available conversations

Description:

Implement a feature to list all available conversations from the conversation directory, providing an overview of saved conversations. This functionality will help users to easily navigate and manage their saved conversations, as well as identify any conversations they may want to delete or revisit.

Set up GitHub Actions for releasing the Rust binary

To make the rust-chatgpt-cli more accessible to users, we should set up GitHub Actions to automatically build and release the Rust binary for multiple platforms. The target platforms include macOS Apple Silicon and Intel, Windows amd64, and Linux amd64. This will allow users to easily download and use the CLI app on their preferred platform.

Set up GitHub Actions to run tests on every PR

Description

To ensure the quality and stability of the codebase, we should set up GitHub Actions to automatically run tests whenever a new pull request is opened. This will help us identify and fix any issues before they get merged into the main branch.

Tasks

  1. Create a new workflow file (e.g., .github/workflows/run-tests.yml) in the project's repository.
  2. Configure the workflow to trigger on pull requests targeting the main branch.
  3. Define the jobs and steps necessary to check out the repository, set up the Rust environment, and run the tests using cargo test.
  4. Ensure that the workflow status is reported back to the pull request so that it's clear whether the tests have passed or failed.

Acceptance Criteria

  • GitHub Actions workflow is created and configured to run tests on every PR targeting the main branch.
  • The workflow checks out the repository, sets up the Rust environment, and runs the tests using cargo test.
  • The workflow status (success or failure) is reported back to the pull request.

Refinements for rust-chatgpt-cli to Ensure Immediate Usability in its Current State

This master issue proposes a series of enhancements for the rust-chatgpt-cli project.

  1. Improve the CLI app to process and display the response from the ChatGPT API more effectively.
  2. Set up GitHub Actions for releasing the Rust binary targeting macOS Apple Silicon and Intel, Windows amd64, and Linux amd64.
  3. Provide example scripts in Bash to automate tasks such as generating Git commits, Git PR descriptions, and code reviews using ChatGPT.

Please see the individual issues below for more details:

Implement chatgpt_rs integration in the application

Integrate the chatgpt_rs library into the application, replacing the existing API calls and interaction logic with the chatgpt_rs library functions. Update the command-line interface to use the chatgpt_rs library for communication with the OpenAI API.

Integrate chatgpt_rs and complete the application

Integrate the chatgpt_rs library into the application and complete its development. This involves the following tasks:

  • #12 Add chatgpt_rs library as a dependency
  • #13 Implement chatgpt_rs integration in the application
  • #14 Add error handling and user input validation
  • #15 Implement conversation persistence and management
  • #16 Testing and documentation

Complete each task and close the corresponding issue. Once all tasks are completed, close this issue.

Handling Conversations Feature ๐Ÿšง

Description:

This issue covers the implementation of a set of features to handle conversations in the rust-chatgpt-cli. The following functionalities will be added to manage conversations:

  1. Generate names and filenames: Implement a method to generate unique and descriptive names for conversation files, which will be used to save the conversations.

  2. Read and sort conversations: Develop a functionality to read a directory containing conversation files, parse the files, and sort the conversations based on certain criteria (e.g., date created, conversation length, etc.).

  3. Create a new conversation: Add the ability to create a new conversation. For every prompt input, the application should read the conversation file, append the new message to the conversation list, and save the updated file.

  4. List conversations: Implement a feature to list all available conversations from the conversation directory, providing an overview of saved conversations.

  5. Delete conversations: Add a functionality to delete conversations from the conversation directory, allowing users to manage their conversation storage.

The individual issues:

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.