Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit b73c73c

Browse filesBrowse files
authored
feat: add disable_ping_events flag (abetlen#1257)
for backward compatibility, this is false by default it can be set to true to disable EventSource pings which are not supported by some OpenAI clients. fixes abetlen#1256
1 parent 4924455 commit b73c73c
Copy full SHA for b73c73c

File tree

Expand file treeCollapse file tree

2 files changed

+16
-0
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+16
-0
lines changed

‎llama_cpp/server/app.py

Copy file name to clipboardExpand all lines: llama_cpp/server/app.py
+12Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,13 @@ def get_llama_proxy():
8787
llama_outer_lock.release()
8888

8989

90+
_ping_message_factory = None
91+
92+
def set_ping_message_factory(factory):
93+
global _ping_message_factory
94+
_ping_message_factory = factory
95+
96+
9097
def create_app(
9198
settings: Settings | None = None,
9299
server_settings: ServerSettings | None = None,
@@ -138,6 +145,9 @@ def create_app(
138145
assert model_settings is not None
139146
set_llama_proxy(model_settings=model_settings)
140147

148+
if server_settings.disable_ping_events:
149+
set_ping_message_factory(lambda: bytes())
150+
141151
return app
142152

143153

@@ -302,6 +312,7 @@ def iterator() -> Iterator[llama_cpp.CreateCompletionStreamResponse]:
302312
iterator=iterator(),
303313
),
304314
sep="\n",
315+
ping_message_factory=_ping_message_factory,
305316
)
306317
else:
307318
return iterator_or_completion
@@ -470,6 +481,7 @@ def iterator() -> Iterator[llama_cpp.ChatCompletionChunk]:
470481
iterator=iterator(),
471482
),
472483
sep="\n",
484+
ping_message_factory=_ping_message_factory,
473485
)
474486
else:
475487
return iterator_or_completion

‎llama_cpp/server/settings.py

Copy file name to clipboardExpand all lines: llama_cpp/server/settings.py
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,10 @@ class ServerSettings(BaseSettings):
195195
default=True,
196196
description="Whether to interrupt requests when a new request is received.",
197197
)
198+
disable_ping_events: bool = Field(
199+
default=False,
200+
description="Disable EventSource pings (may be needed for some clients).",
201+
)
198202

199203

200204
class Settings(ServerSettings, ModelSettings):

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.