Class: InstLLM::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/inst_llm/client.rb

Constant Summary collapse

MODELS =
{
  "anthropic.claude-3-sonnet-20240229-v1:0": { format: :claude, provider: :bedrock, type: :chat },
  "anthropic.claude-3-haiku-20240307-v1:0": { format: :claude, provider: :bedrock, type: :chat },
  "anthropic.claude-3-opus-20240229-v1:0": { format: :claude, provider: :bedrock, type: :chat },

  "meta.llama3-8b-instruct-v1:0": { format: :llama3, provider: :bedrock, type: :chat },
  "meta.llama3-70b-instruct-v1:0": { format: :llama3, provider: :bedrock, type: :chat },

  "mistral.mistral-7b-instruct-v0:2": { format: :mistral, provider: :bedrock, type: :chat },
  "mistral.mixtral-8x7b-instruct-v0:1": { format: :mistral, provider: :bedrock, type: :chat },
  "mistral.mistral-large-2402-v1:0": { format: :mistral, provider: :bedrock, type: :chat },

  "cohere.embed-english-v3": { format: :cohere_embed, provider: :bedrock, type: :embedding },
  "cohere.embed-multilingual-v3": { format: :cohere_embed, provider: :bedrock, type: :embedding },
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(model, **options) ⇒ Client

Returns a new instance of Client.



27
28
29
30
31
32
33
# File 'lib/inst_llm/client.rb', line 27

def initialize(model, **options)
  model = model.to_sym
  raise UnknownArgumentError unless MODELS.key?(model)

  @model = model
  @options = options
end

Instance Method Details

#chat(messages, **options) ⇒ Object

Raises:

  • (ArgumentError)


35
36
37
38
39
40
# File 'lib/inst_llm/client.rb', line 35

def chat(messages, **options)
  model = (options[:model] || options[:model_id] || @model).to_sym
  raise ArgumentError, "Model #{model} is not a chat model" unless chat_model?(model)

  response_factory(model, call(model, messages, **options))
end

#embedding(message, **options) ⇒ Object

Raises:

  • (ArgumentError)


42
43
44
45
46
47
# File 'lib/inst_llm/client.rb', line 42

def embedding(message, **options)
  model = (options[:model] || options[:model_id] || @model).to_sym
  raise ArgumentError, "Model #{model} is not an embedding model" unless embedding_model?(model)

  embedding_response_factory(model, call(model, message, **options))
end