Skip to content

add disable_ping_events flag #1257

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions llama_cpp/server/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,13 @@ def get_llama_proxy():
llama_outer_lock.release()


_ping_message_factory = None

def set_ping_message_factory(factory):
global _ping_message_factory
_ping_message_factory = factory


def create_app(
settings: Settings | None = None,
server_settings: ServerSettings | None = None,
Expand Down Expand Up @@ -138,6 +145,9 @@ def create_app(
assert model_settings is not None
set_llama_proxy(model_settings=model_settings)

if server_settings.disable_ping_events:
set_ping_message_factory(lambda: bytes())

return app


Expand Down Expand Up @@ -302,6 +312,7 @@ def iterator() -> Iterator[llama_cpp.CreateCompletionStreamResponse]:
iterator=iterator(),
),
sep="\n",
ping_message_factory=_ping_message_factory,
)
else:
return iterator_or_completion
Expand Down Expand Up @@ -470,6 +481,7 @@ def iterator() -> Iterator[llama_cpp.ChatCompletionChunk]:
iterator=iterator(),
),
sep="\n",
ping_message_factory=_ping_message_factory,
)
else:
return iterator_or_completion
Expand Down
4 changes: 4 additions & 0 deletions llama_cpp/server/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,10 @@ class ServerSettings(BaseSettings):
default=True,
description="Whether to interrupt requests when a new request is received.",
)
disable_ping_events: bool = Field(
default=False,
description="Disable EventSource pings (may be needed for some clients).",
)


class Settings(ServerSettings, ModelSettings):
Expand Down
Loading