Skip to content

Commit

Permalink
sanitize completions content (#129)
Browse files Browse the repository at this point in the history
  • Loading branch information
roman-romanov-o authored Jul 3, 2024
1 parent eac6acd commit d1cce78
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion aidial_adapter_openai/completions.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,20 @@
)


def sanitize_text(text: str) -> str:
return text.replace("<|endoftext|>", "")


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

0 comments on commit d1cce78

Please sign in to comment.