-
-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add embedding method for Langchain::LLM::GoogleGemini (#631)
* Add embedding method for Langchain::LLM::GoogleGemini * Fix rubocop violation * Use dummy value for api key in tests
- Loading branch information
Showing
5 changed files
with
122 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"embedding": { | ||
"values": [ | ||
0.013168523, | ||
-0.008711934, | ||
-0.046782676 | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# frozen_string_literal: true | ||
|
||
RSpec.describe Langchain::LLM::GoogleGemini do | ||
let(:subject) { described_class.new(api_key: "123") } | ||
|
||
describe "#embed" do | ||
let(:embedding) { [0.013168523, -0.008711934, -0.046782676] } | ||
let(:raw_embedding_response) { double(body: File.read("spec/fixtures/llm/google_gemini/embed.json")) } | ||
|
||
before do | ||
allow(Net::HTTP).to receive(:start).and_return(raw_embedding_response) | ||
end | ||
|
||
it "returns valid llm response object" do | ||
response = subject.embed(text: "Hello world") | ||
|
||
expect(response).to be_a(Langchain::LLM::GoogleGeminiResponse) | ||
expect(response.model).to eq("text-embedding-004") | ||
expect(response.embedding).to eq(embedding) | ||
end | ||
end | ||
|
||
describe "#chat" do | ||
let(:messages) { [{role: "user", parts: [{text: "How high is the sky?"}]}] } | ||
let(:raw_chat_completions_response) { double(body: File.read("spec/fixtures/llm/google_gemini/chat.json")) } | ||
|
||
before do | ||
allow(Net::HTTP).to receive(:start).and_return(raw_chat_completions_response) | ||
end | ||
|
||
it "returns valid llm response object" do | ||
response = subject.chat(messages: messages) | ||
|
||
expect(response).to be_a(Langchain::LLM::GoogleGeminiResponse) | ||
expect(response.model).to eq("gemini-1.5-pro-latest") | ||
expect(response.chat_completion).to eq("The answer is 4.0") | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters