返回提交历史
Modified
README.md
+29
-3
Modified
g4f/Provider/Bing.py
+1
-1
Modified
g4f/gui/client/static/js/chat.v1.js
+8
-8
Modified
g4f/gui/server/api.py
+4
-4
Modified
g4f/gui/webview.py
+2
-1
Modified
setup.py
+12
-6
XFEstudio/gpt4free
Add webview docs and examples, Set webview as default
2ee724f9
代码差异
6 个文件
+56
-23
@@ -41,7 +41,7 @@ As per the survey, here is a list of improvements to come
41
41
- [ ] 🚧 Improve Documentation (in /docs & Guides, Howtos, & Do video tutorials)
42
42
- [x] Improve the provider status list & updates
43
43
- [ ] Tutorials on how to reverse sites to write your own wrapper (PoC only ofc)
44
- [ ] Improve the Bing wrapper. (might write a new wrapper in golang as it is very fast)
44
- [x] Improve the Bing wrapper. (Wait and Retry or reuse conversation)
45
45
- [ ] Write a standard provider performance test to improve the stability
46
46
- [ ] Potential support and development of local models
47
47
- [ ] 🚧 Improve compatibility and error handling
@@ -170,7 +170,33 @@ image_url = response.data[0].url
170
170
- New Client API like the OpenAI Python library: [/docs/client](/docs/client.md)
171
171
- Legacy API with python modules: [/docs/legacy](/docs/legacy.md)
172
172
173
#### Web UI
173
### Webview GUI
174
175
Open the GUI in a window of your OS. Runs on a local/static/ssl server with a js api. Supports login into the OpenAI Chat, Image Upload and streamed Text Generation.
176
177
Supports all platforms, but only Linux testet.
178
179
1. Install all requirements with:
180
181
```bash
182
pip install g4f[webview]
183
```
184
185
2. Follow the OS specific steps here:
186
[pywebview installation](https://pywebview.flowrl.com/guide/installation.html#dependencies)
187
188
3. Run the app with:
189
190
```python
191
from g4f.gui.webview import run_webview
192
run_webview(debug=True)
193
```
194
or execute the following command:
195
```bash
196
python -m g4f.gui.webview -debug
197
```
198
199
#### Webserver
174
200
175
201
To start the web interface, type the following codes in python:
176
202
@@ -237,7 +263,7 @@ set G4F_PROXY=http://host:port
237
263
| [bing.com](https://bing.com/chat) | `g4f.Provider.Bing` | ❌ | ✔️ | ✔️ |  | ❌ |
238
264
| [chatgpt.ai](https://chatgpt.ai) | `g4f.Provider.ChatgptAi` | ❌ | ✔️ | ✔️ |  | ❌ |
239
265
| [liaobots.site](https://liaobots.site) | `g4f.Provider.Liaobots` | ✔️ | ✔️ | ✔️ |  | ❌ |
240
| [chat.openai.com](https://chat.openai.com) | `g4f.Provider.OpenaiChat` | ✔️ | ✔️ | ✔️ |  | ✔️ |
266
| [chat.openai.com](https://chat.openai.com) | `g4f.Provider.OpenaiChat` | ✔️ | ❌ | ✔️ |  | ✔️ |
241
267
| [raycast.com](https://raycast.com) | `g4f.Provider.Raycast` | ✔️ | ✔️ | ✔️ |  | ✔️ |
242
268
| [beta.theb.ai](https://beta.theb.ai) | `g4f.Provider.Theb` | ✔️ | ✔️ | ✔️ |  | ❌ |
243
269
| [you.com](https://you.com) | `g4f.Provider.You` | ✔️ | ✔️ | ✔️ |  | ❌ |
@@ -414,7 +414,7 @@ async def stream_generate(
414
414
image_request = await upload_image(
415
415
session,
416
416
image,
417
"Balanced" if Tones.copilot == "Copilot" else tone,
417
"Balanced" if tone == Tones.copilot else tone,
418
418
headers
419
419
) if image else None
420
420
async with session.ws_connect(
@@ -240,26 +240,26 @@ async function add_message_chunk(message) {
240
240
}
241
241
}
242
242
243
cameraInput?.addEventListener("click", (e) => {
244
if (window?.pywebview) {
245
e.preventDefault();
246
pywebview.api.choose_file();
247
}
248
})
243
// fileInput?.addEventListener("click", (e) => {
244
// if (window?.pywebview) {
245
// e.preventDefault();
246
// pywebview.api.choose_file();
247
// }
248
// });
249
249
250
250
cameraInput?.addEventListener("click", (e) => {
251
251
if (window?.pywebview) {
252
252
e.preventDefault();
253
253
pywebview.api.take_picture();
254
254
}
255
})
255
});
256
256
257
257
imageInput?.addEventListener("click", (e) => {
258
258
if (window?.pywebview) {
259
259
e.preventDefault();
260
260
pywebview.api.choose_image();
261
261
}
262
})
262
});
263
263
264
264
const ask_gpt = async () => {
265
265
regenerate.classList.add(`regenerate-hidden`);
@@ -19,12 +19,12 @@ try:
19
19
filters=[["Image", "*.jpg", "*.jpeg", "*.png", "*.webp", "*.svg"]],
20
20
)
21
21
has_plyer = True
22
except (ImportError, NameError):
22
except ImportError:
23
23
has_plyer = False
24
24
try:
25
25
from android.runnable import run_on_ui_thread
26
from android.storage import app_storage_path
27
from android.permissions import request_permissions, Permission
26
import android.permissions
27
from android.permissions import Permission
28
28
from android.permissions import _RequestPermissionsManager
29
29
_RequestPermissionsManager.register_callback()
30
30
from .android_gallery import user_select_image
@@ -161,7 +161,7 @@ class Api():
161
161
162
162
def request_permissions(self):
163
163
if has_android:
164
request_permissions([
164
android.permissions.request_permissions([
165
165
Permission.CAMERA,
166
166
Permission.READ_EXTERNAL_STORAGE,
167
167
Permission.WRITE_EXTERNAL_STORAGE
@@ -16,6 +16,7 @@ import g4f.debug
16
16
17
17
def run_webview(
18
18
debug: bool = False,
19
ssl: bool = True,
19
20
storage_path: str = None
20
21
):
21
22
if getattr(sys, 'frozen', False):
@@ -36,7 +37,7 @@ def run_webview(
36
37
private_mode=False,
37
38
storage_path=storage_path,
38
39
debug=debug,
39
ssl=True
40
ssl=ssl
40
41
)
41
42
42
43
if __name__ == "__main__":
@@ -18,23 +18,24 @@ EXTRA_REQUIRE = {
18
18
'all': [
19
19
"curl_cffi>=0.6.2",
20
20
"certifi",
21
"async-property", # openai
22
"py-arkose-generator", # openai
21
#"py-arkose-generator", # not working
23
22
"browser_cookie3", # get_cookies
24
23
"PyExecJS", # GptForLove
25
24
"duckduckgo-search>=5.0" ,# internet.search
26
25
"beautifulsoup4", # internet.search and bing.create_images
27
26
"brotli", # openai
28
"platformdirs", # webdriver
29
"undetected-chromedriver>=3.5.5", # webdriver
30
"setuptools", # webdriver
27
#"undetected-chromedriver>=3.5.5", # webdriver
28
#"setuptools", # webdriver
29
"pywebview",
30
"platformdirs",
31
"plyer",
31
32
"aiohttp_socks", # proxy
32
33
"pillow", # image
33
34
"cairosvg", # svg image
34
35
"werkzeug", "flask", # gui
35
36
"loguru", "fastapi",
36
37
"uvicorn", "nest_asyncio", # api
37
"selenium-wire"
38
#"selenium-wire"
38
39
],
39
40
"image": [
40
41
"pillow",
@@ -47,6 +48,11 @@ EXTRA_REQUIRE = {
47
48
"setuptools",
48
49
"selenium-wire"
49
50
],
51
"webview": [
52
"webview",
53
"platformdirs",
54
"plyer"
55
],
50
56
"openai": [
51
57
"async-property",
52
58
"py-arkose-generator",