返回提交历史
Modified
g4f/Provider/Upstage.py
+23
-7
XFEstudio/gpt4free
Update (g4f/Provider/Upstage.py)
5519ecbf
代码差异
1 个文件
+23
-7
@@ -41,35 +41,51 @@ class Upstage(AsyncGeneratorProvider, ProviderModelMixin):
41
41
**kwargs
42
42
) -> AsyncResult:
43
43
model = cls.get_model(model)
44
44
45
45
headers = {
46
46
"accept": "*/*",
47
47
"accept-language": "en-US,en;q=0.9",
48
"cache-control": "no-cache",
48
49
"content-type": "application/json",
50
"dnt": "1",
49
51
"origin": "https://console.upstage.ai",
52
"pragma": "no-cache",
50
53
"priority": "u=1, i",
51
54
"referer": "https://console.upstage.ai/",
52
"sec-ch-ua": '"Chromium";v="127", "Not)A;Brand";v="99"',
55
"sec-ch-ua": '"Not?A_Brand";v="99", "Chromium";v="130"',
53
56
"sec-ch-ua-mobile": "?0",
54
57
"sec-ch-ua-platform": '"Linux"',
55
58
"sec-fetch-dest": "empty",
56
59
"sec-fetch-mode": "cors",
57
60
"sec-fetch-site": "cross-site",
58
"user-agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36"
61
"user-agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36"
59
62
}
63
60
64
async with ClientSession(headers=headers) as session:
61
65
data = {
62
66
"stream": True,
63
67
"messages": [{"role": "user", "content": format_prompt(messages)}],
64
68
"model": model
65
69
}
70
66
71
async with session.post(f"{cls.api_endpoint}", json=data, proxy=proxy) as response:
67
72
response.raise_for_status()
73
74
response_text = ""
75
68
76
async for line in response.content:
69
77
if line:
70
78
line = line.decode('utf-8').strip()
79
71
80
if line.startswith("data: ") and line != "data: [DONE]":
72
data = json.loads(line[6:])
73
content = data['choices'][0]['delta'].get('content', '')
74
if content:
75
yield content
81
try:
82
data = json.loads(line[6:])
83
content = data['choices'][0]['delta'].get('content', '')
84
if content:
85
response_text += content
86
yield content
87
except json.JSONDecodeError:
88
continue
89
90
if line == "data: [DONE]":
91
break