Fix streaming chunk structure for Google GenAI

- Ensure complete chunk object is yielded as single unit
- Add logging to show complete chunk structure
- Fix issue where chunk was being serialized as separate fields
- Maintain OpenAI-compatible chat.completion.chunk format

This should fix the streaming issue where chunks were being
serialized as separate data: lines instead of complete
JSON objects.
parent 8360e33b
......@@ -193,7 +193,7 @@ class GoogleProviderHandler(BaseProviderHandler):
except Exception as e:
logging.error(f"Error extracting text from stream chunk: {e}")
# Create OpenAI-compatible chunk
# Create OpenAI-compatible chunk (complete object, not separate fields)
openai_chunk = {
"id": f"google-{model}-{int(time.time())}-chunk-{chunk_id}",
"object": "chat.completion.chunk",
......@@ -210,6 +210,7 @@ class GoogleProviderHandler(BaseProviderHandler):
chunk_id += 1
logging.info(f"Yielding OpenAI chunk: {openai_chunk}")
# Yield the complete chunk object as a single line
yield openai_chunk
except Exception as e:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment