Skip to content

fix: do not assume streaming for ollama #640

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

Merged
merged 1 commit into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
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
6 changes: 2 additions & 4 deletions src/codegate/providers/ollama/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,8 @@ def normalize(self, data: Dict) -> ChatCompletionRequest:
{"content": normalized_data.pop("prompt"), "role": "user"}
]

# In Ollama force the stream to be True. Continue is not setting this parameter and
# most of our functionality is for streaming completions.
normalized_data["stream"] = True

# if we have the stream flag in data we set it, otherwise defaults to true
normalized_data["stream"] = data.get("stream", True)
return ChatCompletionRequest(**normalized_data)

def denormalize(self, data: ChatCompletionRequest) -> Dict:
Expand Down
4 changes: 2 additions & 2 deletions src/codegate/providers/ollama/completion_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def _create_streaming_response(self, stream: AsyncIterator[ChatResponse]) -> Str
"""
return StreamingResponse(
ollama_stream_generator(stream),
media_type="application/x-ndjson",
media_type="application/x-ndjson; charset=utf-8",
headers={
"Cache-Control": "no-cache",
"Connection": "keep-alive",
Expand All @@ -70,4 +70,4 @@ def _create_streaming_response(self, stream: AsyncIterator[ChatResponse]) -> Str
def _create_json_response(
self, response: Union[GenerateResponse, ChatResponse]
) -> JSONResponse:
return JSONResponse(content=response.model_dump_json(), status_code=200)
return JSONResponse(status_code=200, content=response.model_dump())
2 changes: 1 addition & 1 deletion src/codegate/providers/ollama/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ async def show_model(request: Request):
response = await client.post(
f"{self.base_url}/api/show",
content=body,
headers={"Content-Type": "application/json"},
headers={"Content-Type": "application/json; charset=utf-8"},
)
return response.json()

Expand Down
Loading