返回提交历史
Added
.github/copilot-instructions.md
+137
-0
XFEstudio/gpt4free
Add comprehensive GitHub Copilot instructions for gpt4free repository
Co-authored-by: hlohaus <983577+hlohaus@users.noreply.github.com>
9bf34361
代码差异
1 个文件
+137
-0
@@ -0,0 +1,137 @@
1
# gpt4free - Python Library for AI Provider Access
2
3
gpt4free is a Python 3.10+ library that provides unified access to 108+ AI providers for text generation, image generation, audio processing, and video generation. It offers a CLI, API server with web GUI, and Python library interface.
4
5
Always reference these instructions first and fallback to search or bash commands only when you encounter unexpected information that does not match the info here.
6
7
## Working Effectively
8
9
### Bootstrap and Install Dependencies
10
- Install Python 3.10+ (3.12 recommended): Project requires Python 3.10 or higher
11
- Clone repository: `git clone https://github.com/xtekky/gpt4free.git && cd gpt4free`
12
- Install minimal requirements: `pip install -r requirements-min.txt` -- takes 30-60 seconds. NEVER CANCEL.
13
- Install full requirements: `pip install -r requirements.txt` -- takes 2-5 minutes. NEVER CANCEL. Set timeout to 600+ seconds.
14
- Remove nodriver (CI requirement): `pip uninstall -y nodriver`
15
- Install in editable mode: `pip install -e .` -- takes 30 seconds. NEVER CANCEL.
16
17
### Testing and Validation
18
- Run unit tests: `python -m etc.unittest` -- takes 3-5 seconds. NEVER CANCEL.
19
- Expected results: ~41 tests, 1-2 failures expected (network isolation), 5-8 skipped tests
20
- Time unit tests: `time python -m etc.unittest` for precise timing
21
- Individual test scripts available in `etc/testing/` but may have outdated model references
22
23
### Running the Application
24
- **CLI Help**: `g4f --help` or `python -m g4f --help`
25
- **Client CLI**: `g4f client --help` for interactive text generation
26
- **API Server**: `python -m g4f --port 8080` -- starts FastAPI server with web GUI on http://localhost:8080
27
- **API Server Only**: `python -m g4f --port 8080 --no-gui` (if supported)
28
- **Python Library**:
29
```python
30
from g4f.client import Client
31
client = Client()
32
response = client.chat.completions.create(model="gpt-4o", messages=[{"role": "user", "content": "Hello"}])
33
print(response.choices[0].message.content)
34
```
35
36
## Validation Scenarios
37
38
Always test these scenarios after making changes:
39
40
### Basic Functionality Test
41
1. **Import Test**: `python -c "from g4f.client import Client; client = Client(); print('Success')"`
42
2. **CLI Test**: `g4f --help` should show available commands without errors
43
3. **Unit Tests**: `python -m etc.unittest` should complete without hanging
44
4. **API Server Test**: Start server `python -m g4f --port 8080`, then `curl -I http://localhost:8080` should return 200 OK
45
46
### Manual Validation Requirements
47
- ALWAYS test complete user workflows, not just imports
48
- Test both CLI and Python library interfaces when making provider changes
49
- Test API server startup and basic HTTP response
50
- Verify no new import errors or dependency conflicts
51
52
## Critical Timing and Build Information
53
54
- **NEVER CANCEL** long-running operations. Builds may take several minutes.
55
- **Requirements Installation**:
56
- Minimal (`requirements-min.txt`): 30-60 seconds. Set timeout to 120+ seconds.
57
- Full (`requirements.txt`): 2-5 minutes. Set timeout to 600+ seconds.
58
- **Unit Tests**: 3-5 seconds. Set timeout to 30+ seconds.
59
- **Package Installation**: 30-60 seconds. Set timeout to 120+ seconds.
60
- **Warning**: `pydub` will show ffmpeg warning - this is expected and harmless
61
62
## Key Development Info
63
64
### Project Structure
65
- `g4f/` - Main library code
66
- `Provider/` - AI provider implementations (108+ providers)
67
- `client/` - Client interfaces
68
- `api/` - FastAPI server implementation
69
- `gui/` - Web GUI components
70
- `cli/` - Command line interfaces
71
- `etc/` - Testing and development tools
72
- `unittest/` - Unit test suite
73
- `testing/` - Integration tests (may have outdated references)
74
- `examples/` - Usage examples
75
- `docs/` - Documentation
76
- `docker/` - Docker configuration files
77
78
### Provider System
79
- 108+ AI providers supported including OpenAI, Anthropic, Google, Meta, etc.
80
- Each provider in `g4f/Provider/` directory
81
- Working providers listed in CLI help: `g4f --help`
82
- Test provider availability: Network-dependent, many may fail in isolated environments
83
84
### Common Commands Reference
85
```bash
86
# Development workflow
87
git clone https://github.com/xtekky/gpt4free.git
88
cd gpt4free
89
pip install -r requirements-min.txt # Basic deps
90
pip install -r requirements.txt # Full deps
91
pip uninstall -y nodriver # CI requirement
92
pip install -e . # Editable install
93
python -m etc.unittest # Run tests
94
95
# Usage examples
96
g4f client "Hello world" # CLI chat
97
python -m g4f --port 8080 # Start server
98
python etc/examples/messages.py # Example script
99
```
100
101
### Installation Alternatives
102
- **PyPI**: `pip install -U g4f[all]` (external, not for development)
103
- **Docker**: Use provided docker-compose.yml for containerized deployment
104
- **Partial installs**: See `/docs/requirements.md` for component-specific installs
105
106
### Known Issues and Workarounds
107
- **ffmpeg warning**: Expected from pydub library, does not affect functionality
108
- **Network timeouts**: Expected for many providers in isolated environments
109
- **Model availability**: Provider-dependent, some models may not be accessible
110
- **nodriver removal**: Required for CI compatibility, remove after full install
111
112
## Development Guidelines
113
114
### Making Changes
115
- Always run unit tests before and after changes: `python -m etc.unittest`
116
- Test both minimal and full installations when adding dependencies
117
- Validate CLI commands work: `g4f --help`, `g4f client --help`
118
- Test Python import: `python -c "import g4f; print('OK')"`
119
- For provider changes, test basic client creation and simple completions
120
121
### Before Committing
122
- Run full test suite: `python -m etc.unittest`
123
- Verify no new dependency conflicts
124
- Test installation from scratch in clean environment when possible
125
- Ensure backwards compatibility with Python 3.10+
126
127
### Timeout Guidelines
128
- Use 600+ second timeouts for `pip install -r requirements.txt`
129
- Use 120+ second timeouts for basic pip installations
130
- Use 30+ second timeouts for unit tests
131
- NEVER use default timeouts for package installations - they will fail
132
133
### Entry Points
134
- **CLI Binary**: `g4f` (installed via setuptools entry_points)
135
- **Module**: `python -m g4f`
136
- **Client Module**: `python -m g4f.client`
137
- **Python Import**: `import g4f` or `from g4f.client import Client`