-
Notifications
You must be signed in to change notification settings - Fork 5
Feature/streaming responses #23
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
Feature/streaming responses #23
Conversation
- Updated the Rag.Generation.t type, so that the response field can be a stream/enumerable
- returns `{:error, "streaming"}` when evauating the rag triad of a streaming request. - added `keyword()` in the @SPEC for `generate_response` and the @callback for `generate_text` - Update the function clauses to consider the new `opts` argument. - added 2 tests. - A test in `rag/generation_test.exs` that confirms a stream response is returned. - A test in `rag/evaluation_test.exs` that ensures an error is returned when attempting to evaluate a streaming request
- Updated the test to raise the Streaming error.
@joelpaulkoch I think this is ready for a review so we can see if I am heading in the right direction. I am unsure about the evaluation test and what other behaviours I may need to update for the |
@W3NDO just want to let you know that I'll have a look at it tomorrow, thank you! |
@joelpaulkoch Sounds good. I should be available to make changes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This goes very much in the right direction, thank you!
I left some comments and we still have to implement the streaming in the providers, Rag.Ai.Nx
, Rag.Ai.OpenAI
, Rag.Ai.Cohere
.
Just let me know if you have further questions or need help with something.
- removed `.tool-versions` - updated code with changes requested. - working on implementing streaming in the providers `Rag.Ai.Nx`, `Rag.Ai.OpenAI` and `Rag.Ai.Cohere`
- removed .tool-versions locally and in the repo
@joelpaulkoch
What I was thinking is that in the |
Sorry, took me a while to respond. def generate_text(%__MODULE__{} = provider, prompt, _opts) when is_binary(prompt) do
%{results: [result]} =
Nx.Serving.batched_run(provider.text_serving, prompt)
{:ok, result.text}
rescue
error ->
{:error, error}
end When we're streaming we would receive only the stream from def generate_text(%__MODULE__{} = provider, prompt, _opts) when is_binary(prompt) do
case Nx.Serving.batched_run(provider.text_serving, prompt) do
%{results: [result]} -> {:ok, result.text}
stream -> {:ok, stream}
end
rescue
error ->
{:error, error}
end Regarding testing, at the moment we mock expect(Nx.Serving, :batched_run, fn _serving, prompt ->
assert prompt == "a prompt"
%{results: [%{text: "a response"}]}
end) We could do the same in a test for streaming but return a stream instead: expect(Nx.Serving, :batched_run, fn _serving, prompt ->
assert prompt == "a prompt"
Stream.take_while(["this", "is", "a", "stream"], &(&1))
end) |
@joelpaulkoch ,I will start working on this this week. |
- updating so I can work on this branch on a diferent host. Remember to squash this.y
- http streaming is failing - need help with the tests
@joelpaulkoch sorry this took a while. I ran into some issues with testing the streaming options for Cohere and OpenAI. Further I could not figure out how to get the nx test working. |
@joelpaulkoch we have 3 tests failing that I am unsure how to make pass. I have explained the issues I may be facing. |
Thank you a lot! I will have another look at the complete PR soon but I think it's basically ready to merge. |
{:error, "streaming"}
when evauating the rag triad of a streaming request.keyword()
in the@spec
forgenerate_response
and the@callback
forgenerate_text
opts
argument.- A test in
rag/generation_test.exs
that confirms a stream response is returned.- A test in
rag/evaluation_test.exs
that ensures an error is returned when attempting to evaluate a streaming request