Skip to content

Commit cf2bafd

Browse files
Shorter model name params (#840)
* rename chat_completion_model_name -> chat_model and completion_model_name -> completion_model * update readme * update changelog * bump version * update gemfile.lock * fix nits * rename embeddings_model_name -> embed_model * rename completion_model -> complete_model * update changelog * changelog md formatting * Update Gemfile.lock * Update CHANGELOG.md * Renaming the parameters * Update version.rb --------- Co-authored-by: Andrei Bondarev <[email protected]> Co-authored-by: Andrei Bondarev <[email protected]>
1 parent 8091e54 commit cf2bafd

26 files changed

+106
-103
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
- [SECURITY]: A change which fixes a security vulnerability.
1111

1212
## [Unreleased]
13+
- [BREAKING] [https://github.com/patterns-ai-core/langchainrb/pull/840] Rename `chat_completion_model_name` parameter to `chat_model` in Langchain::LLM parameters.
14+
- [BREAKING] [https://github.com/patterns-ai-core/langchainrb/pull/840] Rename `completion_model_name` parameter to `completion_model` in Langchain::LLM parameters.
15+
- [BREAKING] [https://github.com/patterns-ai-core/langchainrb/pull/840] Rename `embeddings_model_name` parameter to `embedding_model` in Langchain::LLM parameters.
1316
- [BUGFIX] [https://github.com/patterns-ai-core/langchainrb/pull/850/] Fix MistralAIMessage to handle "Tool" Output
1417
- [BUGFIX] [https://github.com/patterns-ai-core/langchainrb/pull/837] Fix bug when tool functions with no input variables are used with Langchain::LLM::Anthropic
1518
- [BUGFIX] [https://github.com/patterns-ai-core/langchainrb/pull/836] Fix bug when assistant.instructions = nil did not remove the system message

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ Most LLM classes can be initialized with an API key and optional default options
8686
```ruby
8787
llm = Langchain::LLM::OpenAI.new(
8888
api_key: ENV["OPENAI_API_KEY"],
89-
default_options: { temperature: 0.7, chat_completion_model_name: "gpt-4o" }
89+
default_options: { temperature: 0.7, chat_model: "gpt-4o" }
9090
)
9191
```
9292

examples/openai_qdrant_function_calls.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
openai = Langchain::LLM::OpenAI.new(
2222
api_key: ENV["OPENAI_API_KEY"],
2323
default_options: {
24-
chat_completion_model_name: "gpt-3.5-turbo-16k"
24+
chat_model: "gpt-3.5-turbo-16k"
2525
}
2626
)
2727

lib/langchain/llm/anthropic.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,24 @@ module Langchain::LLM
1313
class Anthropic < Base
1414
DEFAULTS = {
1515
temperature: 0.0,
16-
completion_model_name: "claude-2.1",
17-
chat_completion_model_name: "claude-3-5-sonnet-20240620",
16+
completion_model: "claude-2.1",
17+
chat_model: "claude-3-5-sonnet-20240620",
1818
max_tokens_to_sample: 256
1919
}.freeze
2020

2121
# Initialize an Anthropic LLM instance
2222
#
2323
# @param api_key [String] The API key to use
2424
# @param llm_options [Hash] Options to pass to the Anthropic client
25-
# @param default_options [Hash] Default options to use on every call to LLM, e.g.: { temperature:, completion_model_name:, chat_completion_model_name:, max_tokens_to_sample: }
25+
# @param default_options [Hash] Default options to use on every call to LLM, e.g.: { temperature:, completion_model:, chat_model:, max_tokens_to_sample: }
2626
# @return [Langchain::LLM::Anthropic] Langchain::LLM::Anthropic instance
2727
def initialize(api_key:, llm_options: {}, default_options: {})
2828
depends_on "anthropic"
2929

3030
@client = ::Anthropic::Client.new(access_token: api_key, **llm_options)
3131
@defaults = DEFAULTS.merge(default_options)
3232
chat_parameters.update(
33-
model: {default: @defaults[:chat_completion_model_name]},
33+
model: {default: @defaults[:chat_model]},
3434
temperature: {default: @defaults[:temperature]},
3535
max_tokens: {default: @defaults[:max_tokens_to_sample]},
3636
metadata: {},
@@ -54,7 +54,7 @@ def initialize(api_key:, llm_options: {}, default_options: {})
5454
# @return [Langchain::LLM::AnthropicResponse] The completion
5555
def complete(
5656
prompt:,
57-
model: @defaults[:completion_model_name],
57+
model: @defaults[:completion_model],
5858
max_tokens_to_sample: @defaults[:max_tokens_to_sample],
5959
stop_sequences: nil,
6060
temperature: @defaults[:temperature],

lib/langchain/llm/aws_bedrock.rb

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ module Langchain::LLM
1111
#
1212
class AwsBedrock < Base
1313
DEFAULTS = {
14-
chat_completion_model_name: "anthropic.claude-v2",
15-
completion_model_name: "anthropic.claude-v2",
16-
embeddings_model_name: "amazon.titan-embed-text-v1",
14+
chat_model: "anthropic.claude-v2",
15+
completion_model: "anthropic.claude-v2",
16+
embedding_model: "amazon.titan-embed-text-v1",
1717
max_tokens_to_sample: 300,
1818
temperature: 1,
1919
top_k: 250,
@@ -60,7 +60,7 @@ def initialize(aws_client_options: {}, default_options: {})
6060
@defaults = DEFAULTS.merge(default_options)
6161

6262
chat_parameters.update(
63-
model: {default: @defaults[:chat_completion_model_name]},
63+
model: {default: @defaults[:chat_model]},
6464
temperature: {},
6565
max_tokens: {default: @defaults[:max_tokens_to_sample]},
6666
metadata: {},
@@ -84,7 +84,7 @@ def embed(text:, **params)
8484
parameters = compose_embedding_parameters params.merge(text:)
8585

8686
response = client.invoke_model({
87-
model_id: @defaults[:embeddings_model_name],
87+
model_id: @defaults[:embedding_model],
8888
body: parameters.to_json,
8989
content_type: "application/json",
9090
accept: "application/json"
@@ -103,14 +103,14 @@ def embed(text:, **params)
103103
def complete(prompt:, **params)
104104
raise "Completion provider #{completion_provider} is not supported." unless SUPPORTED_COMPLETION_PROVIDERS.include?(completion_provider)
105105

106-
raise "Model #{@defaults[:completion_model_name]} only supports #chat." if @defaults[:completion_model_name].include?("claude-3")
106+
raise "Model #{@defaults[:completion_model]} only supports #chat." if @defaults[:completion_model].include?("claude-3")
107107

108108
parameters = compose_parameters params
109109

110110
parameters[:prompt] = wrap_prompt prompt
111111

112112
response = client.invoke_model({
113-
model_id: @defaults[:completion_model_name],
113+
model_id: @defaults[:completion_model],
114114
body: parameters.to_json,
115115
content_type: "application/json",
116116
accept: "application/json"
@@ -126,7 +126,7 @@ def complete(prompt:, **params)
126126
# @param [Hash] params unified chat parmeters from [Langchain::LLM::Parameters::Chat::SCHEMA]
127127
# @option params [Array<String>] :messages The messages to generate a completion for
128128
# @option params [String] :system The system prompt to provide instructions
129-
# @option params [String] :model The model to use for completion defaults to @defaults[:chat_completion_model_name]
129+
# @option params [String] :model The model to use for completion defaults to @defaults[:chat_model]
130130
# @option params [Integer] :max_tokens The maximum number of tokens to generate defaults to @defaults[:max_tokens_to_sample]
131131
# @option params [Array<String>] :stop The stop sequences to use for completion
132132
# @option params [Array<String>] :stop_sequences The stop sequences to use for completion
@@ -175,11 +175,11 @@ def chat(params = {}, &block)
175175
private
176176

177177
def completion_provider
178-
@defaults[:completion_model_name].split(".").first.to_sym
178+
@defaults[:completion_model].split(".").first.to_sym
179179
end
180180

181181
def embedding_provider
182-
@defaults[:embeddings_model_name].split(".").first.to_sym
182+
@defaults[:embedding_model].split(".").first.to_sym
183183
end
184184

185185
def wrap_prompt(prompt)

lib/langchain/llm/azure.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def initialize(
3333
)
3434
@defaults = DEFAULTS.merge(default_options)
3535
chat_parameters.update(
36-
model: {default: @defaults[:chat_completion_model_name]},
36+
model: {default: @defaults[:chat_model]},
3737
logprobs: {},
3838
top_logprobs: {},
3939
n: {default: @defaults[:n]},

lib/langchain/llm/base.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def default_dimension
3434
default_dimensions
3535
end
3636

37-
# Returns the number of vector dimensions used by DEFAULTS[:chat_completion_model_name]
37+
# Returns the number of vector dimensions used by DEFAULTS[:chat_model]
3838
#
3939
# @return [Integer] Vector dimensions
4040
def default_dimensions

lib/langchain/llm/cohere.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ module Langchain::LLM
1313
class Cohere < Base
1414
DEFAULTS = {
1515
temperature: 0.0,
16-
completion_model_name: "command",
17-
chat_completion_model_name: "command-r-plus",
18-
embeddings_model_name: "small",
16+
completion_model: "command",
17+
chat_model: "command-r-plus",
18+
embedding_model: "small",
1919
dimensions: 1024,
2020
truncate: "START"
2121
}.freeze
@@ -26,7 +26,7 @@ def initialize(api_key:, default_options: {})
2626
@client = ::Cohere::Client.new(api_key: api_key)
2727
@defaults = DEFAULTS.merge(default_options)
2828
chat_parameters.update(
29-
model: {default: @defaults[:chat_completion_model_name]},
29+
model: {default: @defaults[:chat_model]},
3030
temperature: {default: @defaults[:temperature]},
3131
response_format: {default: @defaults[:response_format]}
3232
)
@@ -48,10 +48,10 @@ def initialize(api_key:, default_options: {})
4848
def embed(text:)
4949
response = client.embed(
5050
texts: [text],
51-
model: @defaults[:embeddings_model_name]
51+
model: @defaults[:embedding_model]
5252
)
5353

54-
Langchain::LLM::CohereResponse.new response, model: @defaults[:embeddings_model_name]
54+
Langchain::LLM::CohereResponse.new response, model: @defaults[:embedding_model]
5555
end
5656

5757
#
@@ -65,7 +65,7 @@ def complete(prompt:, **params)
6565
default_params = {
6666
prompt: prompt,
6767
temperature: @defaults[:temperature],
68-
model: @defaults[:completion_model_name],
68+
model: @defaults[:completion_model],
6969
truncate: @defaults[:truncate]
7070
}
7171

@@ -76,7 +76,7 @@ def complete(prompt:, **params)
7676
default_params.merge!(params)
7777

7878
response = client.generate(**default_params)
79-
Langchain::LLM::CohereResponse.new response, model: @defaults[:completion_model_name]
79+
Langchain::LLM::CohereResponse.new response, model: @defaults[:completion_model]
8080
end
8181

8282
# Generate a chat completion for given messages

lib/langchain/llm/google_gemini.rb

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ module Langchain::LLM
55
# llm = Langchain::LLM::GoogleGemini.new(api_key: ENV['GOOGLE_GEMINI_API_KEY'])
66
class GoogleGemini < Base
77
DEFAULTS = {
8-
chat_completion_model_name: "gemini-1.5-pro-latest",
9-
embeddings_model_name: "text-embedding-004",
8+
chat_model: "gemini-1.5-pro-latest",
9+
embedding_model: "text-embedding-004",
1010
temperature: 0.0
1111
}
1212

@@ -17,7 +17,7 @@ def initialize(api_key:, default_options: {})
1717
@defaults = DEFAULTS.merge(default_options)
1818

1919
chat_parameters.update(
20-
model: {default: @defaults[:chat_completion_model_name]},
20+
model: {default: @defaults[:chat_model]},
2121
temperature: {default: @defaults[:temperature]},
2222
generation_config: {default: nil},
2323
safety_settings: {default: @defaults[:safety_settings]}
@@ -72,9 +72,8 @@ def chat(params = {})
7272

7373
def embed(
7474
text:,
75-
model: @defaults[:embeddings_model_name]
75+
model: @defaults[:embedding_model]
7676
)
77-
7877
params = {
7978
content: {
8079
parts: [

lib/langchain/llm/google_vertex_ai.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ class GoogleVertexAI < Base
1717
top_p: 0.8,
1818
top_k: 40,
1919
dimensions: 768,
20-
embeddings_model_name: "textembedding-gecko",
21-
chat_completion_model_name: "gemini-1.0-pro"
20+
embedding_model: "textembedding-gecko",
21+
chat_model: "gemini-1.0-pro"
2222
}.freeze
2323

2424
# Google Cloud has a project id and a specific region of deployment.
@@ -38,7 +38,7 @@ def initialize(project_id:, region:, default_options: {})
3838
@defaults = DEFAULTS.merge(default_options)
3939

4040
chat_parameters.update(
41-
model: {default: @defaults[:chat_completion_model_name]},
41+
model: {default: @defaults[:chat_model]},
4242
temperature: {default: @defaults[:temperature]},
4343
safety_settings: {default: @defaults[:safety_settings]}
4444
)
@@ -58,7 +58,7 @@ def initialize(project_id:, region:, default_options: {})
5858
#
5959
def embed(
6060
text:,
61-
model: @defaults[:embeddings_model_name]
61+
model: @defaults[:embedding_model]
6262
)
6363
params = {instances: [{content: text}]}
6464

0 commit comments

Comments
 (0)