XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet
公开
关注 0 Fork 0 Star 1
返回提交历史

XFEstudio/gpt4free

Fix some issues in the demo

595dafd7
hlohaus <983577+hlohaus@users.noreply.github.com>
提交于

代码差异

5 个文件 +24 -21
Modified g4f/Provider/Jmuz.py +1 -0
@@ -31,6 +31,7 @@ class Jmuz(OpenaiTemplate):
31 31 model: str,
32 32 messages: Messages,
33 33 stream: bool = True,
34 api_key: str = None, # Remove api_key from kwargs
34 35 **kwargs
35 36 ) -> AsyncResult:
36 37 model = cls.get_model(model)
Modified g4f/Provider/needs_auth/HuggingChat.py +1 -0
@@ -74,6 +74,7 @@ class HuggingChat(AsyncAuthedProvider, ProviderModelMixin):
74 74 "gemma-2-27b": "google/gemma-2-27b-it",
75 75 "qwen-2-72b": "Qwen/Qwen2-72B-Instruct",
76 76 "qvq-72b": "Qwen/QVQ-72B-Preview",
77 "sd-3.5": "stabilityai/stable-diffusion-3.5-large",
77 78 }
78 79
79 80 @classmethod
Modified g4f/gui/server/backend_api.py +20 -9
@@ -8,7 +8,7 @@ import asyncio
8 8 import shutil
9 9 import random
10 10 import datetime
11 from flask import Flask, Response, request, jsonify
11 from flask import Flask, Response, request, jsonify, render_template
12 12 from typing import Generator
13 13 from pathlib import Path
14 14 from urllib.parse import quote_plus
@@ -69,13 +69,16 @@ class Backend_Api(Api):
69 69 default_limits=["200 per day", "50 per hour"],
70 70 storage_uri="memory://",
71 71 )
72
73 if has_flask_limiter and app.demo:
74 @app.route('/', methods=['GET'])
75 @limiter.exempt
76 def home():
77 return render_template('demo.html')
72 78 else:
73 class Dummy():
74 def limit(self, value):
75 def callback(value):
76 return value
77 return callback
78 limiter = Dummy()
79 @app.route('/', methods=['GET'])
80 def home():
81 return render_template('home.html')
79 82
80 83 @app.route('/backend-api/v2/models', methods=['GET'])
81 84 def jsonify_models(**kwargs):
@@ -111,8 +114,6 @@ class Backend_Api(Api):
111 114 }
112 115 for model, providers in models.demo_models.values()]
113 116
114 @app.route('/backend-api/v2/conversation', methods=['POST'])
115 @limiter.limit("4 per minute") # 1 request in 15 seconds
116 117 def handle_conversation():
117 118 """
118 119 Handles conversation requests and streams responses back.
@@ -151,6 +152,16 @@ class Backend_Api(Api):
151 152 mimetype='text/event-stream'
152 153 )
153 154
155 if has_flask_limiter and app.demo:
156 @app.route('/backend-api/v2/conversation', methods=['POST'])
157 @limiter.limit("4 per minute") # 1 request in 15 seconds
158 def _handle_conversation():
159 return handle_conversation()
160 else:
161 @app.route('/backend-api/v2/conversation', methods=['POST'])
162 def _handle_conversation():
163 return handle_conversation()
164
154 165 @app.route('/backend-api/v2/usage', methods=['POST'])
155 166 def add_usage():
156 167 cache_dir = Path(get_cookies_dir()) / ".usage"
Modified g4f/gui/server/website.py +1 -11
@@ -8,10 +8,6 @@ class Website:
8 8 def __init__(self, app) -> None:
9 9 self.app = app
10 10 self.routes = {
11 '/': {
12 'function': self._demo if app.demo else self._home,
13 'methods': ['GET', 'POST']
14 },
15 11 '/chat/': {
16 12 'function': self._index,
17 13 'methods': ['GET', 'POST']
@@ -40,10 +36,4 @@ class Website:
40 36 return render_template('index.html', chat_id=conversation_id)
41 37
42 38 def _index(self):
43 return render_template('index.html', chat_id=str(uuid.uuid4()))
44
45 def _home(self):
46 return render_template('home.html')
47
48 def _demo(self):
49 return render_template('demo.html')
39 return render_template('index.html', chat_id=str(uuid.uuid4()))
Modified g4f/models.py +1 -1
@@ -781,7 +781,7 @@ demo_models = {
781 781 command_r_plus.name: [command_r_plus, [HuggingSpace]],
782 782 command_r7b.name: [command_r7b, [HuggingSpace]],
783 783 gemma_2_27b.name: [gemma_2_27b, [HuggingFaceAPI]],
784 qwen_2_72b.name: [qwen_2_72b, [HuggingFaceAPI]],
784 qwen_2_72b.name: [qwen_2_72b, [HuggingSpace]],
785 785 qwen_2_5_coder_32b.name: [qwen_2_5_coder_32b, [HuggingFace]],
786 786 qwq_32b.name: [qwq_32b, [HuggingFace]],
787 787 llama_3_3_70b.name: [llama_3_3_70b, [HuggingFace]],