---

# cli_buddy

[![style: very good analysis][very_good_analysis_badge]][very_good_analysis_link]
[![License: MIT][license_badge]][license_link]

Generated by the [Very Good CLI][very_good_cli_link] 🤖

---

## Call Any LLM from Your Terminal
 - Lightweight (2MB) and Fast
 - Supports over 100+ LLMs (GPT, Claude, Cohere, LLama 3, Gemini Pro, etc.)
 - Use your own API key ([OpenRouter](https://openrouter.ai/))
 - Complete privacy - not a single analytic data is collected
  

## Demo

![Demo](demo.gif)

## Features
1. **Code Generation**: Ask for code and directly generate (or override) a file with it.
   - Option to copy to clipboard, ask for explanation, or chat with the model.
2. **Shell Command Execution**: Ask for a shell command and directly execute it in your terminal.
   - Option to copy to clipboard or ask for explanation.
3. **Continuous Chat**: Chat with AI continuously in your terminal.
4. **Session Management**: Save chat history in JSON format locally and load it when starting a new session using `-s <session_id>`.
   - By default, saving chat history is disabled.
5. **OpenRouter APIs**: Even though it's made as a CLI tool, this package can also be used for any Dart/Flutter project to use OpenRouter APIs. This package exposes OpenRouter APIs and Models. Simply declare `final openRouter = OpenRouterService();` and use it in your project. such as `final result = await openRouter.invoke(session: ChatSession(), shouldSkipLog: true);`

## Getting Started 🚀

### Installation

#### If Dart SDK is Already Installed
```sh
dart pub global activate cli_buddy
```

#### If Dart SDK is Not Installed
TODO: Add installation instructions using the binary executable and script.

### Get API Key from [OpenRouter](https://openrouter.ai/)
OpenRouter provides unified LLM APIs at (almost) the same cost as the original LLM API provider.

### Add `secret.env`
Create a `secret.env` file in the root directory and add:
```sh
openrouter_key=YOUR_OPENROUTER_KEY
```
Then run:
```sh
buddy set -s <path/to/secret.env>
```
Alternatively, you can run:
```sh
buddy set -k <your openrouter key>
```
This will create `secret.env` and `buddy.config` files at the default path.

### Example `buddy.config`
```json
{
  "secret_env_path": "secret.env",
  "default_model": "openai/gpt-4o-mini-2024-07-18",
  "max_tokens": null,
  "temperature": 0.3,
  "top_p": null,
  "top_k": null,
  "frequency_penalty": null,
  "presence_penalty": null,
  "repetition_penalty": null,
  "min_p": null,
  "top_a": null,
  "seed": null,
  "logit_bias": null,
  "logprobs": null,
  "top_logprobs": null,
  "response_format": null,
  "stop": null,
  "save_session": false,
  "cmd_prompt": null,
  "explain_prompt": null,
  "code_prompt": null,
  "chat_prompt": null
}
```

## Usage

```sh
# Suggest command
$ buddy suggest how can I update homebrew

# If you want to use special characters, use quotes
$ buddy suggest "how can I update homebrew?"

# Coding
$ buddy code "Generate a random number between 1 and 10 in Dart"

# Chat
$ buddy chat "Tell me about the SSH protocol"

# Show CLI version
$ buddy --version

# Show usage help
$ buddy --help
```

## Roadmap

- Refactoring
- Support for RAG (Retrieval-Augmented Generation) using Object_Box
- Installation script for binary executable and setup
- Support for Google Vertex AI API
- Markdown support

## Contributions

Contributions are welcome! Feel free to open issues or submit pull requests.

---

[very_good_analysis_badge]: https://img.shields.io/badge/style-very_good_analysis-B22C89.svg
[very_good_analysis_link]: https://pub.dev/packages/very_good_analysis
[license_badge]: https://img.shields.io/badge/license-MIT-blue.svg
[license_link]: https://opensource.org/licenses/MIT
[very_good_cli_link]: https://github.com/VeryGoodOpenSource/very_good_cli
