From 0486d084de266a550ddc19bce7c8e130b13e1274 Mon Sep 17 00:00:00 2001 From: Andrei Bondarev Date: Tue, 16 May 2023 16:15:21 -0500 Subject: [PATCH 1/3] Bug fixes --- CHANGELOG.md | 3 +++ lib/llm/base.rb | 3 ++- lib/llm/hugging_face.rb | 9 +++++---- lib/version.rb | 2 +- spec/llm/hugging_face_spec.rb | 6 ++++++ spec/vectorsearch/base_spec.rb | 14 ++++++++++++-- 6 files changed, 29 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index baf252f58..7ee3e1381 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ ## [Unreleased] +## [0.3.5] - 2023-05-16 +- Bug fixes + ## [0.3.4] - 2023-05-16 - LLMs - Introducing support for HuggingFace diff --git a/lib/llm/base.rb b/lib/llm/base.rb index 09aa3b814..3d01a0915 100644 --- a/lib/llm/base.rb +++ b/lib/llm/base.rb @@ -8,7 +8,8 @@ class Base # TODO: Add support for HuggingFace and other LLMs LLMS = { openai: "OpenAI", - cohere: "Cohere" + cohere: "Cohere", + huggingface: "HuggingFace" }.freeze def default_dimension diff --git a/lib/llm/hugging_face.rb b/lib/llm/hugging_face.rb index a0c1ecadd..65ebac1bd 100644 --- a/lib/llm/hugging_face.rb +++ b/lib/llm/hugging_face.rb @@ -5,9 +5,11 @@ class HuggingFace < Base # The gem does not currently accept other models: # https://github.com/alchaplinsky/hugging-face/blob/main/lib/hugging_face/inference_api.rb#L32-L34 DEFAULTS = { - embeddings_model_name: "sentence-transformers/all-MiniLM-L6-v2" + temperature: 0.0, + embeddings_model_name: "sentence-transformers/all-MiniLM-L6-v2", + dimension: 384 # Vector size generated by the above model }.freeze - + # # Intialize the HuggingFace LLM # @param api_key [String] The API key to use @@ -24,8 +26,7 @@ def initialize(api_key:) # @return [Array] The embedding def embed(text:) response = client.embedding( - input: text, - model: DEFAULTS[:embeddings_model_name] + input: text ) end end diff --git a/lib/version.rb b/lib/version.rb index 06390998f..70dece287 100644 --- a/lib/version.rb +++ b/lib/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module Langchain - VERSION = "0.3.4" + VERSION = "0.3.5" end diff --git a/spec/llm/hugging_face_spec.rb b/spec/llm/hugging_face_spec.rb index c797c317c..453e4e79f 100644 --- a/spec/llm/hugging_face_spec.rb +++ b/spec/llm/hugging_face_spec.rb @@ -16,4 +16,10 @@ expect(subject.embed(text: "Hello World")).to eq([-1.5693359, -0.9458008, 1.9355469]) end end + + describe "#default_dimension" do + it "returns the default dimension" do + expect(subject.default_dimension).to eq(384) + end + end end \ No newline at end of file diff --git a/spec/vectorsearch/base_spec.rb b/spec/vectorsearch/base_spec.rb index b45c783e9..9c75f41bc 100644 --- a/spec/vectorsearch/base_spec.rb +++ b/spec/vectorsearch/base_spec.rb @@ -20,12 +20,22 @@ ).to be_a(LLM::OpenAI) end - it "throws an error with currently unsupported llm: :huggingface" do - expect { + it "correctly with llm: :huggingface" do + expect( described_class.new( llm: :huggingface, llm_api_key: "123" ) + .llm_client + ).to be_a(LLM::HuggingFace) + end + + it "throws an error with currently unsupported llm: :anthropic" do + expect { + described_class.new( + llm: :anthropic, + llm_api_key: "123" + ) }.to raise_error(ArgumentError) end end From 2c49124df7255b7c1fb20765fe4ae80e7f67327d Mon Sep 17 00:00:00 2001 From: Andrei Bondarev Date: Tue, 16 May 2023 16:27:13 -0500 Subject: [PATCH 2/3] standardrb fixes --- lib/llm/hugging_face.rb | 8 ++++---- spec/llm/hugging_face_spec.rb | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/llm/hugging_face.rb b/lib/llm/hugging_face.rb index 65ebac1bd..07c92799f 100644 --- a/lib/llm/hugging_face.rb +++ b/lib/llm/hugging_face.rb @@ -2,7 +2,7 @@ module LLM class HuggingFace < Base - # The gem does not currently accept other models: + # The gem does not currently accept other models: # https://github.com/alchaplinsky/hugging-face/blob/main/lib/hugging_face/inference_api.rb#L32-L34 DEFAULTS = { temperature: 0.0, @@ -10,10 +10,10 @@ class HuggingFace < Base dimension: 384 # Vector size generated by the above model }.freeze - # + # # Intialize the HuggingFace LLM # @param api_key [String] The API key to use - # + # def initialize(api_key:) depends_on "hugging-face" require "hugging_face" @@ -30,4 +30,4 @@ def embed(text:) ) end end -end \ No newline at end of file +end diff --git a/spec/llm/hugging_face_spec.rb b/spec/llm/hugging_face_spec.rb index 453e4e79f..109db331b 100644 --- a/spec/llm/hugging_face_spec.rb +++ b/spec/llm/hugging_face_spec.rb @@ -22,4 +22,4 @@ expect(subject.default_dimension).to eq(384) end end -end \ No newline at end of file +end From 8e43a222c04c955d2d8fcbf24e7281cd306a1c03 Mon Sep 17 00:00:00 2001 From: Andrei Bondarev Date: Tue, 16 May 2023 16:29:23 -0500 Subject: [PATCH 3/3] version bump --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index c6d9bd00c..bdeeb1c99 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - langchainrb (0.3.4) + langchainrb (0.3.5) GEM remote: https://rubygems.org/