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.
- 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.
Before you begin, ensure you have the following installed:
-
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 -
Build the Application Compile the app with Cargo:
cargo build --release
-
Run It Start using the CLI right away:
cargo run --release -- [OPTIONS] <SUBCOMMAND>
The CLI follows this structure:
mistral-chat-cli-rs [OPTIONS] <SUBCOMMAND>
-
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. -
testChecks 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.
--debugEnable debug mode to see detailed logs of API requests and responses. Example: Useful for troubleshooting.
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.
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.
mistral_api_key = "your_mistral_api_key"
codestral_api_key = "your_codestral_api_key"
debug = falseTip: Get your API keys from the Mistral and Codestral service providers and keep them secure!
Here’s how you can use the CLI in action:
cargo run --release -- chat "What’s the meaning of life?"Streams a thoughtful response from Mistral.
cargo run --release -- chat "How do I sort an array in Rust?"Triggers Codestral for a code-focused answer.
cargo run --release -- testConfirms if Mistral and Codestral are online and ready.
cargo run --release -- code "fn add(a: i32, b: i32) -> i32 { a + b }"Gets feedback from Codestral on your code.
cargo run --release -- config generateCreates a sample configuration file.
cargo run --release -- config viewDisplays the current configuration settings.
cargo run --release -- config load --file-path path/to/config.tomlLoads a configuration file from the specified path.
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.
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.
Love the project? Want to make it better? Contributions are welcome! Here’s how:
- Fork the repository.
- Create a branch for your changes (
git checkout -b feature/awesome-idea). - Commit your updates (
git commit -m "Add awesome idea"). - Push to your branch (
git push origin feature/awesome-idea). - Open a pull request!
Found a bug or have a feature request? Open an issue on GitHub.
This project is licensed under the MIT License. See the LICENSE file for details.
Happy coding, chatting, and exploring with Mistral CLI!