Spaces:
Running
Running
Fixed the streaming issue
Browse files- __pycache__/app.cpython-312.pyc +0 -0
- app.py +6 -2
- logs.json +145 -0
- test.py +32 -0
__pycache__/app.cpython-312.pyc
CHANGED
Binary files a/__pycache__/app.cpython-312.pyc and b/__pycache__/app.cpython-312.pyc differ
|
|
app.py
CHANGED
@@ -223,7 +223,6 @@ async def vercelXaigenerate(json_data: Dict[str, Any]):
|
|
223 |
'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36'
|
224 |
}
|
225 |
|
226 |
-
# Convert messages to XAI format
|
227 |
messages = conver_to_xai_schema(json_data["messages"])
|
228 |
|
229 |
request_data = {
|
@@ -248,7 +247,12 @@ async def vercelXaigenerate(json_data: Dict[str, Any]):
|
|
248 |
async for line in request_ctx.aiter_lines():
|
249 |
if line:
|
250 |
if line.startswith('0:'):
|
251 |
-
text
|
|
|
|
|
|
|
|
|
|
|
252 |
response = {
|
253 |
"id": chunk_id,
|
254 |
"object": "chat.completion.chunk",
|
|
|
223 |
'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36'
|
224 |
}
|
225 |
|
|
|
226 |
messages = conver_to_xai_schema(json_data["messages"])
|
227 |
|
228 |
request_data = {
|
|
|
247 |
async for line in request_ctx.aiter_lines():
|
248 |
if line:
|
249 |
if line.startswith('0:'):
|
250 |
+
# Clean up the text and properly escape JSON characters
|
251 |
+
text = line[2:].strip()
|
252 |
+
if text.startswith('"') and text.endswith('"'):
|
253 |
+
text = text[1:-1]
|
254 |
+
text = text.replace('\\n', '\n').replace('\\', '')
|
255 |
+
|
256 |
response = {
|
257 |
"id": chunk_id,
|
258 |
"object": "chat.completion.chunk",
|
logs.json
CHANGED
@@ -13,5 +13,150 @@
|
|
13 |
"timestamp": "2025-04-12T11:51:54.228166",
|
14 |
"endpoint": "/chat",
|
15 |
"query": "vercelXaigenerate"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
}
|
17 |
]
|
|
|
13 |
"timestamp": "2025-04-12T11:51:54.228166",
|
14 |
"endpoint": "/chat",
|
15 |
"query": "vercelXaigenerate"
|
16 |
+
},
|
17 |
+
{
|
18 |
+
"timestamp": "2025-04-12T11:59:54.231283",
|
19 |
+
"endpoint": "/chat",
|
20 |
+
"query": "vercelXaigenerate"
|
21 |
+
},
|
22 |
+
{
|
23 |
+
"timestamp": "2025-04-12T12:00:40.844595",
|
24 |
+
"endpoint": "/chat",
|
25 |
+
"query": "vercelXaigenerate"
|
26 |
+
},
|
27 |
+
{
|
28 |
+
"timestamp": "2025-04-12T12:00:45.093082",
|
29 |
+
"endpoint": "/chat",
|
30 |
+
"query": "generate"
|
31 |
+
},
|
32 |
+
{
|
33 |
+
"timestamp": "2025-04-12T12:00:53.603673",
|
34 |
+
"endpoint": "/chat",
|
35 |
+
"query": "vercelXaigenerate"
|
36 |
+
},
|
37 |
+
{
|
38 |
+
"timestamp": "2025-04-12T12:01:08.563064",
|
39 |
+
"endpoint": "/chat",
|
40 |
+
"query": "vercelXaigenerate"
|
41 |
+
},
|
42 |
+
{
|
43 |
+
"timestamp": "2025-04-12T12:01:11.525946",
|
44 |
+
"endpoint": "/chat",
|
45 |
+
"query": "generate"
|
46 |
+
},
|
47 |
+
{
|
48 |
+
"timestamp": "2025-04-12T12:01:14.278740",
|
49 |
+
"endpoint": "/chat",
|
50 |
+
"query": "vercelXaigenerate"
|
51 |
+
},
|
52 |
+
{
|
53 |
+
"timestamp": "2025-04-12T12:01:16.915702",
|
54 |
+
"endpoint": "/chat",
|
55 |
+
"query": "vercelXaigenerate"
|
56 |
+
},
|
57 |
+
{
|
58 |
+
"timestamp": "2025-04-12T12:01:30.033848",
|
59 |
+
"endpoint": "/chat",
|
60 |
+
"query": "groqgenerate"
|
61 |
+
},
|
62 |
+
{
|
63 |
+
"timestamp": "2025-04-12T12:02:15.117096",
|
64 |
+
"endpoint": "/chat",
|
65 |
+
"query": "vercelXaigenerate"
|
66 |
+
},
|
67 |
+
{
|
68 |
+
"timestamp": "2025-04-12T12:02:23.649030",
|
69 |
+
"endpoint": "/chat",
|
70 |
+
"query": "generate"
|
71 |
+
},
|
72 |
+
{
|
73 |
+
"timestamp": "2025-04-12T12:02:28.933558",
|
74 |
+
"endpoint": "/chat",
|
75 |
+
"query": "groqgenerate"
|
76 |
+
},
|
77 |
+
{
|
78 |
+
"timestamp": "2025-04-12T12:02:38.160605",
|
79 |
+
"endpoint": "/chat",
|
80 |
+
"query": "generate"
|
81 |
+
},
|
82 |
+
{
|
83 |
+
"timestamp": "2025-04-12T12:02:52.076861",
|
84 |
+
"endpoint": "/chat",
|
85 |
+
"query": "vercelXaigenerate"
|
86 |
+
},
|
87 |
+
{
|
88 |
+
"timestamp": "2025-04-12T12:04:02.320142",
|
89 |
+
"endpoint": "/chat",
|
90 |
+
"query": "generate"
|
91 |
+
},
|
92 |
+
{
|
93 |
+
"timestamp": "2025-04-12T12:04:05.385644",
|
94 |
+
"endpoint": "/chat",
|
95 |
+
"query": "vercelXaigenerate"
|
96 |
+
},
|
97 |
+
{
|
98 |
+
"timestamp": "2025-04-12T12:04:20.976615",
|
99 |
+
"endpoint": "/chat",
|
100 |
+
"query": "generate"
|
101 |
+
},
|
102 |
+
{
|
103 |
+
"timestamp": "2025-04-12T12:04:24.590270",
|
104 |
+
"endpoint": "/chat",
|
105 |
+
"query": "groqgenerate"
|
106 |
+
},
|
107 |
+
{
|
108 |
+
"timestamp": "2025-04-12T12:04:34.063593",
|
109 |
+
"endpoint": "/chat",
|
110 |
+
"query": "groqgenerate"
|
111 |
+
},
|
112 |
+
{
|
113 |
+
"timestamp": "2025-04-12T12:04:38.292885",
|
114 |
+
"endpoint": "/chat",
|
115 |
+
"query": "generate"
|
116 |
+
},
|
117 |
+
{
|
118 |
+
"timestamp": "2025-04-12T12:04:40.796568",
|
119 |
+
"endpoint": "/chat",
|
120 |
+
"query": "vercelXaigenerate"
|
121 |
+
},
|
122 |
+
{
|
123 |
+
"timestamp": "2025-04-12T12:05:13.292850",
|
124 |
+
"endpoint": "/chat",
|
125 |
+
"query": "groqgenerate"
|
126 |
+
},
|
127 |
+
{
|
128 |
+
"timestamp": "2025-04-12T12:05:23.222112",
|
129 |
+
"endpoint": "/chat",
|
130 |
+
"query": "groqgenerate"
|
131 |
+
},
|
132 |
+
{
|
133 |
+
"timestamp": "2025-04-12T12:05:28.215528",
|
134 |
+
"endpoint": "/chat",
|
135 |
+
"query": "groqgenerate"
|
136 |
+
},
|
137 |
+
{
|
138 |
+
"timestamp": "2025-04-12T12:05:32.617464",
|
139 |
+
"endpoint": "/chat",
|
140 |
+
"query": "vercelXaigenerate"
|
141 |
+
},
|
142 |
+
{
|
143 |
+
"timestamp": "2025-04-12T12:06:42.995442",
|
144 |
+
"endpoint": "/chat",
|
145 |
+
"query": "generate"
|
146 |
+
},
|
147 |
+
{
|
148 |
+
"timestamp": "2025-04-12T12:06:44.829603",
|
149 |
+
"endpoint": "/chat",
|
150 |
+
"query": "groqgenerate"
|
151 |
+
},
|
152 |
+
{
|
153 |
+
"timestamp": "2025-04-12T12:06:52.601184",
|
154 |
+
"endpoint": "/chat",
|
155 |
+
"query": "groqgenerate"
|
156 |
+
},
|
157 |
+
{
|
158 |
+
"timestamp": "2025-04-12T12:06:56.874556",
|
159 |
+
"endpoint": "/chat",
|
160 |
+
"query": "vercelXaigenerate"
|
161 |
}
|
162 |
]
|
test.py
CHANGED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import requests
|
2 |
+
import json
|
3 |
+
|
4 |
+
url = "http://127.0.0.1:8000/chat"
|
5 |
+
|
6 |
+
payload = {
|
7 |
+
"model": "your-model-name",
|
8 |
+
"message": "Create a json object of top 10 anime .json response only!",
|
9 |
+
"messages": []
|
10 |
+
}
|
11 |
+
|
12 |
+
headers = {
|
13 |
+
"Content-Type": "application/json"
|
14 |
+
}
|
15 |
+
|
16 |
+
# Send streaming POST request
|
17 |
+
with requests.post(url, data=json.dumps(payload), headers=headers, stream=True) as response:
|
18 |
+
if response.status_code == 200:
|
19 |
+
for line in response.iter_lines(decode_unicode=True):
|
20 |
+
if line and line.startswith('data: '):
|
21 |
+
try:
|
22 |
+
# Remove 'data: ' prefix and parse JSON
|
23 |
+
json_data = json.loads(line[6:])
|
24 |
+
# Extract text from choices if available
|
25 |
+
if json_data.get('choices') and len(json_data['choices']) > 0:
|
26 |
+
text = json_data['choices'][0].get('text', '')
|
27 |
+
if text:
|
28 |
+
print(text, end='')
|
29 |
+
except json.JSONDecodeError:
|
30 |
+
continue
|
31 |
+
else:
|
32 |
+
print("Error:", response.status_code, response.text)
|