|
| 1 | +# DeepShell C Version |
| 2 | + |
| 3 | +This is the C implementation of DeepShell, a command-line interface for interacting with Large Language Models (LLMs). This version provides the same functionality as the Python version but is written in C for better performance and smaller executable size. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +- **Multi-LLM Support**: Connect to Ollama servers and Google Gemini API |
| 8 | +- **Interactive Mode**: Chat with LLMs in an interactive session |
| 9 | +- **Configuration Management**: Easy setup and management of LLM services |
| 10 | +- **Conversation History**: Maintain context across multiple queries |
| 11 | +- **Markdown Rendering**: Beautiful output formatting |
| 12 | +- **Cross-platform**: Works on Linux and Windows (with MSYS2/Mingw64) |
| 13 | + |
| 14 | +## Prerequisites |
| 15 | + |
| 16 | +### Linux |
| 17 | +```bash |
| 18 | +sudo apt-get update |
| 19 | +sudo apt-get install -y build-essential libcurl4-openssl-dev libjson-c-dev |
| 20 | +``` |
| 21 | + |
| 22 | +### Windows (MSYS2/Mingw64) |
| 23 | +```bash |
| 24 | +pacman -S mingw-w64-x86_64-gcc mingw-w64-x86_64-curl mingw-w64-x86_64-json-c |
| 25 | +``` |
| 26 | + |
| 27 | +## Building |
| 28 | + |
| 29 | +### Linux |
| 30 | +```bash |
| 31 | +cd C-Version |
| 32 | +make |
| 33 | +``` |
| 34 | + |
| 35 | +### Windows (MSYS2/Mingw64) |
| 36 | +```bash |
| 37 | +cd C-Version |
| 38 | +make |
| 39 | +``` |
| 40 | + |
| 41 | +### Development Build (with debug info) |
| 42 | +```bash |
| 43 | +make debug |
| 44 | +``` |
| 45 | + |
| 46 | +### Release Build |
| 47 | +```bash |
| 48 | +make release |
| 49 | +``` |
| 50 | + |
| 51 | +## Installation |
| 52 | + |
| 53 | +After building, you can install the executable: |
| 54 | + |
| 55 | +```bash |
| 56 | +# Copy to a directory in your PATH |
| 57 | +sudo cp deepshell /usr/local/bin/ |
| 58 | + |
| 59 | +# Or add the current directory to your PATH |
| 60 | +export PATH=$PATH:$(pwd) |
| 61 | +``` |
| 62 | + |
| 63 | +## Usage |
| 64 | + |
| 65 | +### Initial Setup |
| 66 | + |
| 67 | +The first time you run DeepShell, you'll need to configure your LLM services: |
| 68 | + |
| 69 | +```bash |
| 70 | +./deepshell -s |
| 71 | +``` |
| 72 | + |
| 73 | +This will guide you through: |
| 74 | +1. Configuring Ollama server connection |
| 75 | +2. Setting up Gemini API keys |
| 76 | +3. Selecting default models |
| 77 | +4. Configuring other options |
| 78 | + |
| 79 | +### Basic Usage |
| 80 | + |
| 81 | +**Query an LLM:** |
| 82 | +```bash |
| 83 | +./deepshell -q "What is the capital of France?" |
| 84 | +``` |
| 85 | + |
| 86 | +**Interactive mode:** |
| 87 | +```bash |
| 88 | +./deepshell -i |
| 89 | +``` |
| 90 | + |
| 91 | +**Show help:** |
| 92 | +```bash |
| 93 | +./deepshell -h |
| 94 | +``` |
| 95 | + |
| 96 | +### Command Line Options |
| 97 | + |
| 98 | +- `-s, --setup`: Run interactive configuration setup |
| 99 | +- `-q, --query QUERY`: Send a query to the active LLM |
| 100 | +- `-i, --interactive`: Start an interactive chat session |
| 101 | +- `-l, --llm`: Switch or configure LLM services |
| 102 | +- `-model, --model-change`: Change the default model for active service |
| 103 | +- `-set-key, --set-api-key`: Manage Gemini API keys |
| 104 | +- `-show-key, --show-api-key`: Show active Gemini API key |
| 105 | +- `-gq, --gemini-quota`: Check Gemini API quota |
| 106 | +- `-show-config, --show-full-conf`: Display current configuration |
| 107 | +- `-j, --jump-llm`: Switch to previously used LLM service |
| 108 | +- `-d, --delete-config`: Delete configuration file |
| 109 | +- `-v, --version`: Show version information |
| 110 | +- `-h, --help`: Show help message |
| 111 | + |
| 112 | +## Configuration |
| 113 | + |
| 114 | +DeepShell stores its configuration in `~/.deepshell/deepshell.conf`. The configuration includes: |
| 115 | + |
| 116 | +- Active LLM service |
| 117 | +- Server addresses and API keys |
| 118 | +- Default models for each service |
| 119 | +- Markdown rendering preferences |
| 120 | +- Interactive session settings |
| 121 | + |
| 122 | +## Supported LLMs |
| 123 | + |
| 124 | +### Ollama |
| 125 | +- Connect to any Ollama server (local or remote) |
| 126 | +- Supports all Ollama models (Llama, Mistral, etc.) |
| 127 | +- Automatic model discovery |
| 128 | + |
| 129 | +### Google Gemini |
| 130 | +- Access to Gemini models via Google AI Studio API |
| 131 | +- Multiple API key management |
| 132 | +- Quota monitoring |
| 133 | + |
| 134 | +## Examples |
| 135 | + |
| 136 | +### Setup Ollama |
| 137 | +```bash |
| 138 | +./deepshell -s |
| 139 | +# Choose option 1 (Configure Ollama service) |
| 140 | +# Enter server address: http://localhost:11434 |
| 141 | +# Select a model from the list |
| 142 | +``` |
| 143 | + |
| 144 | +### Setup Gemini |
| 145 | +```bash |
| 146 | +./deepshell -s |
| 147 | +# Choose option 2 (Configure Gemini service) |
| 148 | +# Add your API key with a nickname |
| 149 | +# Select a model from the list |
| 150 | +``` |
| 151 | + |
| 152 | +### Quick Query |
| 153 | +```bash |
| 154 | +./deepshell -q "Write a C function to calculate factorial" |
| 155 | +``` |
| 156 | + |
| 157 | +### Interactive Session |
| 158 | +```bash |
| 159 | +./deepshell -i |
| 160 | +# Type your questions and get responses |
| 161 | +# Type 'exit' to quit |
| 162 | +``` |
| 163 | + |
| 164 | +## Troubleshooting |
| 165 | + |
| 166 | +### Build Issues |
| 167 | +- Ensure you have the required development libraries installed |
| 168 | +- On Windows, make sure you're using MSYS2/Mingw64 environment |
| 169 | +- Check that libcurl and libjson-c are properly installed |
| 170 | + |
| 171 | +### Runtime Issues |
| 172 | +- Verify your Ollama server is running and accessible |
| 173 | +- Check that your Gemini API key is valid |
| 174 | +- Ensure network connectivity for API calls |
| 175 | + |
| 176 | +### Configuration Issues |
| 177 | +- Delete the config file (`~/.deepshell/deepshell.conf`) and run setup again |
| 178 | +- Check file permissions for the config directory |
| 179 | + |
| 180 | +## Performance |
| 181 | + |
| 182 | +The C version offers several advantages over the Python version: |
| 183 | +- **Faster startup time**: No Python interpreter overhead |
| 184 | +- **Smaller executable**: Single binary with minimal dependencies |
| 185 | +- **Lower memory usage**: More efficient memory management |
| 186 | +- **Better system integration**: Native system calls |
| 187 | + |
| 188 | +## Development |
| 189 | + |
| 190 | +### Project Structure |
| 191 | +``` |
| 192 | +C-Version/ |
| 193 | +├── Makefile # Build configuration |
| 194 | +├── deepshell.h # Main header file |
| 195 | +├── main.c # Command-line interface |
| 196 | +├── utils.c # Utility functions |
| 197 | +├── config.c # Configuration management |
| 198 | +├── settings.c # Interactive setup |
| 199 | +├── ollama.c # Ollama API integration |
| 200 | +├── gemini.c # Gemini API integration |
| 201 | +├── interactive.c # Interactive mode |
| 202 | +└── README.md # This file |
| 203 | +``` |
| 204 | + |
| 205 | +### Adding New Features |
| 206 | +1. Add function prototypes to `deepshell.h` |
| 207 | +2. Implement functions in appropriate `.c` files |
| 208 | +3. Update the Makefile if adding new source files |
| 209 | +4. Test thoroughly with different LLM services |
| 210 | + |
| 211 | +## License |
| 212 | + |
| 213 | +This project follows the same license as the original Python version. |
| 214 | + |
| 215 | +## Contributing |
| 216 | + |
| 217 | +Contributions are welcome! Please ensure your code: |
| 218 | +- Follows the existing coding style |
| 219 | +- Includes proper error handling |
| 220 | +- Is tested on both Linux and Windows |
| 221 | +- Maintains compatibility with existing features |
0 commit comments