Spaces:
Sleeping
Sleeping
Update qwen.py
Browse files
qwen.py
CHANGED
@@ -28,12 +28,25 @@ def qwen_chat(chat_history):
|
|
28 |
session.cookies.update(parse_cookies(COOKIE_STRING))
|
29 |
session_id = str(uuid.uuid4())
|
30 |
chat_id = str(uuid.uuid4())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
payload = {
|
32 |
"stream": True,
|
33 |
"incremental_output": True,
|
34 |
"chat_type": "t2t",
|
35 |
"model": "qwen-max-latest",
|
36 |
-
"messages":
|
37 |
"session_id": session_id,
|
38 |
"chat_id": chat_id,
|
39 |
"id": str(uuid.uuid4())
|
@@ -58,16 +71,8 @@ def qwen_chat(chat_history):
|
|
58 |
except requests.exceptions.RequestException as e:
|
59 |
print(f"Request failed: {str(e)}")
|
60 |
|
61 |
-
def get_qwen_response(
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
"chat_type": "t2t",
|
67 |
-
},
|
68 |
-
{
|
69 |
-
"role": "user",
|
70 |
-
"content": user_content # Now accepts list of text/image elements
|
71 |
-
}
|
72 |
-
]
|
73 |
-
return "".join(qwen_chat(chat_history))
|
|
|
28 |
session.cookies.update(parse_cookies(COOKIE_STRING))
|
29 |
session_id = str(uuid.uuid4())
|
30 |
chat_id = str(uuid.uuid4())
|
31 |
+
|
32 |
+
# Build messages with system prompt and history
|
33 |
+
messages = [
|
34 |
+
{
|
35 |
+
"role": "system",
|
36 |
+
"content": system_prompt,
|
37 |
+
"chat_type": "t2t",
|
38 |
+
}
|
39 |
+
]
|
40 |
+
|
41 |
+
# Add last 5 messages from history
|
42 |
+
messages.extend(chat_history[-5:])
|
43 |
+
|
44 |
payload = {
|
45 |
"stream": True,
|
46 |
"incremental_output": True,
|
47 |
"chat_type": "t2t",
|
48 |
"model": "qwen-max-latest",
|
49 |
+
"messages": messages,
|
50 |
"session_id": session_id,
|
51 |
"chat_id": chat_id,
|
52 |
"id": str(uuid.uuid4())
|
|
|
71 |
except requests.exceptions.RequestException as e:
|
72 |
print(f"Request failed: {str(e)}")
|
73 |
|
74 |
+
def get_qwen_response(system_prompt, chat_history):
|
75 |
+
response_text = ""
|
76 |
+
for chunk in qwen_chat(system_prompt, chat_history):
|
77 |
+
response_text += chunk
|
78 |
+
return response_text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|