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 cfb7da9

Browse filesBrowse files
aniljavaAnil Pathakabetlen
authored
Support Accept text/event-stream in chat and completion endpoints, resolves abetlen#1083 (abetlen#1088)
Co-authored-by: Anil Pathak <anil@heyday.com> Co-authored-by: Andrei Betlen <abetlen@gmail.com>
1 parent e39778f commit cfb7da9
Copy full SHA for cfb7da9

File tree

Expand file treeCollapse file tree

1 file changed

+57
-2
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+57
-2
lines changed

‎llama_cpp/server/app.py

Copy file name to clipboardExpand all lines: llama_cpp/server/app.py
+57-2Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,36 @@ async def authenticate(
197197

198198

199199
@router.post(
200-
"/v1/completions", summary="Completion", dependencies=[Depends(authenticate)]
200+
"/v1/completions",
201+
summary="Completion",
202+
dependencies=[Depends(authenticate)],
203+
response_model= Union[
204+
llama_cpp.CreateCompletionResponse,
205+
str,
206+
],
207+
responses={
208+
"200": {
209+
"description": "Successful Response",
210+
"content": {
211+
"application/json": {
212+
"schema": {
213+
"anyOf": [
214+
{"$ref": "#/components/schemas/CreateCompletionResponse"}
215+
],
216+
"title": "Completion response, when stream=False",
217+
}
218+
},
219+
"text/event-stream":{
220+
"schema": {
221+
"type": "string",
222+
"title": "Server Side Streaming response, when stream=True. " +
223+
"See SSE format: https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format", # noqa: E501
224+
"example": """data: {... see CreateCompletionResponse ...} \\n\\n data: ... \\n\\n ... data: [DONE]"""
225+
}
226+
}
227+
},
228+
}
229+
},
201230
)
202231
@router.post(
203232
"/v1/engines/copilot-codex/completions",
@@ -280,7 +309,33 @@ async def create_embedding(
280309

281310

282311
@router.post(
283-
"/v1/chat/completions", summary="Chat", dependencies=[Depends(authenticate)]
312+
"/v1/chat/completions", summary="Chat", dependencies=[Depends(authenticate)],
313+
response_model= Union[
314+
llama_cpp.ChatCompletion, str
315+
],
316+
responses={
317+
"200": {
318+
"description": "Successful Response",
319+
"content": {
320+
"application/json": {
321+
"schema": {
322+
"anyOf": [
323+
{"$ref": "#/components/schemas/CreateChatCompletionResponse"}
324+
],
325+
"title": "Completion response, when stream=False",
326+
}
327+
},
328+
"text/event-stream":{
329+
"schema": {
330+
"type": "string",
331+
"title": "Server Side Streaming response, when stream=True" +
332+
"See SSE format: https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format", # noqa: E501
333+
"example": """data: {... see CreateChatCompletionResponse ...} \\n\\n data: ... \\n\\n ... data: [DONE]"""
334+
}
335+
}
336+
},
337+
}
338+
},
284339
)
285340
async def create_chat_completion(
286341
request: Request,

0 commit comments

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