Skip to content

Commit

Permalink
Merge pull request #14 from andreibondarev/bug-fixes
Browse files Browse the repository at this point in the history
Bug fixes
  • Loading branch information
andreibondarev authored May 16, 2023
2 parents 1ad8c2c + 8e43a22 commit 99120b5
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 14 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
## [Unreleased]

## [0.3.5] - 2023-05-16
- Bug fixes

## [0.3.4] - 2023-05-16
- LLMs
- Introducing support for HuggingFace
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.3.4)
langchainrb (0.3.5)

GEM
remote: https://rubygems.org/
Expand Down
3 changes: 2 additions & 1 deletion lib/llm/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 9 additions & 8 deletions lib/llm/hugging_face.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@

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 = {
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
#
#
def initialize(api_key:)
depends_on "hugging-face"
require "hugging_face"
Expand All @@ -24,9 +26,8 @@ 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
end
end
2 changes: 1 addition & 1 deletion lib/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Langchain
VERSION = "0.3.4"
VERSION = "0.3.5"
end
8 changes: 7 additions & 1 deletion spec/llm/hugging_face_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,10 @@
expect(subject.embed(text: "Hello World")).to eq([-1.5693359, -0.9458008, 1.9355469])
end
end
end

describe "#default_dimension" do
it "returns the default dimension" do
expect(subject.default_dimension).to eq(384)
end
end
end
14 changes: 12 additions & 2 deletions spec/vectorsearch/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 99120b5

Please sign in to comment.