Thanks to visit codestin.com
Credit goes to github.com

Skip to content

RingCanary/mistral-chat-cli-rs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Mistral CLI

Welcome to Mistral CLI, a powerful command-line interface (CLI) tool built in Rust. This application allows you to interact with the Mistral and Codestral APIs to chat with AI, test API connections, and analyze code snippets—all from your terminal.


✨ Features

  • AI-Powered Chat: Send prompts to Mistral or Codestral APIs and receive streamed responses in real-time.
  • API Health Check: Quickly test your connection to the Mistral and Codestral APIs.
  • Code Analysis: Get insights and suggestions for your code snippets using the Codestral API.
  • Configuration Management: Generate, view, and load configuration files to manage your API keys and settings.

🚀 Installation

Prerequisites

Before you begin, ensure you have the following installed:

Setup Steps

  1. Clone the Repository Grab the code from GitHub and navigate into the project folder:

    git clone https://github.com/RingCanary/mistral-chat-cli-rs.git
    cd mistral-chat-cli-rs
  2. Build the Application Compile the app with Cargo:

    cargo build --release
  3. Run It Start using the CLI right away:

    cargo run --release -- [OPTIONS] <SUBCOMMAND>

🛠️ Usage

The CLI follows this structure:

mistral-chat-cli-rs [OPTIONS] <SUBCOMMAND>

Available Subcommands

  • chat <PROMPT> Send a prompt to the AI. If "code" is in your prompt, it uses Codestral; otherwise, it defaults to Mistral. Example: Streams the response directly to your console.

  • test Checks if the Mistral and Codestral APIs are reachable and reports the result. Example: Perfect for verifying your setup.

  • code <CODE_SNIPPET> Analyzes a code snippet using the Codestral API and displays the feedback. Example: Great for debugging or improving code.

  • config <CONFIG_COMMAND> Manage configuration files. Available config commands:

    • generate [--path <FILE_PATH>]: Generate a sample configuration file.
    • view: View the current configuration.
    • load --file-path <FILE_PATH>: Load a configuration file from a specified path.

Options

  • --debug Enable debug mode to see detailed logs of API requests and responses. Example: Useful for troubleshooting.

🔑 Configuration

To interact with the APIs, you’ll need to set up your API keys in a configuration file. The configuration file should contain:

  • mistral_api_key: Your key for the Mistral API.
  • codestral_api_key: Your key for the Codestral API.

Configuration File

The configuration file is typically named config.toml and should be located in the root directory of the project. You can generate a sample configuration file using the config generate command.

Example Configuration File

mistral_api_key = "your_mistral_api_key"
codestral_api_key = "your_codestral_api_key"
debug = false

Tip: Get your API keys from the Mistral and Codestral service providers and keep them secure!


🌟 Examples

Here’s how you can use the CLI in action:

1. Chat About Anything

cargo run --release -- chat "What’s the meaning of life?"

Streams a thoughtful response from Mistral.

2. Code-Related Question

cargo run --release -- chat "How do I sort an array in Rust?"

Triggers Codestral for a code-focused answer.

3. Test Your API Connection

cargo run --release -- test

Confirms if Mistral and Codestral are online and ready.

4. Analyze a Code Snippet

cargo run --release -- code "fn add(a: i32, b: i32) -> i32 { a + b }"

Gets feedback from Codestral on your code.

5. Generate a Configuration File

cargo run --release -- config generate

Creates a sample configuration file.

6. View Current Configuration

cargo run --release -- config view

Displays the current configuration settings.

7. Load a Configuration File

cargo run --release -- config load --file-path path/to/config.toml

Loads a configuration file from the specified path.


🐞 Debugging

Need to troubleshoot? Use the --debug flag to peek under the hood:

cargo run --release -- --debug chat "Test this out"

This prints detailed info about API calls, helping you spot issues fast.


🛠️ Built With

This CLI is powered by some amazing tools:

  • Rust: Fast, safe, and efficient programming language.
  • clap: Command-line argument parsing made simple.
  • reqwest: Robust HTTP client for API requests.
  • serde: JSON serialization/deserialization magic.
  • tokio: Asynchronous runtime for smooth streaming.
  • config: Configuration file management.

🤝 Contributing

Love the project? Want to make it better? Contributions are welcome! Here’s how:

  1. Fork the repository.
  2. Create a branch for your changes (git checkout -b feature/awesome-idea).
  3. Commit your updates (git commit -m "Add awesome idea").
  4. Push to your branch (git push origin feature/awesome-idea).
  5. Open a pull request!

Found a bug or have a feature request? Open an issue on GitHub.


📜 License

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


Happy coding, chatting, and exploring with Mistral CLI!

About

a cli chat app using mistral and codestral

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages