Skip to content
This repository was archived by the owner on Jul 13, 2026. It is now read-only.

Commit 5f6688a

Browse files
committed
Added C code
1 parent 7107578 commit 5f6688a

20 files changed

Lines changed: 3028 additions & 0 deletions

File tree

C/Makefile

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# DeepShell C Version Makefile
2+
# Supports both Linux and Windows (MSYS2/Mingw64)
3+
4+
CC = gcc
5+
CFLAGS = -Wall -Wextra -std=c99 -O2
6+
LDFLAGS =
7+
LIBS = -lcurl -ljson-c
8+
9+
# Platform detection
10+
ifeq ($(OS),Windows_NT)
11+
# Windows with MSYS2/Mingw64
12+
EXECUTABLE = deepshell.exe
13+
CFLAGS += -D_WIN32
14+
LDFLAGS += -static-libgcc
15+
else
16+
# Linux
17+
EXECUTABLE = deepshell
18+
CFLAGS += -D_POSIX_C_SOURCE=200809L
19+
endif
20+
21+
# Source files
22+
SOURCES = main.c settings.c gemini.c ollama.c utils.c config.c interactive.c
23+
OBJECTS = $(SOURCES:.c=.o)
24+
25+
# Default target
26+
all: $(EXECUTABLE)
27+
28+
# Build the executable
29+
$(EXECUTABLE): $(OBJECTS)
30+
$(CC) $(OBJECTS) -o $(EXECUTABLE) $(LDFLAGS) $(LIBS)
31+
32+
# Compile source files
33+
%.o: %.c
34+
$(CC) $(CFLAGS) -c $< -o $@
35+
36+
# Clean build artifacts
37+
clean:
38+
rm -f $(OBJECTS) $(EXECUTABLE)
39+
40+
# Install dependencies (Linux)
41+
install-deps-linux:
42+
sudo apt-get update
43+
sudo apt-get install -y libcurl4-openssl-dev libjson-c-dev
44+
45+
# Install dependencies (Windows/MSYS2)
46+
install-deps-windows:
47+
pacman -S mingw-w64-x86_64-curl mingw-w64-x86_64-json-c
48+
49+
# Development build with debug info
50+
debug: CFLAGS += -g -DDEBUG
51+
debug: $(EXECUTABLE)
52+
53+
# Release build
54+
release: CFLAGS += -DNDEBUG
55+
release: $(EXECUTABLE)
56+
57+
.PHONY: all clean install-deps-linux install-deps-windows debug release

C/README.md

Lines changed: 221 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,221 @@
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

Comments
 (0)