Skip to content
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

Update media type and JSON handling in OpenAISpec #360

Merged
merged 3 commits into from
Nov 11, 2024
Merged
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
10 changes: 5 additions & 5 deletions src/litserve/specs/openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ async def chat_completion(self, request: ChatCompletionRequest, background_tasks
if request.stream:
return StreamingResponse(
self.streaming_completion(request, responses),
media_type="application/x-ndjson",
media_type="text/event-stream",
background=background_tasks,
)

Expand Down Expand Up @@ -394,9 +394,9 @@ async def streaming_completion(self, request: ChatCompletionRequest, pipe_respon

# Only use the last item from encode_response
usage_info = sum(usage_infos)
chunk = ChatCompletionChunk(model=model, choices=choices, usage=None).json()
chunk = ChatCompletionChunk(model=model, choices=choices, usage=None)
logger.debug(chunk)
yield f"data: {chunk}\n\n"
yield f"data: {chunk.model_dump_json()}\n\n"

choices = [
ChatCompletionStreamingChoice(
Expand All @@ -410,8 +410,8 @@ async def streaming_completion(self, request: ChatCompletionRequest, pipe_respon
model=model,
choices=choices,
usage=usage_info,
).json()
yield f"data: {last_chunk}\n\n"
)
yield f"data: {last_chunk.model_dump_json()}\n\n"
yield "data: [DONE]\n\n"

async def non_streaming_completion(self, request: ChatCompletionRequest, generator_list: List[AsyncGenerator]):
Expand Down
Loading