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

XFEstudio/gpt4free

fix LMArena get_models (#3189)

* fix * Update PollinationsAI.py * Update Qwen.py * Update Qwen.py * Update Qwen.py * Update LMArena.py * Update LMArena.py * Update Qwen.py * Update Qwen.py * Update g4f/Provider/Qwen.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: H Lohaus <hlohaus@users.noreply.github.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

c938760a
Ammar <ammar.alkotb@gmail.com>
提交于

代码差异

2 个文件 +35 -24
Modified g4f/Provider/Qwen.py +33 -22
@@ -2,6 +2,7 @@ from __future__ import annotations
2 2
3 3 import asyncio
4 4 import json
5 import mimetypes
5 6 import re
6 7 import uuid
7 8 from time import time
@@ -95,6 +96,37 @@ class Qwen(AsyncGeneratorProvider, ProviderModelMixin):
95 96 debug.log(f"Failed to load models from {cls.url}: {response.status_code} {response.reason}")
96 97 return cls.models
97 98
99 @classmethod
100 async def prepare_files(cls, media, chat_type="")->list:
101 files = []
102 for _file, file_name in media:
103 file_type, _ = mimetypes.guess_type(file_name)
104 file_class: Literal["default", "vision", "video", "audio", "document"] = "default"
105 _type: Literal["file", "image", "video", "audio"] = "file"
106 showType: Literal["file", "image", "video", "audio"] = "file"
107
108 if isinstance(_file, str) and _file.startswith('http'):
109 if chat_type == "image_edit" or (file_type and file_type.startswith("image")):
110 file_class = "vision"
111 _type = "image"
112 if not file_type:
113 # Try to infer from file extension, fallback to generic
114 ext = file_name.split('.')[-1].lower() if '.' in file_name else ''
115 file_type = mimetypes.types_map.get(f'.{ext}', 'application/octet-stream')
116 showType = "image"
117
118 files.append(
119 {
120 "type": _type,
121 "name": file_name,
122 "file_type": file_type,
123 "showType": showType,
124 "file_class": file_class,
125 "url": _file
126 }
127 )
128 return files
129
98 130 @classmethod
99 131 async def create_async_generator(
100 132 cls,
@@ -189,29 +221,8 @@ class Qwen(AsyncGeneratorProvider, ProviderModelMixin):
189 221 files = []
190 222 media = list(merge_media(media, messages))
191 223 if media:
192 for _file, file_name in media:
193 file_class: Literal["default", "vision", "video", "audio", "document"] = "vision"
194 _type: Literal["file", "image", "video", "audio"] = "image"
195 file_type = "image/jpeg"
196 showType: Literal["file", "image", "video", "audio"] = "image"
197
198 if isinstance(_file, str) and _file.startswith('http'):
199 if chat_type == "image_edit":
200 file_class = "vision"
201 _type = "image"
202 file_type = "image"
203 showType = "image"
224 files = await cls.prepare_files(media, chat_type=chat_type)
204 225
205 files.append(
206 {
207 "type": _type,
208 "name": file_name,
209 "file_type": file_type,
210 "showType": showType,
211 "file_class": file_class,
212 "url": _file
213 }
214 )
215 226 msg_payload = {
216 227 "stream": stream,
217 228 "incremental_output": stream,
Modified g4f/Provider/needs_auth/LMArena.py +2 -2
@@ -520,8 +520,8 @@ class LMArena(AsyncGeneratorProvider, ProviderModelMixin, AuthFileMixin):
520 520 if response.ok:
521 521 for line in response.text.splitlines():
522 522 if "initialModels" in line:
523 line = line.split("initialModels", maxsplit=1)[-1].split("initialModelAId")[0][
524 3:-3].replace('\\', '')
523 line = line.split("initialModels", maxsplit=1)[-1].split("initialModelAId")[0][3:-3]
524 line = line.encode("utf-8").decode("unicode_escape")
525 525 models = json.loads(line)
526 526 cls.text_models = {model["publicName"]: model["id"] for model in models if
527 527 "text" in model["capabilities"]["outputCapabilities"]}