Skip to content

Commit 886744d

Browse files
committed
feat: support gemini api
1 parent 01dd528 commit 886744d

File tree

12 files changed

+3856
-2183
lines changed

12 files changed

+3856
-2183
lines changed

Cargo.lock

Lines changed: 408 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ clap = { version = "4.0", features = ["derive"] }
1313
async-trait = "0.1"
1414
chrono = { version = "0.4", features = ["serde"] }
1515
toml = "0.8"
16+
scraper = "0.20"
1617

1718
[dev-dependencies]
1819
tokio-test = "0.4"

README.md

Lines changed: 59 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Access the latest AI model information in JSON format:
1818
- **All Providers Combined**: [all.json](dist/all.json) - Complete aggregated data from all providers
1919
- **PPInfra**: [ppinfra.json](dist/ppinfra.json) - PPInfra provider models
2020
- **OpenRouter**: [openrouter.json](dist/openrouter.json) - OpenRouter provider models
21+
- **Google Gemini**: [gemini.json](dist/gemini.json) - Google Gemini API models with web-scraped details
2122

2223
## 📦 Installation
2324

@@ -135,17 +136,68 @@ rate_limit = 5
135136

136137
[openai]
137138
api_url = "https://api.openai.com/v1/models"
138-
api_key_env = "OPENAI_API_KEY"
139+
api_key_env = "OPENAI_API_KEY" # OpenAI requires API key
139140
rate_limit = 20
140141
```
141142

142-
### Environment Variables
143-
If providers require API keys, set corresponding environment variables:
143+
### API Key Configuration
144+
145+
The tool supports flexible API key configuration with multiple methods and clear priority ordering:
146+
147+
#### Configuration Methods
148+
149+
**Method 1: Environment Variables (Recommended)**
144150
```bash
145-
export OPENAI_API_KEY="your-key-here"
146-
export OPENROUTER_API_KEY="your-key-here"
151+
# Only for providers that require API keys
152+
export GEMINI_API_KEY="your-key-here"
153+
# export OPENAI_API_KEY="your-key-here" # When OpenAI provider is added
154+
```
155+
156+
**Method 2: Configuration File**
157+
```toml
158+
# config/providers.toml
159+
[providers.gemini]
160+
api_url = "https://generativelanguage.googleapis.com/v1beta/openai/models"
161+
# Option A: Use default environment variable
162+
api_key_env = "GEMINI_API_KEY"
163+
# Option B: Use custom environment variable name
164+
# api_key_env = "MY_CUSTOM_GEMINI_KEY"
165+
# Option C: Direct API key (not recommended for production)
166+
# api_key = "your-gemini-key-here"
147167
```
148168

169+
#### API Key Priority (High to Low)
170+
171+
1. **Direct API key in config file** (`api_key` field)
172+
2. **Environment variable specified in config** (`api_key_env` field)
173+
3. **Default environment variable** (e.g., `GEMINI_API_KEY`)
174+
175+
This allows you to:
176+
- Use environment variables for security (recommended)
177+
- Override per-environment using config files
178+
- Mix different approaches for different providers
179+
180+
#### Provider-Specific Notes
181+
182+
- **PPInfra**: ✅ No API key required - uses public API
183+
- **OpenRouter**: ✅ No API key required - uses public model listing API
184+
- **Gemini**: ⚠️ Optional API key - uses hybrid web scraping + API approach
185+
186+
### Gemini Provider Details
187+
188+
The Gemini provider implements a unique **hybrid approach**:
189+
190+
**How It Works:**
191+
1. **API Call**: Fetches model list from Gemini API (model names only)
192+
2. **Web Scraping**: Scrapes Google's documentation for detailed capabilities
193+
3. **Data Merging**: Combines API data with scraped metadata
194+
195+
**Behavior by API Key Status:**
196+
- **With API Key**: Complete model list from API + enriched capabilities from scraping
197+
- **Without API Key**: Model list and capabilities from web scraping + fallback known models
198+
199+
**Why Hybrid?** The official Gemini API only provides model names, so web scraping is always required to get comprehensive capability information (vision, function calling, reasoning, context lengths, etc.).
200+
149201
## 🤖 GitHub Actions Automation
150202

151203
The project includes GitHub Actions workflow with multiple trigger methods:
@@ -225,8 +277,8 @@ For detailed development guide, see [Architecture Documentation](docs/architectu
225277

226278
-**PPInfra** - 38 models with reasoning, function calling, and vision capability detection
227279
-**OpenRouter** - 600+ models with comprehensive capability detection and metadata
228-
- 🚧 **OpenAI** - Planned
229-
- 🚧 **Google Gemini** - Planned
280+
- **Google Gemini** - Gemini models with hybrid API + web scraping approach for complete metadata
281+
- 🚧 **OpenAI** - Planned
230282

231283
## 🛠️ Development
232284

config/providers.toml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# PublicProviderConf Configuration File
2+
# This file allows you to customize provider settings and API keys
3+
4+
[providers.ppinfra]
5+
api_url = "https://api.ppinfra.com/openai/v1/models"
6+
# PPInfra doesn't require an API key
7+
rate_limit = 10
8+
timeout = 30
9+
10+
[providers.openrouter]
11+
api_url = "https://openrouter.ai/api/v1/models"
12+
# OpenRouter provides public model listing API - no API key required
13+
rate_limit = 5
14+
timeout = 30
15+
16+
[providers.gemini]
17+
api_url = "https://generativelanguage.googleapis.com/v1beta/openai/models"
18+
# Option 1: Use environment variable (recommended for security)
19+
api_key_env = "GEMINI_API_KEY"
20+
# Option 2: Direct API key (not recommended for production)
21+
# api_key = "your-gemini-key-here"
22+
# Option 3: Use custom environment variable name
23+
# api_key_env = "MY_CUSTOM_GEMINI_KEY"
24+
rate_limit = 10
25+
timeout = 60 # Web scraping might take longer
26+
27+
# API Key Configuration Notes:
28+
# - PPInfra: Uses public API, no key required
29+
# - OpenRouter: Uses public model listing API, no key required
30+
# - Gemini: Optional API key for complete model list
31+
#
32+
# API Key Priority (when applicable):
33+
# 1. Direct API key in config file (api_key)
34+
# 2. Environment variable specified in config (api_key_env)
35+
# 3. Default environment variable (e.g., GEMINI_API_KEY)

0 commit comments

Comments
 (0)