返回提交历史
Modified
g4f/Provider/GradientNetwork.py
+7
-16
Modified
g4f/Provider/ItalyGPT.py
+4
-3
Modified
g4f/Provider/__init__.py
+1
-0
Modified
g4f/Provider/hf_space/BAAI_Ling.py
+29
-22
XFEstudio/gpt4free
Refactor GradientNetwork and ItalyGPT providers; update BAAI_Ling for improved functionality and model handling
1fd9b8d1
代码差异
4 个文件
+41
-41
@@ -3,7 +3,7 @@ from __future__ import annotations
3
3
import json
4
4
5
5
from ..typing import AsyncResult, Messages
6
from ..providers.response import Reasoning
6
from ..providers.response import Reasoning, JsonResponse
7
7
from ..requests import StreamSession
8
8
from .base_provider import AsyncGeneratorProvider, ProviderModelMixin
9
9
@@ -23,7 +23,7 @@ class GradientNetwork(AsyncGeneratorProvider, ProviderModelMixin):
23
23
supports_system_message = True
24
24
supports_message_history = True
25
25
26
default_model = "Qwen3 235B"
26
default_model = "GPT OSS 120B"
27
27
models = [
28
28
default_model,
29
29
"GPT OSS 120B",
@@ -40,9 +40,7 @@ class GradientNetwork(AsyncGeneratorProvider, ProviderModelMixin):
40
40
model: str,
41
41
messages: Messages,
42
42
proxy: str = None,
43
temperature: float = None,
44
max_tokens: int = None,
45
enable_thinking: bool = False,
43
enable_thinking: bool = True,
46
44
**kwargs
47
45
) -> AsyncResult:
48
46
"""
@@ -52,8 +50,6 @@ class GradientNetwork(AsyncGeneratorProvider, ProviderModelMixin):
52
50
model: The model name to use
53
51
messages: List of message dictionaries
54
52
proxy: Optional proxy URL
55
temperature: Optional temperature parameter
56
max_tokens: Optional max tokens parameter
57
53
enable_thinking: Enable the thinking/analysis channel (maps to enableThinking in API)
58
54
**kwargs: Additional arguments
59
55
@@ -66,24 +62,18 @@ class GradientNetwork(AsyncGeneratorProvider, ProviderModelMixin):
66
62
headers = {
67
63
"Accept": "application/x-ndjson",
68
64
"Content-Type": "application/json",
69
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36",
70
65
"Origin": cls.url,
71
66
"Referer": f"{cls.url}/",
72
67
}
73
68
74
69
payload = {
70
"clusterMode": "nvidia" if "GPT OSS" in model else "hybrid",
75
71
"model": model,
76
72
"messages": messages,
77
73
}
78
79
if temperature is not None:
80
payload["temperature"] = temperature
81
if max_tokens is not None:
82
payload["max_tokens"] = max_tokens
83
74
if enable_thinking:
84
75
payload["enableThinking"] = enable_thinking
85
86
async with StreamSession(headers=headers, proxy=proxy) as session:
76
async with StreamSession(headers=headers, proxy=proxy, impersonate="chrome") as session:
87
77
async with session.post(
88
78
cls.api_endpoint,
89
79
json=payload,
@@ -96,6 +86,7 @@ class GradientNetwork(AsyncGeneratorProvider, ProviderModelMixin):
96
86
97
87
try:
98
88
data = json.loads(line)
89
yield JsonResponse.from_dict(data)
99
90
msg_type = data.get("type")
100
91
101
92
if msg_type == "reply":
@@ -113,4 +104,4 @@ class GradientNetwork(AsyncGeneratorProvider, ProviderModelMixin):
113
104
114
105
except json.JSONDecodeError:
115
106
# Skip non-JSON lines (may be partial data or empty)
116
continue
107
raise
@@ -1,5 +1,6 @@
1
1
from .base_provider import AsyncGeneratorProvider, ProviderModelMixin
2
2
from ..typing import AsyncResult, Messages
3
from ..requests import DEFAULT_HEADERS
3
4
from aiohttp import ClientSession
4
5
5
6
class ItalyGPT(AsyncGeneratorProvider, ProviderModelMixin):
@@ -23,10 +24,10 @@ class ItalyGPT(AsyncGeneratorProvider, ProviderModelMixin):
23
24
) -> AsyncResult:
24
25
model = cls.get_model(model)
25
26
headers = {
27
**DEFAULT_HEADERS,
26
28
"content-type": "application/json",
27
29
"origin": "https://italygpt.it",
28
30
"referer": "https://italygpt.it/",
29
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36"
30
31
}
31
32
payload = {
32
33
"messages": messages,
@@ -34,12 +35,12 @@ class ItalyGPT(AsyncGeneratorProvider, ProviderModelMixin):
34
35
}
35
36
async with ClientSession() as session:
36
37
async with session.post(
37
f"{cls.url}/api/chat/",
38
f"{cls.url}/api/chat",
38
39
json=payload,
39
40
headers=headers,
40
41
proxy=proxy,
41
42
) as resp:
42
43
resp.raise_for_status()
43
async for chunk in resp.content:
44
async for chunk in resp.content.iter_any():
44
45
if chunk:
45
46
yield chunk.decode()
@@ -49,6 +49,7 @@ from .DeepInfra import DeepInfra
49
49
from .EasyChat import EasyChat
50
50
from .GLM import GLM
51
51
from .GradientNetwork import GradientNetwork
52
from .ItalyGPT import ItalyGPT
52
53
from .LambdaChat import LambdaChat
53
54
from .Mintlify import Mintlify
54
55
from .OIVSCodeSer import OIVSCodeSer2, OIVSCodeSer0501
@@ -8,12 +8,12 @@ from ...typing import AsyncResult, Messages
8
8
from ...providers.response import JsonConversation
9
9
from ...requests.raise_for_status import raise_for_status
10
10
from ..base_provider import AsyncGeneratorProvider, ProviderModelMixin
11
from ..helper import format_prompt, get_last_user_message
11
from ..helper import format_prompt, get_last_user_message, get_system_prompt
12
12
from ... import debug
13
13
14
14
class BAAI_Ling(AsyncGeneratorProvider, ProviderModelMixin):
15
label = "BAAI Ling"
16
url = "https://instspace-ling-playground.hf.space"
15
label = "Ling & Ring Playground"
16
url = "https://cafe3310-ling-playground.hf.space"
17
17
api_endpoint = f"{url}/gradio_api/queue/join"
18
18
19
19
working = True
@@ -25,7 +25,7 @@ class BAAI_Ling(AsyncGeneratorProvider, ProviderModelMixin):
25
25
model_aliases = {
26
26
"ling": default_model,
27
27
}
28
models = [default_model]
28
models = ['ling-mini-2.0', 'ling-1t', 'ling-flash-2.0', 'ring-1t', 'ring-flash-2.0', 'ring-mini-2.0']
29
29
30
30
@classmethod
31
31
async def create_async_generator(
@@ -40,6 +40,7 @@ class BAAI_Ling(AsyncGeneratorProvider, ProviderModelMixin):
40
40
if is_new_conversation:
41
41
conversation = JsonConversation(session_hash=str(uuid.uuid4()).replace('-', '')[:12])
42
42
43
model = cls.get_model(model)
43
44
prompt = format_prompt(messages) if is_new_conversation else get_last_user_message(messages)
44
45
45
46
headers = {
@@ -52,10 +53,21 @@ class BAAI_Ling(AsyncGeneratorProvider, ProviderModelMixin):
52
53
}
53
54
54
55
payload = {
55
"data": [prompt],
56
"data": [
57
prompt,
58
[
59
[
60
None,
61
"Hello! I'm Ling. Try selecting a scenario and a message example below to get started."
62
]
63
],
64
get_system_prompt(messages),
65
1,
66
model
67
],
56
68
"event_data": None,
57
"fn_index": 0,
58
"trigger_id": 5,
69
"fn_index": 11,
70
"trigger_id": 14,
59
71
"session_hash": conversation.session_hash
60
72
}
61
73
@@ -79,27 +91,22 @@ class BAAI_Ling(AsyncGeneratorProvider, ProviderModelMixin):
79
91
if decoded_line.startswith('data: '):
80
92
try:
81
93
json_data = json.loads(decoded_line[6:])
82
83
94
if json_data.get('msg') == 'process_generating':
84
95
if 'output' in json_data and 'data' in json_data['output']:
85
96
output_data = json_data['output']['data']
86
97
if output_data and len(output_data) > 0:
87
text = output_data[0]
88
if isinstance(text, str) and text.startswith(full_response):
89
yield text[len(full_response):]
90
full_response = text
91
elif isinstance(text, str):
92
yield text
93
full_response = text
98
parts = output_data[0][0]
99
if len(parts) == 2:
100
new_text = output_data[0][1].pop()
101
full_response += new_text
102
yield new_text
103
if len(parts) > 2:
104
new_text = parts[2]
105
full_response += new_text
106
yield new_text
94
107
95
108
elif json_data.get('msg') == 'process_completed':
96
if 'output' in json_data and 'data' in json_data['output']:
97
output_data = json_data['output']['data']
98
if output_data and len(output_data) > 0:
99
final_text = output_data[0]
100
if isinstance(final_text, str) and len(final_text) > len(full_response):
101
yield final_text[len(full_response):]
102
break
109
break
103
110
104
111
except json.JSONDecodeError:
105
112
debug.log("Could not parse JSON:", decoded_line)