Skip to content

Update proxy.go to add streaming response - #1

Open
Lacuranas wants to merge 1 commit into
postula:mainfrom
Lacuranas:patch-1
Open

Update proxy.go to add streaming response#1
Lacuranas wants to merge 1 commit into
postula:mainfrom
Lacuranas:patch-1

Conversation

@Lacuranas

Copy link
Copy Markdown

Changes:
Replaced io.ReadAll() in ServeHTTP with a chunked reading loop.
Implemented io.MultiWriter to simultaneously stream the response to the client and copy it into a local buffer for metric extraction.
Added http.Flusher support to ensure that chunks are pushed to the client immediately without being buffered by Go's HTTP server.
Metrics are now extracted from the accumulated buffer after the stream has finished, maintaining compatibility with existing extractMetrics logic.

Impact:
Users can now experience real-time token streaming (the "typing" effect) while the proxy continues to track token usage and latency for Prometheus metrics in the background.

Changes:
    Replaced io.ReadAll() in ServeHTTP with a chunked reading loop.
    Implemented io.MultiWriter to simultaneously stream the response to the client and copy it into a local buffer for metric extraction.
    Added http.Flusher support to ensure that chunks are pushed to the client immediately without being buffered by Go's HTTP server.
    Metrics are now extracted from the accumulated buffer after the stream has finished, maintaining compatibility with existing extractMetrics logic.

Impact:
Users can now experience real-time token streaming (the "typing" effect) while the proxy continues to track token usage and latency for Prometheus metrics in the background.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant