diff --git a/aidial_adapter_openai/completions.py b/aidial_adapter_openai/completions.py index bd8c2b7..b6b7704 100644 --- a/aidial_adapter_openai/completions.py +++ b/aidial_adapter_openai/completions.py @@ -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,