Skip to content

Commit

Permalink
Fix delta field (#127)
Browse files Browse the repository at this point in the history
  • Loading branch information
roman-romanov-o authored Jun 28, 2024
1 parent bfa0f34 commit eac6acd
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions aidial_adapter_openai/completions.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,26 @@
)
from aidial_adapter_openai.utils.reflection import call_with_extra_body
from aidial_adapter_openai.utils.sse_stream import to_openai_sse_stream
from aidial_adapter_openai.utils.streaming import build_chunk, map_stream
from aidial_adapter_openai.utils.streaming import (
build_chunk,
debug_print,
map_stream,
)


def convert_to_chat_completions_response(
chunk: Completion, is_stream: bool
) -> Dict[str, Any]:
return build_chunk(
converted_chunk = build_chunk(
id=chunk.id,
finish_reason=chunk.choices[0].finish_reason,
delta=chunk.choices[0].text,
delta={"content": chunk.choices[0].text, "role": "assistant"},
created=str(chunk.created),
is_stream=is_stream,
usage=chunk.usage.to_dict() if chunk.usage else None,
)
debug_print("response", converted_chunk)
return converted_chunk


async def chat_completion(
Expand Down Expand Up @@ -76,7 +82,8 @@ async def chat_completion(
),
response,
)
)
),
media_type="text/event-stream",
)
else:
return JSONResponse(
Expand Down

0 comments on commit eac6acd

Please sign in to comment.