Skip to content

Commit

Permalink
0.15.6 (#781)
Browse files Browse the repository at this point in the history
* Resetting instructions on Langchain::Assistant with Google VertexAI no longer throws an error.

* 0.15.6

* fix specs
  • Loading branch information
andreibondarev authored Sep 16, 2024
1 parent 4e6c274 commit e5550e2
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 6 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
## [Unreleased]

## [0.15.4] - 2024-09-10 🇧🇦
## [0.15.6] - 2024-09-16
- Throw an error when `Langchain::Assistant#add_message_callback` is not a callable proc.
- Resetting instructions on Langchain::Assistant with Google Gemini no longer throws an error.
- Add Meta models support for AWS Bedrock LLM

## [0.15.5] - 2024-09-10 🇧🇦
- Fix for Langchain::Prompt::PromptTemplate supporting nested JSON data
- Require common libs at top-level
- Add `add_message_callback` to `Langchain::Assistant` constructor to invoke an optional function when any message is added to the conversation
Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
langchainrb (0.15.5)
langchainrb (0.15.6)
baran (~> 0.1.9)
json-schema (~> 4)
matrix
Expand Down
4 changes: 3 additions & 1 deletion lib/langchain/assistants/assistant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,9 @@ def instructions=(new_instructions)
@instructions = new_instructions

# This only needs to be done that support Message#@role="system"
if !llm.is_a?(Langchain::LLM::GoogleGemini) && !llm.is_a?(Langchain::LLM::Anthropic)
if !llm.is_a?(Langchain::LLM::GoogleGemini) &&
!llm.is_a?(Langchain::LLM::GoogleVertexAI) &&
!llm.is_a?(Langchain::LLM::Anthropic)
# Find message with role: "system" in thread.messages and delete it from the thread.messages array
replace_system_message!(content: new_instructions)
end
Expand Down
2 changes: 0 additions & 2 deletions lib/langchain/llm/google_vertex_ai.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,6 @@ def embed(
def chat(params = {})
params[:system] = {parts: [{text: params[:system]}]} if params[:system]
params[:tools] = {function_declarations: params[:tools]} if params[:tools]
# This throws an error when tool_choice is passed
# params[:tool_choice] = {function_calling_config: {mode: params[:tool_choice].upcase}} if params[:tool_choice]

raise ArgumentError.new("messages argument is required") if Array(params[:messages]).empty?

Expand Down
2 changes: 1 addition & 1 deletion lib/langchain/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Langchain
VERSION = "0.15.5"
VERSION = "0.15.6"
end
28 changes: 28 additions & 0 deletions spec/langchain/assistants/assistant_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

require "googleauth"

RSpec.describe Langchain::Assistant do
context "initialization" do
let(:llm) { Langchain::LLM::OpenAI.new(api_key: "123") }
Expand Down Expand Up @@ -756,6 +758,32 @@
end
end

context "when llm is GoogleVertexAI" do
let(:llm) { Langchain::LLM::GoogleVertexAI.new(project_id: "123", region: "us-central1") }
let(:calculator) { Langchain::Tool::Calculator.new }
let(:instructions) { "You are an expert assistant" }

before do
allow(::Google::Auth).to receive(:get_application_default).and_return({})
end

subject {
described_class.new(
llm: llm,
tools: [calculator],
instructions: instructions
)
}

describe "#instructions=" do
it "resets instructions" do
subject.instructions = "New instructions"
expect(subject).not_to receive(:replace_system_message!)
expect(subject.instructions).to eq("New instructions")
end
end
end

context "when llm is GoogleGemini" do
let(:llm) { Langchain::LLM::GoogleGemini.new(api_key: "123") }
let(:calculator) { Langchain::Tool::Calculator.new }
Expand Down

0 comments on commit e5550e2

Please sign in to comment.