langgraph_rb 0.1.8 → 0.1.10

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: 6882db2f57746e6a18576eefd6bd26749009361880d1cd858ee91d3d06385abe
4
- data.tar.gz: fa195eb1ed6763a3e0b53803792e92e7dd1dd327c9dd9372d7acf7ab3ea49d8f
3
+ metadata.gz: 4db933d491b92e89ffd2520c1b1c9912f076510c8a5ee2e2bea3cdb7706b123e
4
+ data.tar.gz: b4bcc52d2863d2101cea6e26c5e4082ad35129c676f942e1bed18ed80adadf73
5
5
  SHA512:
6
- metadata.gz: aa652301646c12a2d2ade30faf5d5f463a89190813b9dbccb8c1b8df675bc6e0e8911c3358166224617239f763578b95fe78f27850e11690fc3e7726b85edc4c
7
- data.tar.gz: 1a7fa46cf43d02b0c356c58f5e5aaed84023c5c2cece84eaf49ff084627ac046f1dd170f4e9cf2477ed1981d1ca8b7321ad416c9e4610c854793bdcdbf6b990d
6
+ metadata.gz: 2ab4b6b056843d7608c7a45c71d99097158365ddc6a1226d03590cf6e2bb28207cf47a4309cc5c2696b263372c8646b777051cd5f0a4582707a4fb7b54d66990
7
+ data.tar.gz: 70fa2be9a71cb51291e6dd05c6278cbb201bb1227a0ca8a24d947de626ab5b179ff241bc67583c9c23526952eb9d11127d254478115839aa3f3383f5ef0e32ed
data/Gemfile CHANGED
@@ -2,7 +2,6 @@ source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
4
 
5
- gem 'openai', '~> 0.24.0'
6
5
 
7
6
  group :development, :test do
8
7
  gem 'rspec', '~> 3.0'
data/Gemfile.lock CHANGED
@@ -1,9 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- langgraph_rb (0.1.4)
4
+ langgraph_rb (0.1.9)
5
5
  json (~> 2.0)
6
- openai (~> 0.24.0)
7
6
 
8
7
  GEM
9
8
  remote: https://rubygems.org/
@@ -12,22 +11,19 @@ GEM
12
11
  byebug (12.0.0)
13
12
  coderay (1.1.3)
14
13
  concurrent-ruby (1.3.5)
15
- connection_pool (2.5.4)
16
14
  diff-lcs (1.6.2)
17
- json (2.13.2)
15
+ json (2.15.1)
18
16
  langfuse (0.1.1)
19
17
  concurrent-ruby (~> 1.2)
20
18
  sorbet-runtime (~> 0.5)
21
19
  language_server-protocol (3.17.0.5)
22
20
  lint_roller (1.1.0)
23
21
  method_source (1.1.0)
24
- openai (0.24.0)
25
- connection_pool
26
22
  parallel (1.27.0)
27
23
  parser (3.3.9.0)
28
24
  ast (~> 2.4.1)
29
25
  racc
30
- prism (1.4.0)
26
+ prism (1.5.1)
31
27
  pry (0.15.2)
32
28
  coderay (~> 1.1)
33
29
  method_source (~> 1.0)
@@ -37,7 +33,7 @@ GEM
37
33
  racc (1.8.1)
38
34
  rainbow (3.1.1)
39
35
  rake (13.3.0)
40
- regexp_parser (2.11.1)
36
+ regexp_parser (2.11.3)
41
37
  rspec (3.13.1)
42
38
  rspec-core (~> 3.13.0)
43
39
  rspec-expectations (~> 3.13.0)
@@ -50,8 +46,8 @@ GEM
50
46
  rspec-mocks (3.13.5)
51
47
  diff-lcs (>= 1.2.0, < 2.0)
52
48
  rspec-support (~> 3.13.0)
53
- rspec-support (3.13.4)
54
- rubocop (1.79.2)
49
+ rspec-support (3.13.6)
50
+ rubocop (1.81.1)
55
51
  json (~> 2.3)
56
52
  language_server-protocol (~> 3.17.0.2)
57
53
  lint_roller (~> 1.1.0)
@@ -59,17 +55,17 @@ GEM
59
55
  parser (>= 3.3.0.2)
60
56
  rainbow (>= 2.2.2, < 4.0)
61
57
  regexp_parser (>= 2.9.3, < 3.0)
62
- rubocop-ast (>= 1.46.0, < 2.0)
58
+ rubocop-ast (>= 1.47.1, < 2.0)
63
59
  ruby-progressbar (~> 1.7)
64
60
  unicode-display_width (>= 2.4.0, < 4.0)
65
- rubocop-ast (1.46.0)
61
+ rubocop-ast (1.47.1)
66
62
  parser (>= 3.3.7.2)
67
63
  prism (~> 1.4)
68
64
  ruby-progressbar (1.13.0)
69
- sorbet-runtime (0.6.12534)
70
- unicode-display_width (3.1.4)
71
- unicode-emoji (~> 4.0, >= 4.0.4)
72
- unicode-emoji (4.0.4)
65
+ sorbet-runtime (0.6.12627)
66
+ unicode-display_width (3.2.0)
67
+ unicode-emoji (~> 4.1)
68
+ unicode-emoji (4.1.0)
73
69
 
74
70
  PLATFORMS
75
71
  arm64-darwin-22
@@ -79,7 +75,6 @@ DEPENDENCIES
79
75
  bundler (~> 2.0)
80
76
  langfuse (~> 0.1)
81
77
  langgraph_rb!
82
- openai (~> 0.24.0)
83
78
  pry (~> 0.14)
84
79
  pry-byebug
85
80
  rake (~> 13.0)
@@ -87,4 +82,4 @@ DEPENDENCIES
87
82
  rubocop (~> 1.0)
88
83
 
89
84
  BUNDLED WITH
90
- 2.6.7
85
+ 2.7.2
data/examples/Gemfile ADDED
@@ -0,0 +1 @@
1
+ gem 'ruby-openai', '~> 8.1.0'
@@ -3,6 +3,10 @@ require 'pry'
3
3
  require 'pry-byebug'
4
4
  require 'langfuse'
5
5
  require_relative '../lib/langgraph_rb'
6
+ #require 'openai'
7
+ #require_relative '../lib/langgraph_rb/chat_openai'
8
+ require "openai"
9
+ require_relative '../lib/langgraph_rb/chat_ruby_openai'
6
10
 
7
11
  url = 'https://us.cloud.langfuse.com'
8
12
 
@@ -13,32 +17,35 @@ Langfuse.configure do |config|
13
17
  config.debug = true # Enable debug logging
14
18
  end
15
19
 
16
- class MovieInfoTool < LangGraphRB::ToolBase
17
- define_function :search_movie, description: "MovieInfoTool: Search for a movie by title" do
18
- property :query, type: "string", description: "The movie title to search for", required: true
19
- end
20
+ module Tool
21
+ class MovieInfoTool < LangGraphRB::ToolBase
22
+ define_function :search_movie, description: "MovieInfoTool: Search for a movie by title" do
23
+ property :query, type: "string", description: "The movie title to search for", required: true
24
+ end
20
25
 
21
- define_function :get_movie_details, description: "MovieInfoTool: Get detailed information about a specific movie" do
22
- property :movie_id, type: "integer", description: "The TMDb ID of the movie", required: true
23
- end
26
+ define_function :get_movie_details, description: "MovieInfoTool: Get detailed information about a specific movie" do
27
+ property :movie_id, type: "integer", description: "The TMDb ID of the movie", required: true
28
+ end
24
29
 
25
- def initialize(api_key: "demo")
26
- @api_key = api_key
27
- end
30
+ def initialize(api_key: "demo")
31
+ @api_key = api_key
32
+ end
28
33
 
29
- def search_movie(query:)
30
- tool_response({ results: [ { id: 603, title: query, year: 1999 } ] })
31
- end
34
+ def search_movie(query:)
35
+ tool_response({ results: [ { id: 603, title: query, year: 1999 } ] })
36
+ end
32
37
 
33
- def get_movie_details(movie_id:)
34
- tool_response({ id: movie_id, title: "The Matrix", overview: "A computer hacker learns the truth of reality." })
38
+ def get_movie_details(movie_id:)
39
+ tool_response({ id: movie_id, title: "The Matrix", overview: "A computer hacker learns the truth of reality." })
40
+ end
35
41
  end
36
42
  end
37
43
 
38
44
  def run_chat_openai_tools
39
- tools = [MovieInfoTool.new(api_key: ENV['TMDB_API_KEY'] || 'demo')]
45
+ tools = [Tool::MovieInfoTool.new(api_key: ENV['TMDB_API_KEY'] || 'demo')]
40
46
 
41
- chat = LangGraphRB::ChatOpenAI.new(model: ENV.fetch('OPENAI_MODEL', 'gpt-4o-mini'), temperature: 0)
47
+ #chat = LangGraphRB::ChatOpenAI.new(model: ENV.fetch('OPENAI_MODEL', 'gpt-4o-mini'), temperature: 0)
48
+ chat = LangGraphRB::ChatRubyOpenAI.new(model: ENV.fetch('OPENAI_MODEL', 'gpt-4o-mini'), temperature: 0)
42
49
  chat = chat.bind_tools(tools)
43
50
 
44
51
  observers = [LangGraphRB::Observers::LangfuseObserver.new(name: 'chat-openai-tools-example')]
@@ -47,15 +47,15 @@ module LangGraphRB
47
47
  name: 'OpenAI::ChatCompletion',
48
48
  model: @model,
49
49
  model_parameters: { temperature: @temperature },
50
- input: request_payload[:messages]
50
+ input: request_payload
51
51
  })
52
52
 
53
53
  # ruby-openai 8.1.x: client.chat(parameters: {...}) returns a Hash
54
54
  response = @client.chat(parameters: request_payload)
55
55
 
56
56
  message = extract_message_from_response(response)
57
- tool_calls = message[:tool_calls]
58
- text_content = message[:content]
57
+ tool_calls = message["tool_calls"]
58
+ text_content = message["content"]
59
59
 
60
60
  usage = extract_usage_from_response(response)
61
61
  notify_llm_response({
@@ -68,9 +68,9 @@ module LangGraphRB
68
68
  if tool_calls && !tool_calls.empty?
69
69
  normalized_calls = tool_calls.map do |tc|
70
70
  {
71
- id: tc[:id],
72
- name: tc[:function][:name],
73
- arguments: parse_tool_arguments(tc[:function][:arguments])
71
+ id: tc["id"],
72
+ name: tc["function"]["name"],
73
+ arguments: parse_tool_arguments(tc["function"]["arguments"])
74
74
  }
75
75
  end
76
76
  { tool_calls: normalized_calls }
@@ -158,7 +158,7 @@ module LangGraphRB
158
158
  return {
159
159
  id: call[:id],
160
160
  name: name.to_sym,
161
- class_name: class_name,
161
+ class_name: class_name.gsub('--', '::'),
162
162
  arguments: call[:arguments]
163
163
  }
164
164
  elsif call[:function]
@@ -8,7 +8,7 @@ module LangGraphRB
8
8
  end
9
9
 
10
10
  def define_function(name, description: "", &block)
11
- class_name = self.name
11
+ class_name = self.name.gsub('::', '--')
12
12
  fn_name = "#{class_name}__#{name}".to_sym
13
13
  @__tool_functions ||= {}
14
14
  @__tool_functions[fn_name] = {
@@ -1,3 +1,3 @@
1
1
  module LangGraphRB
2
- VERSION = "0.1.8"
2
+ VERSION = "0.1.10"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: langgraph_rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.1.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julian Toro
@@ -109,6 +109,7 @@ files:
109
109
  - Gemfile.lock
110
110
  - README.md
111
111
  - SUMMARY.md
112
+ - examples/Gemfile
112
113
  - examples/advanced_example.rb
113
114
  - examples/basic_example.rb
114
115
  - examples/chat_openai_tools_example.rb