From 0164660ce4674f1830263e2383407d3af53086ab Mon Sep 17 00:00:00 2001 From: Rinas <5433320+onerinas@users.noreply.github.com> Date: Fri, 23 Feb 2024 18:53:22 +0400 Subject: [PATCH 1/2] Prototype streaming in Assistants --- lib/langchain/assistants/assistant.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/langchain/assistants/assistant.rb b/lib/langchain/assistants/assistant.rb index 829ed699c..2ae425ffa 100644 --- a/lib/langchain/assistants/assistant.rb +++ b/lib/langchain/assistants/assistant.rb @@ -16,6 +16,7 @@ def initialize( thread:, tools: [], instructions: nil + &block ) raise ArgumentError, "Invalid LLM; currently only Langchain::LLM::OpenAI is supported" unless llm.instance_of?(Langchain::LLM::OpenAI) raise ArgumentError, "Thread must be an instance of Langchain::Thread" unless thread.is_a?(Langchain::Thread) @@ -25,6 +26,7 @@ def initialize( @thread = thread @tools = tools @instructions = instructions + @block = block # The first message in the thread should be the system instructions # TODO: What if the user added old messages and the system instructions are already in there? Should this overwrite the existing instructions? @@ -132,7 +134,7 @@ def chat_with_llm params[:tool_choice] = "auto" end - llm.chat(**params) + llm.chat(**params, &@block) end # Run the tools automatically From 078909d26ba855e76bf62028683a8ebb458c17dd Mon Sep 17 00:00:00 2001 From: Andrei Bondarev Date: Fri, 23 Feb 2024 10:21:01 -0500 Subject: [PATCH 2/2] Adding missing semicolon --- lib/langchain/assistants/assistant.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/langchain/assistants/assistant.rb b/lib/langchain/assistants/assistant.rb index 2ae425ffa..0e5d715b5 100644 --- a/lib/langchain/assistants/assistant.rb +++ b/lib/langchain/assistants/assistant.rb @@ -15,7 +15,7 @@ def initialize( llm:, thread:, tools: [], - instructions: nil + instructions: nil, &block ) raise ArgumentError, "Invalid LLM; currently only Langchain::LLM::OpenAI is supported" unless llm.instance_of?(Langchain::LLM::OpenAI)