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

XFEstudio/gpt4free

feat: Enhance Qwen provider with reasoning effort parameter and update RequestConfig model

6ca8b6eb
hlohaus <983577+hlohaus@users.noreply.github.com>
提交于

代码差异

3 个文件 +18 -32
Modified g4f/Provider/Qwen.py +10 -26
@@ -197,7 +197,7 @@ class Qwen(AsyncGeneratorProvider, ProviderModelMixin):
197 197 file_id = data.get("file_id")
198 198
199 199 # Put File into Url
200 str_date = datetime.datetime.now(datetime.timezone.utc).strftime('%Y%m%dT%H%M%SZ')
200 str_date = datetime.datetime.now(datetime.timezone.utc).strftime('%Y%m%dT%H%M%SZ')
201 201 headers = get_oss_headers('PUT', str_date, data, file_type)
202 202 async with session.put(
203 203 file_url.split("?")[0],
@@ -360,7 +360,7 @@ class Qwen(AsyncGeneratorProvider, ProviderModelMixin):
360 360 conversation: JsonConversation = None,
361 361 proxy: str = None,
362 362 stream: bool = True,
363 enable_thinking: bool = True,
363 reasoning_effort: Optional[Literal["low", "medium", "high"]] = "medium",
364 364 chat_type: Literal[
365 365 "t2t", "search", "artifacts", "web_dev", "deep_research", "t2i", "image_edit", "t2v"
366 366 ] = "t2t",
@@ -378,44 +378,28 @@ class Qwen(AsyncGeneratorProvider, ProviderModelMixin):
378 378 Txt2Txt = "t2t"
379 379 WebDev = "web_dev"
380 380 """
381 # cache_file = cls.get_cache_file()
382 # cookie: str = kwargs.get("cookie", "") # ssxmod_itna=1-...
383 # args = kwargs.get("qwen_args", {})
384 # args.setdefault("cookies", {})
385
386 # if not args and cache_file.exists():
387 # try:
388 # with cache_file.open("r") as f:
389 # args = json.load(f)
390 # except json.JSONDecodeError:
391 # debug.log(f"Cache file {cache_file} is corrupted, removing it.")
392 # cache_file.unlink()
393 # if not cookie:
394 # if not args:
395 # args = await cls.get_args(proxy, **kwargs)
396 # cookie = "; ".join([f"{k}={v}" for k, v in args["cookies"].items()])
397 381 model_name = cls.get_model(model)
398 382 prompt = get_last_user_message(messages)
383 enable_thinking = reasoning_effort in ("medium", "high")
399 384 timeout = kwargs.get("timeout") or 5 * 60
400 385 token = kwargs.get("token")
401 386 async with StreamSession(headers=cls._get_headers(token)) as session:
402 try:
403 if token:
387 if token:
388 try:
404 389 async with session.get('https://chat.qwen.ai/api/v1/auths/', proxy=proxy) as user_info_res:
405 390 await cls.raise_for_status(user_info_res)
406 391 debug.log(await user_info_res.json())
407 except Exception as e:
408 debug.error(e)
392 except Exception as e:
393 debug.error(e)
409 394 for attempt in range(5):
410 395 try:
411 req_headers = await cls._get_req_headers(session.headers)
412 # req_headers['bx-ua'] = ua
396 req_headers = await cls._get_req_headers(session, proxy=proxy)
413 397 message_id = str(uuid.uuid4())
414 398 if conversation is None:
415 399 chat_payload = {
416 400 "title": "New Chat",
417 401 "models": [model_name],
418 "chat_mode": "normal",# local
402 "chat_mode": "normal",
419 403 "chat_type": chat_type,
420 404 "timestamp": int(time() * 1000)
421 405 }
@@ -442,7 +426,7 @@ class Qwen(AsyncGeneratorProvider, ProviderModelMixin):
442 426 "stream": stream,
443 427 "incremental_output": stream,
444 428 "chat_id": conversation.chat_id,
445 "chat_mode": "normal",# local
429 "chat_mode": "normal",
446 430 "model": model_name,
447 431 "parent_id": conversation.parent_id,
448 432 "messages": [
Modified g4f/api/stubs.py +4 -5
@@ -1,7 +1,7 @@
1 1 from __future__ import annotations
2 2
3 3 from pydantic import BaseModel, Field, model_validator
4 from typing import Union, Optional
4 from typing import Literal, Union, Optional
5 5
6 6 from ..typing import Messages
7 7
@@ -10,7 +10,7 @@ class RequestConfig(BaseModel):
10 10 model: str = Field(default="")
11 11 provider: Optional[str] = None
12 12 media: Optional[list[tuple[str, str]]] = None
13 modalities: Optional[list[str]] = None
13 modalities: Optional[list[Literal["text", "audio"]]] = None
14 14 temperature: Optional[float] = None
15 15 presence_penalty: Optional[float] = None
16 16 frequency_penalty: Optional[float] = None
@@ -18,7 +18,7 @@ class RequestConfig(BaseModel):
18 18 max_tokens: Optional[int] = None
19 19 stop: Union[list[str], str, None] = None
20 20 api_key: Optional[Union[str, dict[str, str]]] = None
21 web_search: Optional[bool] = None
21 web_search: Optional[Union[str, bool]] = None
22 22 conversation: Optional[dict] = None
23 23 timeout: Optional[int] = None
24 24 stream_timeout: Optional[int] = None
@@ -43,9 +43,8 @@ class RequestConfig(BaseModel):
43 43 ]
44 44 ],
45 45 )
46 reasoning_effort: Optional[str] = None
46 reasoning_effort: Optional[Literal["low", "medium", "high"]] = None
47 47 logit_bias: Optional[dict] = None
48 modalities: Optional[list[str]] = None
49 48 audio: Optional[dict] = None
50 49 response_format: Optional[dict] = None
51 50 download_media: bool = False
Modified g4f/providers/base_provider.py +4 -1
@@ -37,7 +37,9 @@ SAFE_PARAMETERS = [
37 37 "api_key", "seed", "width", "height",
38 38 "max_retries", "web_search", "cache",
39 39 "guidance_scale", "num_inference_steps", "randomize_seed",
40 "safe", "enhance", "private", "aspect_ratio", "n", "transparent"
40 "safe", "enhance", "private",
41 "aspect_ratio", "n", "transparent",
42 "reasoning_effort"
41 43 ]
42 44
43 45 BASIC_PARAMETERS = {
@@ -66,6 +68,7 @@ PARAMETER_EXAMPLES = {
66 68 "tools": [],
67 69 "width": 1024,
68 70 "height": 1024,
71 "reasoning_effort": "medium",
69 72 }
70 73
71 74 class AbstractProvider(BaseProvider):