Skip to content
This repository was archived by the owner on Jun 5, 2025. It is now read-only.

Fix FIM pipeline with copilot #362

Merged
merged 2 commits into from
Dec 16, 2024
Merged
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
19 changes: 11 additions & 8 deletions src/codegate/providers/copilot/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -575,13 +575,6 @@ def _ensure_output_processor(self) -> None:
# Already initialized, no need to reinitialize
return

# this is a hotfix - we shortcut before selecting the output pipeline for FIM
# because our FIM output pipeline is actually empty as of now. We should fix this
# but don't have any immediate need.
is_fim = self.proxy.context_tracking.metadata.get("is_fim", False)
if is_fim:
return

logger.debug("Tracking context for pipeline processing")
self.sse_processor = SSEProcessor()
is_fim = self.proxy.context_tracking.metadata.get("is_fim", False)
Expand All @@ -601,16 +594,23 @@ async def _process_stream(self):
async def stream_iterator():
while True:
incoming_record = await self.stream_queue.get()

record_content = incoming_record.get("content", {})

streaming_choices = []
for choice in record_content.get("choices", []):
is_fim = self.proxy.context_tracking.metadata.get("is_fim", False)
if is_fim:
content = choice.get("text", "")
else:
content = choice.get("delta", {}).get("content")

streaming_choices.append(
StreamingChoices(
finish_reason=choice.get("finish_reason", None),
index=0,
delta=Delta(
content=choice.get("delta", {}).get("content"), role="assistant"
content=content, role="assistant"
),
logprobs=None,
)
Expand Down Expand Up @@ -658,6 +658,9 @@ def _process_chunk(self, chunk: bytes):
self.stream_queue.put_nowait(record)

def _proxy_transport_write(self, data: bytes):
if not self.proxy.transport or self.proxy.transport.is_closing():
logger.error("Proxy transport not available")
return
self.proxy.transport.write(data)

def data_received(self, data: bytes) -> None:
Expand Down
Loading