Skip to content
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

Stream chat response in Assistants #484

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

onerinas
Copy link
Contributor

@onerinas onerinas commented Feb 23, 2024

This PR is an attempt to make streaming working in Assistants.

Feel free to create a new PR or push to the same branch if you want to try different implemention.

With the current changes, usage looks like this:

llm = Langchain::LLM::OpenAI.new(api_key: ENV["OPENAI_API_KEY"])

thread = Langchain::Thread.new

Langchain::Assistant.new(llm: llm, thread: thread) do |response_chunk|
  print(response_chunk["delta"]["content"])
end

Screenshot of the same logged in a Sidekiq worker:
Screenshot 2024-02-23 at 7 07 54 PM

@onerinas onerinas changed the title Prototype streaming in Assistants Stream chat response in Assistants Feb 23, 2024
@andreibondarev
Copy link
Collaborator

@onerinas Looks like it works for streaming tool_calls as well if you yield:

print(response_chunk["delta"]["tool_calls"])

Are you planning on finishing this PR?

@onerinas
Copy link
Contributor Author

@andreibondarev That’s good to know it works for tool_calls as well.

What would be the next steps to make some progress on the PR? I assume these?

  • yield in tool_calls
  • Update usage of Assistant in the methods docs and README
  • Specs

I can give it a try. I’m okay with you picking it up as well if you want.

@andreibondarev
Copy link
Collaborator

@onerinas Go for it!

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.

None yet

2 participants