Spaces:
Running
Running
Hermes Agent commited on
Commit ·
742f647
1
Parent(s): 716f99c
fix(stream): add proxy_buffering off, X-Accel-Buffering no headers, and sitecustomize monkeypatch to eliminate blank responses and sentence-transformers errors
Browse files- entrypoint.sh +7 -4
- gateway/hermes_standalone.py +10 -3
- nginx.conf +1 -0
entrypoint.sh
CHANGED
|
@@ -565,10 +565,13 @@ os.environ["OPENAI_API_KEY"] = "sk-2e556e0437ee2958-7baf2d-b4133935"
|
|
| 565 |
os.environ["HERMES_API_BASE_URL"] = "http://127.0.0.1:20128/api/v1"
|
| 566 |
os.environ["HERMES_API_KEY"] = "sk-2e556e0437ee2958-7baf2d-b4133935"
|
| 567 |
try:
|
| 568 |
-
import
|
| 569 |
-
|
| 570 |
-
|
| 571 |
-
|
|
|
|
|
|
|
|
|
|
| 572 |
except Exception:
|
| 573 |
pass
|
| 574 |
PYCUSTOM
|
|
|
|
| 565 |
os.environ["HERMES_API_BASE_URL"] = "http://127.0.0.1:20128/api/v1"
|
| 566 |
os.environ["HERMES_API_KEY"] = "sk-2e556e0437ee2958-7baf2d-b4133935"
|
| 567 |
try:
|
| 568 |
+
import open_webui.routers.retrieval as rrouter
|
| 569 |
+
rrouter.get_ef = lambda engine, model: None
|
| 570 |
+
except Exception:
|
| 571 |
+
pass
|
| 572 |
+
try:
|
| 573 |
+
import open_webui.retrieval.utils as rutils
|
| 574 |
+
rutils.get_model_path = lambda model, auto_update=False: ""
|
| 575 |
except Exception:
|
| 576 |
pass
|
| 577 |
PYCUSTOM
|
gateway/hermes_standalone.py
CHANGED
|
@@ -239,6 +239,13 @@ async def chat_completions(request: Request):
|
|
| 239 |
duration_ms = (time.time() - t0) * 1000
|
| 240 |
record_hermes_telemetry("chat_completions_fallback", duration_ms, {"model": model, "stream": stream})
|
| 241 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 242 |
if stream:
|
| 243 |
async def stream_generator():
|
| 244 |
chunk = {
|
|
@@ -246,7 +253,7 @@ async def chat_completions(request: Request):
|
|
| 246 |
"object": "chat.completion.chunk",
|
| 247 |
"created": int(time.time()),
|
| 248 |
"model": model,
|
| 249 |
-
"choices": [{"index": 0, "delta": {"role": "assistant", "content": reply_text}, "finish_reason": None}]
|
| 250 |
}
|
| 251 |
yield f"data: {json.dumps(chunk)}\n\n"
|
| 252 |
end_chunk = {
|
|
@@ -254,11 +261,11 @@ async def chat_completions(request: Request):
|
|
| 254 |
"object": "chat.completion.chunk",
|
| 255 |
"created": int(time.time()),
|
| 256 |
"model": model,
|
| 257 |
-
"choices": [{"index": 0, "delta": {}, "finish_reason": "stop"}]
|
| 258 |
}
|
| 259 |
yield f"data: {json.dumps(end_chunk)}\n\n"
|
| 260 |
yield "data: [DONE]\n\n"
|
| 261 |
-
return StreamingResponse(stream_generator(), media_type="text/event-stream")
|
| 262 |
|
| 263 |
return JSONResponse(content={
|
| 264 |
"id": f"chatcmpl-{int(time.time()*1000)}",
|
|
|
|
| 239 |
duration_ms = (time.time() - t0) * 1000
|
| 240 |
record_hermes_telemetry("chat_completions_fallback", duration_ms, {"model": model, "stream": stream})
|
| 241 |
|
| 242 |
+
stream_headers = {
|
| 243 |
+
"Cache-Control": "no-cache",
|
| 244 |
+
"Connection": "keep-alive",
|
| 245 |
+
"X-Accel-Buffering": "no",
|
| 246 |
+
"Content-Type": "text/event-stream"
|
| 247 |
+
}
|
| 248 |
+
|
| 249 |
if stream:
|
| 250 |
async def stream_generator():
|
| 251 |
chunk = {
|
|
|
|
| 253 |
"object": "chat.completion.chunk",
|
| 254 |
"created": int(time.time()),
|
| 255 |
"model": model,
|
| 256 |
+
"choices": [{"index": 0, "delta": {"role": "assistant", "content": reply_text}, "logprobs": None, "finish_reason": None}]
|
| 257 |
}
|
| 258 |
yield f"data: {json.dumps(chunk)}\n\n"
|
| 259 |
end_chunk = {
|
|
|
|
| 261 |
"object": "chat.completion.chunk",
|
| 262 |
"created": int(time.time()),
|
| 263 |
"model": model,
|
| 264 |
+
"choices": [{"index": 0, "delta": {}, "logprobs": None, "finish_reason": "stop"}]
|
| 265 |
}
|
| 266 |
yield f"data: {json.dumps(end_chunk)}\n\n"
|
| 267 |
yield "data: [DONE]\n\n"
|
| 268 |
+
return StreamingResponse(stream_generator(), media_type="text/event-stream", headers=stream_headers)
|
| 269 |
|
| 270 |
return JSONResponse(content={
|
| 271 |
"id": f"chatcmpl-{int(time.time()*1000)}",
|
nginx.conf
CHANGED
|
@@ -37,6 +37,7 @@ http {
|
|
| 37 |
proxy_set_header X-Forwarded-Host $host;
|
| 38 |
proxy_set_header X-Forwarded-Port $server_port;
|
| 39 |
|
|
|
|
| 40 |
proxy_connect_timeout 60s;
|
| 41 |
proxy_send_timeout 300s;
|
| 42 |
proxy_read_timeout 300s;
|
|
|
|
| 37 |
proxy_set_header X-Forwarded-Host $host;
|
| 38 |
proxy_set_header X-Forwarded-Port $server_port;
|
| 39 |
|
| 40 |
+
proxy_buffering off;
|
| 41 |
proxy_connect_timeout 60s;
|
| 42 |
proxy_send_timeout 300s;
|
| 43 |
proxy_read_timeout 300s;
|