From 15e5ca47034a9dfe6a4a25222ebf106997c446ca Mon Sep 17 00:00:00 2001 From: Matheus Richard Date: Wed, 1 Nov 2023 10:11:42 -0300 Subject: [PATCH] Update ruby-openai to 5.2 The major difference is that the methods return hashes instead of Response objects. --- .tool-versions | 2 +- Gemfile.lock | 14 ++++++-------- gold_miner.gemspec | 2 +- lib/gold_miner.rb | 1 - lib/gold_miner/author_config.rb | 2 ++ lib/gold_miner/blog_post/open_ai_writer.rb | 3 ++- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/.tool-versions b/.tool-versions index c23af94..f2a971a 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1 +1 @@ -ruby 3.2.0 +ruby 3.2.2 diff --git a/Gemfile.lock b/Gemfile.lock index 35ae74a..61de887 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -5,7 +5,7 @@ PATH async (~> 2.6) dotenv (~> 2.8.0) dry-monads (~> 1.6) - ruby-openai (~> 3.0) + ruby-openai (~> 5.0) slack-ruby-client (~> 2.x) zeitwerk (~> 2.6.6) @@ -37,6 +37,7 @@ GEM concurrent-ruby (~> 1.0) dry-core (~> 1.0, < 2) zeitwerk (~> 2.6) + event_stream_parser (0.3.0) faraday (2.7.11) base64 faraday-net_http (>= 2.0, < 3.1) @@ -52,15 +53,10 @@ GEM gli (2.21.1) hashdiff (1.0.1) hashie (5.0.0) - httparty (0.21.0) - mini_mime (>= 1.0.0) - multi_xml (>= 0.5.2) io-event (1.3.3) json (2.6.3) language_server-protocol (3.17.0.3) lint_roller (1.1.0) - mini_mime (1.1.5) - multi_xml (0.6.0) multipart-post (2.3.0) parallel (1.23.0) parser (3.2.2.4) @@ -102,8 +98,10 @@ GEM rubocop-performance (1.19.1) rubocop (>= 1.7.0, < 2.0) rubocop-ast (>= 0.4.0) - ruby-openai (3.7.0) - httparty (>= 0.18.1) + ruby-openai (5.2.0) + event_stream_parser (>= 0.3.0, < 1.0.0) + faraday (>= 1) + faraday-multipart (>= 1) ruby-progressbar (1.13.0) ruby2_keywords (0.0.5) simplecov (0.22.0) diff --git a/gold_miner.gemspec b/gold_miner.gemspec index c578108..019665f 100644 --- a/gold_miner.gemspec +++ b/gold_miner.gemspec @@ -34,7 +34,7 @@ Gem::Specification.new do |spec| spec.add_dependency "async", "~> 2.6" spec.add_dependency "dotenv", "~> 2.8.0" spec.add_dependency "dry-monads", "~> 1.6" - spec.add_dependency "ruby-openai", "~> 3.0" + spec.add_dependency "ruby-openai", "~> 5.0" spec.add_dependency "slack-ruby-client", "~> 2.x" spec.add_dependency "zeitwerk", "~> 2.6.6" diff --git a/lib/gold_miner.rb b/lib/gold_miner.rb index 0ecfa91..4211376 100644 --- a/lib/gold_miner.rb +++ b/lib/gold_miner.rb @@ -2,7 +2,6 @@ require "dry/monads" require "zeitwerk" -require "openai" Zeitwerk::Loader.for_gem.setup diff --git a/lib/gold_miner/author_config.rb b/lib/gold_miner/author_config.rb index 49cb76b..fd5cfb4 100644 --- a/lib/gold_miner/author_config.rb +++ b/lib/gold_miner/author_config.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true +require "yaml" + class GoldMiner class AuthorConfig DEFAULT_AUTHOR_LINK = "#to-do" diff --git a/lib/gold_miner/blog_post/open_ai_writer.rb b/lib/gold_miner/blog_post/open_ai_writer.rb index 557adb0..cf37ee2 100644 --- a/lib/gold_miner/blog_post/open_ai_writer.rb +++ b/lib/gold_miner/blog_post/open_ai_writer.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true +require "openai" require "json" class GoldMiner @@ -53,7 +54,7 @@ def ask_openai(prompt) } ) - if !response.success? + if !response["error"].nil? warn "[WARNING] OpenAI error: #{response["error"]["message"]}" return end