langchainrb 0.13.0 → 0.13.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b146eb8568d30ae12aca93a25818fcff7421b7ee2e968330f3a68c5e523da148
4
- data.tar.gz: 33f88d7ba03501606706314dce58f626fa0df5aab50639b5f5db3df527ee6520
3
+ metadata.gz: 31daa3b09f92561f783122c10c1b48482bba75eac67e01550c71f7d76af36551
4
+ data.tar.gz: 355e21f33fbc3d21ac364ce046b0d2908ef111d2aa17996605df953ca25d0640
5
5
  SHA512:
6
- metadata.gz: 6518e30de12653426280f6f8cf05f37a6d4b311ad4219af52276bace8a75ec6440b8f42c208d9d5c07bb4218f3259cc95ea9edd77f8ba037e7a1600a7dfa3170
7
- data.tar.gz: 7f881a4347866c8b52161adaf6b98b669e38b4e2fd1ac513f02efd1dcfe73b2552ad8e65acdd02e9e002769ad3b394850f720e0971774632c2f489c25d9ce076
6
+ metadata.gz: f2bbf794a223f9b0da303f9b65a1a309213db00d45227ce6e9d5a9bc039d1150e06b786ff9730c1e4f2f2fd6d6566687d4a04d3c39f5dcd8d9e66c8e84e097ba
7
+ data.tar.gz: b406738ff1be88c7c545ec284d3050a3b5c0bb34a747f345ff18cbaeb63a3abf9763ec723913bd58ddd62be261c6abd88a87448fd2b9d3bde00eb53d795931e2
data/CHANGELOG.md CHANGED
@@ -1,5 +1,8 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.13.1] - 2024-05-14
4
+ - Better error handling for `Langchain::LLM::GoogleVertexAI`
5
+
3
6
  ## [0.13.0] - 2024-05-14
4
7
  - New 🛠️ `Langchain::Tool::NewsRetriever` tool to fetch news via newsapi.org
5
8
  - Langchain::Assistant works with `Langchain::LLM::GoogleVertexAI` and `Langchain::LLM::GoogleGemini` llms
@@ -42,6 +42,8 @@ module Langchain
42
42
 
43
43
  def count_verified_statements(verifications)
44
44
  match = verifications.match(/Final verdict for each statement in order:\s*(.*)/)
45
+ return 0.0 unless match # no verified statements found
46
+
45
47
  verdicts = match.captures.first
46
48
  verdicts
47
49
  .split(".")
@@ -58,16 +58,20 @@ module Langchain::LLM
58
58
  )
59
59
  params = {instances: [{content: text}]}
60
60
 
61
- response = HTTParty.post(
62
- "#{url}#{model}:predict",
63
- body: params.to_json,
64
- headers: {
65
- "Content-Type" => "application/json",
66
- "Authorization" => "Bearer #{@authorizer.fetch_access_token!["access_token"]}"
67
- }
68
- )
61
+ uri = URI("#{url}#{model}:predict")
69
62
 
70
- Langchain::LLM::GoogleGeminiResponse.new(response, model: model)
63
+ request = Net::HTTP::Post.new(uri)
64
+ request.content_type = "application/json"
65
+ request["Authorization"] = "Bearer #{@authorizer.fetch_access_token!["access_token"]}"
66
+ request.body = params.to_json
67
+
68
+ response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == "https") do |http|
69
+ http.request(request)
70
+ end
71
+
72
+ parsed_response = JSON.parse(response.body)
73
+
74
+ Langchain::LLM::GoogleGeminiResponse.new(parsed_response, model: model)
71
75
  end
72
76
 
73
77
  # Generate a chat completion for given messages
@@ -81,6 +85,7 @@ module Langchain::LLM
81
85
  def chat(params = {})
82
86
  params[:system] = {parts: [{text: params[:system]}]} if params[:system]
83
87
  params[:tools] = {function_declarations: params[:tools]} if params[:tools]
88
+ # This throws an error when tool_choice is passed
84
89
  params[:tool_choice] = {function_calling_config: {mode: params[:tool_choice].upcase}} if params[:tool_choice]
85
90
 
86
91
  raise ArgumentError.new("messages argument is required") if Array(params[:messages]).empty?
@@ -101,7 +106,13 @@ module Langchain::LLM
101
106
 
102
107
  parsed_response = JSON.parse(response.body)
103
108
 
104
- Langchain::LLM::GoogleGeminiResponse.new(parsed_response, model: parameters[:model])
109
+ wrapped_response = Langchain::LLM::GoogleGeminiResponse.new(parsed_response, model: parameters[:model])
110
+
111
+ if wrapped_response.chat_completion || Array(wrapped_response.tool_calls).any?
112
+ wrapped_response
113
+ else
114
+ raise StandardError.new(response)
115
+ end
105
116
  end
106
117
  end
107
118
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Langchain
4
- VERSION = "0.13.0"
4
+ VERSION = "0.13.1"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: langchainrb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.0
4
+ version: 0.13.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrei Bondarev
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-05-14 00:00:00.000000000 Z
11
+ date: 2024-05-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport