Skip to content

Return response from streamed request to Anthropic

Nicolas Dular requested to merge nd/return-anthropic-stream into master

What does this MR do and why?

Return response from streamed request to Anthropic

This accumulates the response we get from a streamed request to Anthropic and returns it as one string.

This is helpful as we need the full response when broadcasting the messages from chat.

The tests were not correct as the streamed response contained one additional \n.

It also fixes how we parse the SSE as it's not guaranteed that we receive only one SSE from the HTTP.post yield.

Screenshots or screen recordings

Screenshots are required for UI changes, and strongly recommended for all other merge requests.

Before After

How to set up and validate locally

a = Gitlab::Llm::Anthropic::Client.new(User.first).stream(prompt: "What is 1+1?") do |e|
end

puts a

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Nicolas Dular

Merge request reports