From 00b0d1c64fccf3e37d0fc20c790e6f2e1d7fff25 Mon Sep 17 00:00:00 2001 From: Justin Harris Date: Fri, 26 Jun 2026 21:29:51 -0400 Subject: [PATCH] rename module to ShopifAi --- .rubocop.yml | 2 +- CHANGELOG.md | 6 ++ Gemfile.lock | 2 +- README.md | 60 ++++++++-------- bin/console | 2 +- lib/openai/version.rb | 3 - lib/ruby/openai.rb | 1 - lib/ruby/shopif_ai.rb | 1 + lib/{openai.rb => shopif_ai.rb} | 50 ++++++------- lib/{openai => shopif_ai}/assistants.rb | 4 +- lib/{openai => shopif_ai}/audio.rb | 2 +- lib/{openai => shopif_ai}/batches.rb | 2 +- lib/{openai => shopif_ai}/client.rb | 42 +++++------ lib/{openai => shopif_ai}/conversations.rb | 2 +- lib/{openai => shopif_ai}/files.rb | 4 +- lib/{openai => shopif_ai}/finetunes.rb | 2 +- lib/{openai => shopif_ai}/http.rb | 2 +- lib/{openai => shopif_ai}/http_headers.rb | 2 +- lib/{openai => shopif_ai}/images.rb | 2 +- lib/{openai => shopif_ai}/messages.rb | 4 +- lib/{openai => shopif_ai}/models.rb | 2 +- lib/{openai => shopif_ai}/realtime.rb | 2 +- lib/{openai => shopif_ai}/responses.rb | 2 +- lib/{openai => shopif_ai}/run_steps.rb | 4 +- lib/{openai => shopif_ai}/runs.rb | 4 +- lib/{openai => shopif_ai}/stream.rb | 2 +- lib/{openai => shopif_ai}/threads.rb | 4 +- lib/{openai => shopif_ai}/usage.rb | 2 +- .../vector_store_file_batches.rb | 4 +- .../vector_store_files.rb | 4 +- lib/{openai => shopif_ai}/vector_stores.rb | 4 +- lib/shopif_ai/version.rb | 3 + ruby-openai.gemspec | 4 +- spec/openai_spec.rb | 71 ------------------- .../client/assistants_spec.rb | 14 ++-- .../client/audio_spec.rb | 8 +-- .../client/batches_spec.rb | 18 ++--- .../{openai => shopif_ai}/client/chat_spec.rb | 10 +-- .../client/client_spec.rb | 30 ++++---- .../client/completions_spec.rb | 4 +- .../client/conversations_spec.rb | 28 ++++---- .../client/embeddings_spec.rb | 4 +- .../client/files_spec.rb | 28 ++++---- .../client/finetunes_spec.rb | 16 ++--- .../{openai => shopif_ai}/client/http_spec.rb | 58 +++++++-------- .../client/images_spec.rb | 14 ++-- .../client/messages_spec.rb | 16 ++--- .../client/models_spec.rb | 8 +-- .../client/moderations_spec.rb | 4 +- .../client/realtime_spec.rb | 4 +- .../client/responses_spec.rb | 18 ++--- .../client/run_steps_spec.rb | 12 ++-- .../{openai => shopif_ai}/client/runs_spec.rb | 22 +++--- .../client/stream_spec.rb | 4 +- .../client/threads_spec.rb | 12 ++-- .../client/usage_spec.rb | 4 +- .../client/vector_store_file_batches_spec.rb | 16 ++--- .../client/vector_store_files_spec.rb | 16 ++--- .../client/vector_stores_spec.rb | 16 ++--- spec/shopif_ai_spec.rb | 71 +++++++++++++++++++ spec/spec_helper.rb | 6 +- 61 files changed, 387 insertions(+), 381 deletions(-) delete mode 100644 lib/openai/version.rb delete mode 100644 lib/ruby/openai.rb create mode 100644 lib/ruby/shopif_ai.rb rename lib/{openai.rb => shopif_ai.rb} (71%) rename lib/{openai => shopif_ai}/assistants.rb (85%) rename lib/{openai => shopif_ai}/audio.rb (96%) rename lib/{openai => shopif_ai}/batches.rb (96%) rename lib/{openai => shopif_ai}/client.rb (69%) rename lib/{openai => shopif_ai}/conversations.rb (98%) rename lib/{openai => shopif_ai}/files.rb (96%) rename lib/{openai => shopif_ai}/finetunes.rb (97%) rename lib/{openai => shopif_ai}/http.rb (99%) rename lib/{openai => shopif_ai}/http_headers.rb (97%) rename lib/{openai => shopif_ai}/images.rb (98%) rename lib/{openai => shopif_ai}/messages.rb (88%) rename lib/{openai => shopif_ai}/models.rb (94%) rename lib/{openai => shopif_ai}/realtime.rb (97%) rename lib/{openai => shopif_ai}/responses.rb (97%) rename lib/{openai => shopif_ai}/run_steps.rb (80%) rename lib/{openai => shopif_ai}/runs.rb (92%) rename lib/{openai => shopif_ai}/stream.rb (98%) rename lib/{openai => shopif_ai}/threads.rb (82%) rename lib/{openai => shopif_ai}/usage.rb (98%) rename lib/{openai => shopif_ai}/vector_store_file_batches.rb (88%) rename lib/{openai => shopif_ai}/vector_store_files.rb (87%) rename lib/{openai => shopif_ai}/vector_stores.rb (88%) create mode 100644 lib/shopif_ai/version.rb delete mode 100644 spec/openai_spec.rb rename spec/{openai => shopif_ai}/client/assistants_spec.rb (80%) rename spec/{openai => shopif_ai}/client/audio_spec.rb (91%) rename spec/{openai => shopif_ai}/client/batches_spec.rb (83%) rename spec/{openai => shopif_ai}/client/chat_spec.rb (97%) rename spec/{openai => shopif_ai}/client/client_spec.rb (89%) rename spec/{openai => shopif_ai}/client/completions_spec.rb (89%) rename spec/{openai => shopif_ai}/client/conversations_spec.rb (85%) rename spec/{openai => shopif_ai}/client/embeddings_spec.rb (88%) rename spec/{openai => shopif_ai}/client/files_spec.rb (82%) rename spec/{openai => shopif_ai}/client/finetunes_spec.rb (82%) rename spec/{openai => shopif_ai}/client/http_spec.rb (81%) rename spec/{openai => shopif_ai}/client/images_spec.rb (93%) rename spec/{openai => shopif_ai}/client/messages_spec.rb (81%) rename spec/{openai => shopif_ai}/client/models_spec.rb (80%) rename spec/{openai => shopif_ai}/client/moderations_spec.rb (83%) rename spec/{openai => shopif_ai}/client/realtime_spec.rb (92%) rename spec/{openai => shopif_ai}/client/responses_spec.rb (91%) rename spec/{openai => shopif_ai}/client/run_steps_spec.rb (83%) rename spec/{openai => shopif_ai}/client/runs_spec.rb (87%) rename spec/{openai => shopif_ai}/client/stream_spec.rb (97%) rename spec/{openai => shopif_ai}/client/threads_spec.rb (77%) rename spec/{openai => shopif_ai}/client/usage_spec.rb (92%) rename spec/{openai => shopif_ai}/client/vector_store_file_batches_spec.rb (81%) rename spec/{openai => shopif_ai}/client/vector_store_files_spec.rb (78%) rename spec/{openai => shopif_ai}/client/vector_stores_spec.rb (80%) create mode 100644 spec/shopif_ai_spec.rb diff --git a/.rubocop.yml b/.rubocop.yml index 0db3ae69..8b5bbe7c 100755 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -15,7 +15,7 @@ Layout/LineLength: Lint/AmbiguousOperator: # https://github.com/rubocop/rubocop/issues/4294 Exclude: - - "lib/openai/client.rb" + - "lib/shopif_ai/client.rb" Metrics/AbcSize: Max: 20 diff --git a/CHANGELOG.md b/CHANGELOG.md index cc82545d..0ce45df7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [9.0.0] - 2026-06-27 + +### Changed + +- [BREAKING] Rename the gem namespace from `OpenAI` to `ShopifAi` and the canonical require path from `openai` to `shopif_ai`. + ## [8.4.0] - 2026-06-26 ### Added diff --git a/Gemfile.lock b/Gemfile.lock index d5b55289..d8c57847 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - ruby-openai (8.4.0) + ruby-openai (9.0.0) event_stream_parser (>= 0.3.0, < 2.0.0) faraday (>= 1) faraday-multipart (>= 1) diff --git a/README.md b/README.md index 3d451c65..a78f0b46 100644 --- a/README.md +++ b/README.md @@ -143,7 +143,7 @@ gem install ruby-openai and require with: ```ruby -require "openai" +require "shopif_ai" ``` ## How to use @@ -156,7 +156,7 @@ require "openai" For a quick test you can pass your token directly to a new client: ```ruby -client = OpenAI::Client.new( +client = ShopifAi::Client.new( access_token: "access_token_goes_here", log_errors: true # Highly recommended in development, so you can see what errors OpenAI is returning. Not recommended in production because it could leak private data to your logs. ) @@ -164,10 +164,10 @@ client = OpenAI::Client.new( ### With Config -For a more robust setup, you can configure the gem with your API keys, for example in an `openai.rb` initializer file. Never hardcode secrets into your codebase - instead use something like [dotenv](https://github.com/motdotla/dotenv) to pass the keys safely into your environments. +For a more robust setup, you can configure the gem with your API keys, for example in a `shopif_ai.rb` initializer file. Never hardcode secrets into your codebase - instead use something like [dotenv](https://github.com/motdotla/dotenv) to pass the keys safely into your environments. ```ruby -OpenAI.configure do |config| +ShopifAi.configure do |config| config.access_token = ENV.fetch("OPENAI_ACCESS_TOKEN") config.admin_token = ENV.fetch("OPENAI_ADMIN_TOKEN") # Optional, used for admin endpoints, created here: https://platform.openai.com/settings/organization/admin-keys config.organization_id = ENV.fetch("OPENAI_ORGANIZATION_ID") # Optional @@ -178,13 +178,13 @@ end Then you can create a client like this: ```ruby -client = OpenAI::Client.new +client = ShopifAi::Client.new ``` -You can still override the config defaults when making new clients; any options not included will fall back to any global config set with OpenAI.configure. e.g. in this example the organization_id, request_timeout, etc. will fallback to any set globally using OpenAI.configure, with only the access_token and admin_token overridden: +You can still override the config defaults when making new clients; any options not included will fall back to any global config set with ShopifAi.configure. e.g. in this example the organization_id, request_timeout, etc. will fallback to any set globally using ShopifAi.configure, with only the access_token and admin_token overridden: ```ruby -client = OpenAI::Client.new(access_token: "access_token_goes_here", admin_token: "admin_token_goes_here") +client = ShopifAi::Client.new(access_token: "access_token_goes_here", admin_token: "admin_token_goes_here") ``` #### Custom timeout or base URI @@ -194,7 +194,7 @@ client = OpenAI::Client.new(access_token: "access_token_goes_here", admin_token: - You can also add arbitrary other headers e.g. for [openai-caching-proxy-worker](https://github.com/6/openai-caching-proxy-worker), eg.: ```ruby -client = OpenAI::Client.new( +client = ShopifAi::Client.new( access_token: "access_token_goes_here", uri_base: "https://oai.hconeai.com/", request_timeout: 240, @@ -210,7 +210,7 @@ client = OpenAI::Client.new( or when configuring the gem: ```ruby -OpenAI.configure do |config| +ShopifAi.configure do |config| config.access_token = ENV.fetch("OPENAI_ACCESS_TOKEN") config.admin_token = ENV.fetch("OPENAI_ADMIN_TOKEN") # Optional, used for admin endpoints, created here: https://platform.openai.com/settings/organization/admin-keys config.organization_id = ENV.fetch("OPENAI_ORGANIZATION_ID") # Optional @@ -227,10 +227,10 @@ end #### Extra Headers per Client -You can dynamically pass headers per client object, which will be merged with any headers set globally with OpenAI.configure: +You can dynamically pass headers per client object, which will be merged with any headers set globally with ShopifAi.configure: ```ruby -client = OpenAI::Client.new(access_token: "access_token_goes_here") +client = ShopifAi::Client.new(access_token: "access_token_goes_here") client.add_headers("X-Proxy-TTL" => "43200") ``` @@ -243,7 +243,7 @@ By default, `ruby-openai` does not log any `Faraday::Error`s encountered while e If you would like to enable this functionality, you can set `log_errors` to `true` when configuring the client: ```ruby -client = OpenAI::Client.new(log_errors: true) +client = ShopifAi::Client.new(log_errors: true) ``` ##### Faraday middleware @@ -253,7 +253,7 @@ You can pass [Faraday middleware](https://lostisland.github.io/faraday/#/middlew - To enable verbose logging with Ruby's [Logger](https://ruby-doc.org/3.2.2/stdlibs/logger/Logger.html): ```ruby -client = OpenAI::Client.new do |f| +client = ShopifAi::Client.new do |f| f.response :logger, Logger.new($stdout), bodies: true end ``` @@ -261,7 +261,7 @@ end - To add a web debugging proxy like [Charles](https://www.charlesproxy.com/documentation/welcome/): ```ruby - client = OpenAI::Client.new do |f| + client = ShopifAi::Client.new do |f| f.proxy = { uri: "http://localhost:8888" } end ``` @@ -270,7 +270,7 @@ end To use the [Azure OpenAI Service](https://learn.microsoft.com/en-us/azure/cognitive-services/openai/) API, you can configure the gem like this: ```ruby -OpenAI.configure do |config| +ShopifAi.configure do |config| config.access_token = ENV.fetch("AZURE_OPENAI_API_KEY") config.uri_base = ENV.fetch("AZURE_OPENAI_URI") config.api_type = :azure @@ -285,7 +285,7 @@ where `AZURE_OPENAI_URI` is e.g. `https://custom-domain.openai.azure.com/openai/ [Deepseek](https://api-docs.deepseek.com/) is compatible with the OpenAI chat API. Get an access token from [here](https://platform.deepseek.com/api_keys), then: ```ruby -client = OpenAI::Client.new( +client = ShopifAi::Client.new( access_token: "deepseek_access_token_goes_here", uri_base: "https://api.deepseek.com/" ) @@ -317,7 +317,7 @@ ollama pull llama3:latest # In new terminal tab. Create a client using your Ollama server and the pulled model, and stream a conversation for free: ```ruby -client = OpenAI::Client.new( +client = ShopifAi::Client.new( uri_base: "http://localhost:11434" ) @@ -340,7 +340,7 @@ client.chat( [Groq API Chat](https://console.groq.com/docs/quickstart) is broadly compatible with the OpenAI API, with a [few minor differences](https://console.groq.com/docs/openai). Get an access token from [here](https://console.groq.com/keys), then: ```ruby -client = OpenAI::Client.new( +client = ShopifAi::Client.new( access_token: "groq_access_token_goes_here", uri_base: "https://api.groq.com/openai" ) @@ -362,7 +362,7 @@ client.chat( [Gemini API Chat](https://ai.google.dev/gemini-api/docs/openai) is also broadly compatible with the OpenAI API, and [currently in beta](https://ai.google.dev/gemini-api/docs/openai#current-limitations). Get an access token from [here](https://aistudio.google.com/app/apikey), then: ```ruby -client = OpenAI::Client.new( +client = ShopifAi::Client.new( access_token: "gemini_access_token_goes_here", uri_base: "https://generativelanguage.googleapis.com/v1beta/openai/" ) @@ -388,7 +388,7 @@ OpenAI parses prompt text into [tokens](https://help.openai.com/en/articles/4936 To estimate the token-count of your text: ```ruby -OpenAI.rough_token_count("Your text") +ShopifAi.rough_token_count("Your text") ``` If you need a more accurate count, try [tiktoken_ruby](https://github.com/IAPark/tiktoken_ruby). @@ -1463,10 +1463,10 @@ thread_id = response['thread_id'] You can include images in a thread and they will be described & read by the LLM. In this example I'm using [this file](https://upload.wikimedia.org/wikipedia/commons/7/70/Example.png): ```ruby -require "openai" +require "shopif_ai" # Make a client -client = OpenAI::Client.new( +client = ShopifAi::Client.new( access_token: "access_token_goes_here", log_errors: true # Don't log errors in production. ) @@ -1580,15 +1580,15 @@ Take a deep breath. You might need a drink for this one. It's possible for OpenAI to share what chunks it used in its internal RAG Pipeline to create its filesearch results. -An example spec can be found [here](https://github.com/Shopify/ruby-openai/blob/main/spec/openai/client/assistant_file_search_spec.rb) that does this, just so you know it's possible. +An example spec can be found [here](https://github.com/Shopify/ruby-openai/blob/main/spec/shopif_ai/client/assistant_file_search_spec.rb) that does this, just so you know it's possible. Here's how to get the chunks used in a file search. In this example I'm using [this file](https://css4.pub/2015/textbook/somatosensory.pdf): ```ruby -require "openai" +require "shopif_ai" # Make a client -client = OpenAI::Client.new( +client = ShopifAi::Client.new( access_token: "access_token_goes_here", log_errors: true # Don't log errors in production. ) @@ -1742,7 +1742,7 @@ puts response.dig("data", 0, "url") You can also upload arrays of images, eg. ```ruby - client = OpenAI::Client.new + client = ShopifAi::Client.new response = client.images.edit( parameters: { model: "gpt-image-1", @@ -1879,13 +1879,13 @@ The Usage API provides information about the cost of various OpenAI services wit To use Admin APIs like Usage, you need to set an OPENAI_ADMIN_TOKEN, which can be generated [here](https://platform.openai.com/settings/organization/admin-keys). ```ruby -OpenAI.configure do |config| +ShopifAi.configure do |config| config.admin_token = ENV.fetch("OPENAI_ADMIN_TOKEN") end # or -client = OpenAI::Client.new(admin_token: "123abc") +client = ShopifAi::Client.new(admin_token: "123abc") ``` You can retrieve usage data for different endpoints and time periods: @@ -1938,7 +1938,7 @@ HTTP errors can be caught like this: ```ruby begin - OpenAI::Client.new.models.retrieve(id: "gpt-4o") + ShopifAi::Client.new.models.retrieve(id: "gpt-4o") rescue Faraday::Error => e raise "Got a Faraday error: #{e}" end @@ -1958,7 +1958,7 @@ To run all tests, execute the command `bundle exec rake`, which will also run th ### To check for deprecations ``` -bundle exec ruby -e "Warning[:deprecated] = true; require 'rspec'; exit RSpec::Core::Runner.run(['spec/openai/client/http_spec.rb:25'])" +bundle exec ruby -e "Warning[:deprecated] = true; require 'rspec'; exit RSpec::Core::Runner.run(['spec/shopif_ai/client/http_spec.rb:25'])" ``` ## Release diff --git a/bin/console b/bin/console index dfb0352c..f7ae0063 100755 --- a/bin/console +++ b/bin/console @@ -1,7 +1,7 @@ #!/usr/bin/env ruby require "bundler/setup" -require "openai" +require "shopif_ai" # You can add fixtures and/or initialization code here to make experimenting # with your gem easier. You can also use a different console, if you like. diff --git a/lib/openai/version.rb b/lib/openai/version.rb deleted file mode 100644 index f3b6d56e..00000000 --- a/lib/openai/version.rb +++ /dev/null @@ -1,3 +0,0 @@ -module OpenAI - VERSION = "8.4.0".freeze -end diff --git a/lib/ruby/openai.rb b/lib/ruby/openai.rb deleted file mode 100644 index 1f6860a8..00000000 --- a/lib/ruby/openai.rb +++ /dev/null @@ -1 +0,0 @@ -require_relative "../openai" diff --git a/lib/ruby/shopif_ai.rb b/lib/ruby/shopif_ai.rb new file mode 100644 index 00000000..924f8915 --- /dev/null +++ b/lib/ruby/shopif_ai.rb @@ -0,0 +1 @@ +require_relative "../shopif_ai" diff --git a/lib/openai.rb b/lib/shopif_ai.rb similarity index 71% rename from lib/openai.rb rename to lib/shopif_ai.rb index d5880c90..2adab980 100644 --- a/lib/openai.rb +++ b/lib/shopif_ai.rb @@ -1,29 +1,29 @@ require "faraday" require "faraday/multipart" if Gem::Version.new(Faraday::VERSION) >= Gem::Version.new("2.0") -require_relative "openai/http" -require_relative "openai/client" -require_relative "openai/files" -require_relative "openai/finetunes" -require_relative "openai/images" -require_relative "openai/models" -require_relative "openai/responses" -require_relative "openai/assistants" -require_relative "openai/threads" -require_relative "openai/messages" -require_relative "openai/realtime" -require_relative "openai/runs" -require_relative "openai/run_steps" -require_relative "openai/stream" -require_relative "openai/vector_stores" -require_relative "openai/vector_store_files" -require_relative "openai/vector_store_file_batches" -require_relative "openai/audio" -require_relative "openai/version" -require_relative "openai/batches" -require_relative "openai/usage" -require_relative "openai/conversations" +require_relative "shopif_ai/http" +require_relative "shopif_ai/client" +require_relative "shopif_ai/files" +require_relative "shopif_ai/finetunes" +require_relative "shopif_ai/images" +require_relative "shopif_ai/models" +require_relative "shopif_ai/responses" +require_relative "shopif_ai/assistants" +require_relative "shopif_ai/threads" +require_relative "shopif_ai/messages" +require_relative "shopif_ai/realtime" +require_relative "shopif_ai/runs" +require_relative "shopif_ai/run_steps" +require_relative "shopif_ai/stream" +require_relative "shopif_ai/vector_stores" +require_relative "shopif_ai/vector_store_files" +require_relative "shopif_ai/vector_store_file_batches" +require_relative "shopif_ai/audio" +require_relative "shopif_ai/version" +require_relative "shopif_ai/batches" +require_relative "shopif_ai/usage" +require_relative "shopif_ai/conversations" -module OpenAI +module ShopifAi class Error < StandardError; end class ConfigurationError < Error; end class AuthenticationError < Error; end @@ -34,7 +34,7 @@ def call(env) rescue Faraday::Error => e raise e unless e.response.is_a?(Hash) - OpenAI.log_message("OpenAI HTTP Error", e.response[:body], :error) + ShopifAi.log_message("OpenAI HTTP Error", e.response[:body], :error) raise e end end @@ -72,7 +72,7 @@ class << self attr_writer :configuration def configuration - @configuration ||= OpenAI::Configuration.new + @configuration ||= ShopifAi::Configuration.new end def configure diff --git a/lib/openai/assistants.rb b/lib/shopif_ai/assistants.rb similarity index 85% rename from lib/openai/assistants.rb rename to lib/shopif_ai/assistants.rb index c7fbc2d0..b9567f35 100644 --- a/lib/openai/assistants.rb +++ b/lib/shopif_ai/assistants.rb @@ -1,9 +1,9 @@ -module OpenAI +module ShopifAi class Assistants BETA_VERSION = "v2".freeze def initialize(client:) - @client = client.beta(assistants: OpenAI::Assistants::BETA_VERSION) + @client = client.beta(assistants: ShopifAi::Assistants::BETA_VERSION) end def list diff --git a/lib/openai/audio.rb b/lib/shopif_ai/audio.rb similarity index 96% rename from lib/openai/audio.rb rename to lib/shopif_ai/audio.rb index 57ea5466..76fe4dcb 100644 --- a/lib/openai/audio.rb +++ b/lib/shopif_ai/audio.rb @@ -1,4 +1,4 @@ -module OpenAI +module ShopifAi class Audio def initialize(client:) @client = client diff --git a/lib/openai/batches.rb b/lib/shopif_ai/batches.rb similarity index 96% rename from lib/openai/batches.rb rename to lib/shopif_ai/batches.rb index ccb47458..dc664011 100644 --- a/lib/openai/batches.rb +++ b/lib/shopif_ai/batches.rb @@ -1,4 +1,4 @@ -module OpenAI +module ShopifAi class Batches def initialize(client:) @client = client diff --git a/lib/openai/client.rb b/lib/shopif_ai/client.rb similarity index 69% rename from lib/openai/client.rb rename to lib/shopif_ai/client.rb index 313bfded..b3d7d918 100644 --- a/lib/openai/client.rb +++ b/lib/shopif_ai/client.rb @@ -1,7 +1,7 @@ # rubocop:disable Metrics/ClassLength -module OpenAI +module ShopifAi class Client - include OpenAI::HTTP + include ShopifAi::HTTP SENSITIVE_ATTRIBUTES = %i[@access_token @admin_token @organization_id @extra_headers].freeze CONFIG_KEYS = %i[access_token admin_token api_type api_version extra_headers @@ -15,7 +15,7 @@ def initialize(config = {}, &faraday_middleware) # if not present. instance_variable_set( "@#{key}", - config[key].nil? ? OpenAI.configuration.send(key) : config[key] + config[key].nil? ? ShopifAi.configuration.send(key) : config[key] ) end @faraday_middleware = faraday_middleware @@ -34,67 +34,67 @@ def completions(parameters: {}, extra_headers: {}) end def audio - @audio ||= OpenAI::Audio.new(client: self) + @audio ||= ShopifAi::Audio.new(client: self) end def files - @files ||= OpenAI::Files.new(client: self) + @files ||= ShopifAi::Files.new(client: self) end def finetunes - @finetunes ||= OpenAI::Finetunes.new(client: self) + @finetunes ||= ShopifAi::Finetunes.new(client: self) end def images - @images ||= OpenAI::Images.new(client: self) + @images ||= ShopifAi::Images.new(client: self) end def models - @models ||= OpenAI::Models.new(client: self) + @models ||= ShopifAi::Models.new(client: self) end def responses - @responses ||= OpenAI::Responses.new(client: self) + @responses ||= ShopifAi::Responses.new(client: self) end def assistants - @assistants ||= OpenAI::Assistants.new(client: self) + @assistants ||= ShopifAi::Assistants.new(client: self) end def threads - @threads ||= OpenAI::Threads.new(client: self) + @threads ||= ShopifAi::Threads.new(client: self) end def messages - @messages ||= OpenAI::Messages.new(client: self) + @messages ||= ShopifAi::Messages.new(client: self) end def runs - @runs ||= OpenAI::Runs.new(client: self) + @runs ||= ShopifAi::Runs.new(client: self) end def run_steps - @run_steps ||= OpenAI::RunSteps.new(client: self) + @run_steps ||= ShopifAi::RunSteps.new(client: self) end def vector_stores - @vector_stores ||= OpenAI::VectorStores.new(client: self) + @vector_stores ||= ShopifAi::VectorStores.new(client: self) end def vector_store_files - @vector_store_files ||= OpenAI::VectorStoreFiles.new(client: self) + @vector_store_files ||= ShopifAi::VectorStoreFiles.new(client: self) end def vector_store_file_batches - @vector_store_file_batches ||= OpenAI::VectorStoreFileBatches.new(client: self) + @vector_store_file_batches ||= ShopifAi::VectorStoreFileBatches.new(client: self) end def batches - @batches ||= OpenAI::Batches.new(client: self) + @batches ||= ShopifAi::Batches.new(client: self) end def realtime - @realtime ||= OpenAI::Realtime.new(client: self) + @realtime ||= ShopifAi::Realtime.new(client: self) end def moderations(parameters: {}, extra_headers: {}) @@ -102,11 +102,11 @@ def moderations(parameters: {}, extra_headers: {}) end def usage - @usage ||= OpenAI::Usage.new(client: self) + @usage ||= ShopifAi::Usage.new(client: self) end def conversations - @conversations ||= OpenAI::Conversations.new(client: self) + @conversations ||= ShopifAi::Conversations.new(client: self) end def azure? diff --git a/lib/openai/conversations.rb b/lib/shopif_ai/conversations.rb similarity index 98% rename from lib/openai/conversations.rb rename to lib/shopif_ai/conversations.rb index b0ef3d1b..def26018 100644 --- a/lib/openai/conversations.rb +++ b/lib/shopif_ai/conversations.rb @@ -1,4 +1,4 @@ -module OpenAI +module ShopifAi class Conversations def initialize(client:) @client = client diff --git a/lib/openai/files.rb b/lib/shopif_ai/files.rb similarity index 96% rename from lib/openai/files.rb rename to lib/shopif_ai/files.rb index 558c8a70..c876f3ad 100644 --- a/lib/openai/files.rb +++ b/lib/shopif_ai/files.rb @@ -1,4 +1,4 @@ -module OpenAI +module ShopifAi class Files PURPOSES = %w[ assistants @@ -60,7 +60,7 @@ def validate(file:, purpose:, file_input:) filename = file_input.is_a?(String) ? File.basename(file_input) : "uploaded file" message = "The purpose '#{purpose}' for file '#{filename}' is not in the known purpose " message += "list: #{PURPOSES.join(', ')}." - OpenAI.log_message("Warning", message, :warn) + ShopifAi.log_message("Warning", message, :warn) end validate_jsonl(file: file) if file_input.is_a?(String) && file_input.end_with?(".jsonl") diff --git a/lib/openai/finetunes.rb b/lib/shopif_ai/finetunes.rb similarity index 97% rename from lib/openai/finetunes.rb rename to lib/shopif_ai/finetunes.rb index 02850173..9b376bdc 100644 --- a/lib/openai/finetunes.rb +++ b/lib/shopif_ai/finetunes.rb @@ -1,4 +1,4 @@ -module OpenAI +module ShopifAi class Finetunes def initialize(client:) @client = client diff --git a/lib/openai/http.rb b/lib/shopif_ai/http.rb similarity index 99% rename from lib/openai/http.rb rename to lib/shopif_ai/http.rb index 76107ea8..1f7cc663 100644 --- a/lib/openai/http.rb +++ b/lib/shopif_ai/http.rb @@ -2,7 +2,7 @@ require_relative "http_headers" -module OpenAI +module ShopifAi module HTTP include HTTPHeaders diff --git a/lib/openai/http_headers.rb b/lib/shopif_ai/http_headers.rb similarity index 97% rename from lib/openai/http_headers.rb rename to lib/shopif_ai/http_headers.rb index 62e3e74e..f816982a 100644 --- a/lib/openai/http_headers.rb +++ b/lib/shopif_ai/http_headers.rb @@ -1,4 +1,4 @@ -module OpenAI +module ShopifAi module HTTPHeaders def add_headers(headers) @extra_headers = extra_headers.merge(headers.transform_keys(&:to_s)) diff --git a/lib/openai/images.rb b/lib/shopif_ai/images.rb similarity index 98% rename from lib/openai/images.rb rename to lib/shopif_ai/images.rb index 35a9b5f2..273248c6 100644 --- a/lib/openai/images.rb +++ b/lib/shopif_ai/images.rb @@ -1,4 +1,4 @@ -module OpenAI +module ShopifAi class Images def initialize(client: nil) @client = client diff --git a/lib/openai/messages.rb b/lib/shopif_ai/messages.rb similarity index 88% rename from lib/openai/messages.rb rename to lib/shopif_ai/messages.rb index 672f552c..341f0b39 100644 --- a/lib/openai/messages.rb +++ b/lib/shopif_ai/messages.rb @@ -1,7 +1,7 @@ -module OpenAI +module ShopifAi class Messages def initialize(client:) - @client = client.beta(assistants: OpenAI::Assistants::BETA_VERSION) + @client = client.beta(assistants: ShopifAi::Assistants::BETA_VERSION) end def list(thread_id:, parameters: {}) diff --git a/lib/openai/models.rb b/lib/shopif_ai/models.rb similarity index 94% rename from lib/openai/models.rb rename to lib/shopif_ai/models.rb index 3985c3b2..3e17f1f4 100644 --- a/lib/openai/models.rb +++ b/lib/shopif_ai/models.rb @@ -1,4 +1,4 @@ -module OpenAI +module ShopifAi class Models def initialize(client:) @client = client diff --git a/lib/openai/realtime.rb b/lib/shopif_ai/realtime.rb similarity index 97% rename from lib/openai/realtime.rb rename to lib/shopif_ai/realtime.rb index 0282d3d2..dd6fd246 100644 --- a/lib/openai/realtime.rb +++ b/lib/shopif_ai/realtime.rb @@ -1,4 +1,4 @@ -module OpenAI +module ShopifAi class Realtime def initialize(client:) @client = client.beta(realtime: "v1") diff --git a/lib/openai/responses.rb b/lib/shopif_ai/responses.rb similarity index 97% rename from lib/openai/responses.rb rename to lib/shopif_ai/responses.rb index 15b86e41..4a4cc5bb 100644 --- a/lib/openai/responses.rb +++ b/lib/shopif_ai/responses.rb @@ -1,4 +1,4 @@ -module OpenAI +module ShopifAi class Responses def initialize(client:) @client = client diff --git a/lib/openai/run_steps.rb b/lib/shopif_ai/run_steps.rb similarity index 80% rename from lib/openai/run_steps.rb rename to lib/shopif_ai/run_steps.rb index bf3b47fe..e8f82173 100644 --- a/lib/openai/run_steps.rb +++ b/lib/shopif_ai/run_steps.rb @@ -1,7 +1,7 @@ -module OpenAI +module ShopifAi class RunSteps def initialize(client:) - @client = client.beta(assistants: OpenAI::Assistants::BETA_VERSION) + @client = client.beta(assistants: ShopifAi::Assistants::BETA_VERSION) end def list(thread_id:, run_id:, parameters: {}) diff --git a/lib/openai/runs.rb b/lib/shopif_ai/runs.rb similarity index 92% rename from lib/openai/runs.rb rename to lib/shopif_ai/runs.rb index a8cf56bd..000c8c51 100644 --- a/lib/openai/runs.rb +++ b/lib/shopif_ai/runs.rb @@ -1,7 +1,7 @@ -module OpenAI +module ShopifAi class Runs def initialize(client:) - @client = client.beta(assistants: OpenAI::Assistants::BETA_VERSION) + @client = client.beta(assistants: ShopifAi::Assistants::BETA_VERSION) end def list(thread_id:, parameters: {}) diff --git a/lib/openai/stream.rb b/lib/shopif_ai/stream.rb similarity index 98% rename from lib/openai/stream.rb rename to lib/shopif_ai/stream.rb index 64cf704e..581a15bf 100644 --- a/lib/openai/stream.rb +++ b/lib/shopif_ai/stream.rb @@ -1,4 +1,4 @@ -module OpenAI +module ShopifAi class Stream DONE = "[DONE]".freeze private_constant :DONE diff --git a/lib/openai/threads.rb b/lib/shopif_ai/threads.rb similarity index 82% rename from lib/openai/threads.rb rename to lib/shopif_ai/threads.rb index ed494aac..0a398e43 100644 --- a/lib/openai/threads.rb +++ b/lib/shopif_ai/threads.rb @@ -1,7 +1,7 @@ -module OpenAI +module ShopifAi class Threads def initialize(client:) - @client = client.beta(assistants: OpenAI::Assistants::BETA_VERSION) + @client = client.beta(assistants: ShopifAi::Assistants::BETA_VERSION) end def retrieve(id:) diff --git a/lib/openai/usage.rb b/lib/shopif_ai/usage.rb similarity index 98% rename from lib/openai/usage.rb rename to lib/shopif_ai/usage.rb index d3deb0c3..ec8e69bd 100644 --- a/lib/openai/usage.rb +++ b/lib/shopif_ai/usage.rb @@ -1,4 +1,4 @@ -module OpenAI +module ShopifAi class Usage def initialize(client:) @client = client diff --git a/lib/openai/vector_store_file_batches.rb b/lib/shopif_ai/vector_store_file_batches.rb similarity index 88% rename from lib/openai/vector_store_file_batches.rb rename to lib/shopif_ai/vector_store_file_batches.rb index c5aa7e52..66431761 100644 --- a/lib/openai/vector_store_file_batches.rb +++ b/lib/shopif_ai/vector_store_file_batches.rb @@ -1,7 +1,7 @@ -module OpenAI +module ShopifAi class VectorStoreFileBatches def initialize(client:) - @client = client.beta(assistants: OpenAI::Assistants::BETA_VERSION) + @client = client.beta(assistants: ShopifAi::Assistants::BETA_VERSION) end def list(vector_store_id:, id:, parameters: {}) diff --git a/lib/openai/vector_store_files.rb b/lib/shopif_ai/vector_store_files.rb similarity index 87% rename from lib/openai/vector_store_files.rb rename to lib/shopif_ai/vector_store_files.rb index fc338612..f2b3640d 100644 --- a/lib/openai/vector_store_files.rb +++ b/lib/shopif_ai/vector_store_files.rb @@ -1,7 +1,7 @@ -module OpenAI +module ShopifAi class VectorStoreFiles def initialize(client:) - @client = client.beta(assistants: OpenAI::Assistants::BETA_VERSION) + @client = client.beta(assistants: ShopifAi::Assistants::BETA_VERSION) end def list(vector_store_id:, parameters: {}) diff --git a/lib/openai/vector_stores.rb b/lib/shopif_ai/vector_stores.rb similarity index 88% rename from lib/openai/vector_stores.rb rename to lib/shopif_ai/vector_stores.rb index 0b8cb775..b8054d44 100644 --- a/lib/openai/vector_stores.rb +++ b/lib/shopif_ai/vector_stores.rb @@ -1,7 +1,7 @@ -module OpenAI +module ShopifAi class VectorStores def initialize(client:) - @client = client.beta(assistants: OpenAI::Assistants::BETA_VERSION) + @client = client.beta(assistants: ShopifAi::Assistants::BETA_VERSION) end def list(parameters: {}) diff --git a/lib/shopif_ai/version.rb b/lib/shopif_ai/version.rb new file mode 100644 index 00000000..6b4543b8 --- /dev/null +++ b/lib/shopif_ai/version.rb @@ -0,0 +1,3 @@ +module ShopifAi + VERSION = "9.0.0".freeze +end diff --git a/ruby-openai.gemspec b/ruby-openai.gemspec index 6b17e66f..385a5894 100644 --- a/ruby-openai.gemspec +++ b/ruby-openai.gemspec @@ -1,8 +1,8 @@ -require_relative "lib/openai/version" +require_relative "lib/shopif_ai/version" Gem::Specification.new do |spec| spec.name = "ruby-openai" - spec.version = OpenAI::VERSION + spec.version = ShopifAi::VERSION spec.authors = ["Alex"] spec.email = ["alexrudall@users.noreply.github.com"] diff --git a/spec/openai_spec.rb b/spec/openai_spec.rb deleted file mode 100644 index f3b4eee8..00000000 --- a/spec/openai_spec.rb +++ /dev/null @@ -1,71 +0,0 @@ -RSpec.describe OpenAI do - it "has a version number" do - expect(OpenAI::VERSION).not_to be nil - end - - describe "#configure" do - let(:access_token) { "abc123" } - let(:api_version) { "v2" } - let(:organization_id) { "def456" } - let(:custom_uri_base) { "ghi789" } - let(:custom_request_timeout) { 25 } - let(:extra_headers) { { "User-Agent" => "OpenAI Ruby Gem #{OpenAI::VERSION}" } } - - before do - OpenAI.configure do |config| - config.access_token = access_token - config.api_version = api_version - config.organization_id = organization_id - config.extra_headers = extra_headers - end - end - - it "returns the config" do - expect(OpenAI.configuration.access_token).to eq(access_token) - expect(OpenAI.configuration.api_version).to eq(api_version) - expect(OpenAI.configuration.organization_id).to eq(organization_id) - expect(OpenAI.configuration.uri_base).to eq("https://api.openai.com/") - expect(OpenAI.configuration.request_timeout).to eq(120) - expect(OpenAI.configuration.extra_headers).to eq(extra_headers) - end - - context "with custom timeout and uri base" do - before do - OpenAI.configure do |config| - config.uri_base = custom_uri_base - config.request_timeout = custom_request_timeout - end - end - - it "returns the config" do - expect(OpenAI.configuration.access_token).to eq(access_token) - expect(OpenAI.configuration.api_version).to eq(api_version) - expect(OpenAI.configuration.organization_id).to eq(organization_id) - expect(OpenAI.configuration.uri_base).to eq(custom_uri_base) - expect(OpenAI.configuration.request_timeout).to eq(custom_request_timeout) - expect(OpenAI.configuration.extra_headers).to eq(extra_headers) - end - end - end - - describe "#rough_token_count" do - context "on a non-String" do - it "raises an error" do - expect { OpenAI.rough_token_count([]) }.to raise_error(ArgumentError) - end - end - - context "on the empty string" do - it "returns 0" do - expect(OpenAI.rough_token_count("")).to eq(0) - end - end - - context "on a string" do - let(:content) { "Red is my favorite color. Egg is not a necessary ingredient." } - it "estimates tokens" do - expect(OpenAI.rough_token_count(content)).to eq(15) - end - end - end -end diff --git a/spec/openai/client/assistants_spec.rb b/spec/shopif_ai/client/assistants_spec.rb similarity index 80% rename from spec/openai/client/assistants_spec.rb rename to spec/shopif_ai/client/assistants_spec.rb index 49837c7d..212ba567 100644 --- a/spec/openai/client/assistants_spec.rb +++ b/spec/shopif_ai/client/assistants_spec.rb @@ -1,8 +1,8 @@ -RSpec.describe OpenAI::Client do +RSpec.describe ShopifAi::Client do describe "#assistants" do let(:assistant_id) do VCR.use_cassette("#{cassette} setup") do - OpenAI::Client.new.assistants.create( + ShopifAi::Client.new.assistants.create( parameters: { model: "gpt-4", name: "OpenAI-Ruby test assistant" @@ -12,7 +12,7 @@ end describe "#list", :vcr do - let(:response) { OpenAI::Client.new.assistants.list } + let(:response) { ShopifAi::Client.new.assistants.list } let(:cassette) { "assistants list" } before { assistant_id } @@ -26,7 +26,7 @@ describe "#retrieve" do let(:cassette) { "assistants retrieve" } - let(:response) { OpenAI::Client.new.assistants.retrieve(id: assistant_id) } + let(:response) { ShopifAi::Client.new.assistants.retrieve(id: assistant_id) } it "succeeds" do VCR.use_cassette(cassette) do @@ -38,7 +38,7 @@ describe "#create" do let(:cassette) { "assistants create" } let(:response) do - OpenAI::Client.new.assistants.create(parameters: { model: "gpt-4", + ShopifAi::Client.new.assistants.create(parameters: { model: "gpt-4", name: "OpenAI-Ruby test assistant" }) end @@ -52,7 +52,7 @@ describe "#modify" do let(:cassette) { "assistants modify" } let(:response) do - OpenAI::Client.new.assistants.modify( + ShopifAi::Client.new.assistants.modify( id: assistant_id, parameters: { model: "gpt-3.5-turbo", name: "Test Assistant for OpenAI-Ruby" } ) @@ -68,7 +68,7 @@ describe "#delete" do let(:cassette) { "assistants delete" } let(:response) do - OpenAI::Client.new.assistants.delete(id: assistant_id) + ShopifAi::Client.new.assistants.delete(id: assistant_id) end it "succeeds" do diff --git a/spec/openai/client/audio_spec.rb b/spec/shopif_ai/client/audio_spec.rb similarity index 91% rename from spec/openai/client/audio_spec.rb rename to spec/shopif_ai/client/audio_spec.rb index 52ac489a..0457a1a8 100644 --- a/spec/openai/client/audio_spec.rb +++ b/spec/shopif_ai/client/audio_spec.rb @@ -1,4 +1,4 @@ -RSpec.describe OpenAI::Client do +RSpec.describe ShopifAi::Client do describe "#audio" do describe "#transcribe" do context "with audio", :vcr do @@ -6,7 +6,7 @@ let(:audio) { File.join(RSPEC_ROOT, "fixtures/files", filename) } let(:response) do - OpenAI::Client.new.audio.transcribe( + ShopifAi::Client.new.audio.transcribe( parameters: { model: model, file: File.open(audio, "rb") @@ -34,7 +34,7 @@ let(:audio) { File.join(RSPEC_ROOT, "fixtures/files", filename) } let(:response) do - OpenAI::Client.new.audio.translate( + ShopifAi::Client.new.audio.translate( parameters: { model: model, file: File.open(audio, "rb") @@ -62,7 +62,7 @@ it "returns a working mp3 file as body" do VCR.use_cassette("speech #{model} test") do - response = OpenAI::Client.new.audio.speech( + response = ShopifAi::Client.new.audio.speech( parameters: { model: model, input: "This is a speech test!", diff --git a/spec/openai/client/batches_spec.rb b/spec/shopif_ai/client/batches_spec.rb similarity index 83% rename from spec/openai/client/batches_spec.rb rename to spec/shopif_ai/client/batches_spec.rb index 69c835e1..2b964173 100644 --- a/spec/openai/client/batches_spec.rb +++ b/spec/shopif_ai/client/batches_spec.rb @@ -1,17 +1,17 @@ -RSpec.describe OpenAI::Client do +RSpec.describe ShopifAi::Client do describe "#batches" do let(:filename) { "batch.jsonl" } let(:file) { File.join(RSPEC_ROOT, "fixtures/files", filename) } let(:upload_purpose) { "batch" } let(:input_file) do VCR.use_cassette(input_cassette) do - OpenAI::Client.new.files.upload(parameters: { file: file, purpose: upload_purpose }) + ShopifAi::Client.new.files.upload(parameters: { file: file, purpose: upload_purpose }) end end let(:input_file_id) { input_file["id"] } let(:batch_id) do VCR.use_cassette("#{cassette} setup") do - OpenAI::Client.new.batches.create( + ShopifAi::Client.new.batches.create( parameters: { input_file_id: input_file_id, endpoint: "/v1/chat/completions", @@ -25,9 +25,9 @@ let(:input_cassette) { "batches list input" } let(:cassette) { "batches list" } let(:limit) { 10 } - let(:response) { OpenAI::Client.new.batches.list } + let(:response) { ShopifAi::Client.new.batches.list } let(:existing_batch) do - OpenAI::Client.new.batches.create( + ShopifAi::Client.new.batches.create( parameters: { input_file_id: input_file_id, endpoint: "/v1/chat/completions", @@ -46,7 +46,7 @@ it "supports after and limit parameters" do VCR.use_cassette(cassette) do - response = OpenAI::Client.new.batches.list(parameters: { + response = ShopifAi::Client.new.batches.list(parameters: { after: existing_batch["id"], limit: limit }) @@ -60,7 +60,7 @@ describe "#retrieve" do let(:input_cassette) { "batches retrieve input" } let(:cassette) { "batches retrieve" } - let(:response) { OpenAI::Client.new.batches.retrieve(id: batch_id) } + let(:response) { ShopifAi::Client.new.batches.retrieve(id: batch_id) } it "succeeds" do VCR.use_cassette(cassette) do @@ -73,7 +73,7 @@ let(:input_cassette) { "batches create input" } let(:cassette) { "batches create" } let(:response) do - OpenAI::Client.new.batches.create(parameters: { + ShopifAi::Client.new.batches.create(parameters: { input_file_id: input_file_id, endpoint: "/v1/chat/completions", completion_window: "24h" @@ -91,7 +91,7 @@ let(:input_cassette) { "batches cancel input" } let(:cassette) { "batches cancel" } let(:response) do - OpenAI::Client.new.batches.cancel(id: batch_id) + ShopifAi::Client.new.batches.cancel(id: batch_id) end it "succeeds" do diff --git a/spec/openai/client/chat_spec.rb b/spec/shopif_ai/client/chat_spec.rb similarity index 97% rename from spec/openai/client/chat_spec.rb rename to spec/shopif_ai/client/chat_spec.rb index ca58071a..170f0265 100644 --- a/spec/openai/client/chat_spec.rb +++ b/spec/shopif_ai/client/chat_spec.rb @@ -1,11 +1,11 @@ -RSpec.describe OpenAI::Client do +RSpec.describe ShopifAi::Client do describe "#chat" do context "with messages", :vcr do let(:messages) { [{ role: "user", content: "Hello!" }] } let(:stream) { false } let(:uri_base) { nil } let(:response) do - OpenAI::Client.new({ uri_base: uri_base }).chat( + ShopifAi::Client.new({ uri_base: uri_base }).chat( parameters: parameters ) end @@ -114,7 +114,7 @@ } end - second_response = OpenAI::Client.new.chat( + second_response = ShopifAi::Client.new.chat( parameters: { model: model, messages: messages @@ -239,7 +239,7 @@ def call(chunk) let(:provider) { "deepseek" } let(:model) { "deepseek-chat" } let(:response) do - OpenAI::Client.new({ uri_base: uri_base }).chat( + ShopifAi::Client.new({ uri_base: uri_base }).chat( parameters: parameters ) end @@ -267,7 +267,7 @@ def call(chunk) let(:provider) { "groq" } let(:model) { "llama3-8b-8192" } let(:response) do - OpenAI::Client.new({ uri_base: uri_base }).chat( + ShopifAi::Client.new({ uri_base: uri_base }).chat( parameters: parameters ) end diff --git a/spec/openai/client/client_spec.rb b/spec/shopif_ai/client/client_spec.rb similarity index 89% rename from spec/openai/client/client_spec.rb rename to spec/shopif_ai/client/client_spec.rb index 487fcc0b..836cd8fb 100644 --- a/spec/openai/client/client_spec.rb +++ b/spec/shopif_ai/client/client_spec.rb @@ -1,7 +1,7 @@ -RSpec.describe OpenAI::Client do +RSpec.describe ShopifAi::Client do context "with clients with different access tokens" do before do - OpenAI.configure do |config| + ShopifAi.configure do |config| config.organization_id = "organization_id0" config.extra_headers = { "test" => "X-Default" } end @@ -10,15 +10,15 @@ after do # Necessary otherwise the dummy organization_id bleeds into other specs # that actually hit the API and causes them to fail. - OpenAI.configure do |config| + ShopifAi.configure do |config| config.organization_id = nil config.extra_headers = {} end end - let!(:c0) { OpenAI::Client.new } + let!(:c0) { ShopifAi::Client.new } let!(:c1) do - OpenAI::Client.new( + ShopifAi::Client.new( api_type: "azure", access_token: "access_token1", organization_id: "organization_id1", @@ -28,7 +28,7 @@ ) end let!(:c2) do - OpenAI::Client.new( + ShopifAi::Client.new( access_token: "access_token2", organization_id: nil, request_timeout: 1, @@ -40,12 +40,12 @@ expect(c0.azure?).to eq(false) expect(c0.access_token).to eq(ENV.fetch("OPENAI_ACCESS_TOKEN", "dummy-token")) expect(c0.organization_id).to eq("organization_id0") - expect(c0.request_timeout).to eq(OpenAI::Configuration::DEFAULT_REQUEST_TIMEOUT) - expect(c0.uri_base).to eq(OpenAI::Configuration::DEFAULT_URI_BASE) + expect(c0.request_timeout).to eq(ShopifAi::Configuration::DEFAULT_REQUEST_TIMEOUT) + expect(c0.uri_base).to eq(ShopifAi::Configuration::DEFAULT_URI_BASE) expect(c0.send(:headers).values).to include("Bearer #{c0.access_token}") expect(c0.send(:headers).values).to include(c0.organization_id) - expect(c0.send(:conn).options.timeout).to eq(OpenAI::Configuration::DEFAULT_REQUEST_TIMEOUT) - expect(c0.send(:uri, path: "")).to include(OpenAI::Configuration::DEFAULT_URI_BASE) + expect(c0.send(:conn).options.timeout).to eq(ShopifAi::Configuration::DEFAULT_REQUEST_TIMEOUT) + expect(c0.send(:uri, path: "")).to include(ShopifAi::Configuration::DEFAULT_URI_BASE) expect(c0.send(:headers).values).to include("X-Default") expect(c0.send(:headers).values).not_to include("X-Test") @@ -117,7 +117,7 @@ context "with admin token configured" do let(:client) do - OpenAI::Client.new(admin_token: admin_token) + ShopifAi::Client.new(admin_token: admin_token) end it "creates a new client instance with admin token as access token" do @@ -130,7 +130,7 @@ context "when using both beta and admin" do let(:client) do - OpenAI::Client.new(admin_token: admin_token) + ShopifAi::Client.new(admin_token: admin_token) end it "allows chaining beta and admin" do @@ -148,7 +148,7 @@ end context "when using beta APIs" do - let(:client) { OpenAI::Client.new.beta(assistants: "v2") } + let(:client) { ShopifAi::Client.new.beta(assistants: "v2") } it "sends the appropriate header value" do expect(client.send(:headers)["OpenAI-Beta"]).to eq "assistants=v2" @@ -157,7 +157,7 @@ context "with a block" do let(:client) do - OpenAI::Client.new do |client| + ShopifAi::Client.new do |client| client.response :logger, Logger.new($stdout), bodies: true end end @@ -176,7 +176,7 @@ let(:uri_base) { "https://example.com/" } let(:request_timeout) { 500 } let(:client) do - OpenAI::Client.new( + ShopifAi::Client.new( uri_base: uri_base, request_timeout: request_timeout, access_token: api_key, diff --git a/spec/openai/client/completions_spec.rb b/spec/shopif_ai/client/completions_spec.rb similarity index 89% rename from spec/openai/client/completions_spec.rb rename to spec/shopif_ai/client/completions_spec.rb index 78eb69f3..239b31b7 100644 --- a/spec/openai/client/completions_spec.rb +++ b/spec/shopif_ai/client/completions_spec.rb @@ -1,11 +1,11 @@ -RSpec.describe OpenAI::Client do +RSpec.describe ShopifAi::Client do describe "#completions: gpt-3.5-turbo-instruct" do context "with a prompt and max_tokens", :vcr do let(:prompt) { "Once upon a time" } let(:max_tokens) { 5 } let(:response) do - OpenAI::Client.new.completions( + ShopifAi::Client.new.completions( parameters: { model: model, prompt: prompt, diff --git a/spec/openai/client/conversations_spec.rb b/spec/shopif_ai/client/conversations_spec.rb similarity index 85% rename from spec/openai/client/conversations_spec.rb rename to spec/shopif_ai/client/conversations_spec.rb index 2b799d83..162dbba5 100644 --- a/spec/openai/client/conversations_spec.rb +++ b/spec/shopif_ai/client/conversations_spec.rb @@ -1,13 +1,13 @@ -RSpec.describe OpenAI::Client do +RSpec.describe ShopifAi::Client do describe "#conversations" do let(:conversation_id) do VCR.use_cassette("#{cassette} setup") do - OpenAI::Client.new.conversations.create(parameters: {})["id"] + ShopifAi::Client.new.conversations.create(parameters: {})["id"] end end let(:item_id) do VCR.use_cassette("#{cassette} item setup") do - OpenAI::Client.new.conversations.create_items( + ShopifAi::Client.new.conversations.create_items( conversation_id: conversation_id, parameters: { items: [ @@ -26,7 +26,7 @@ describe "#retrieve" do let(:cassette) { "conversations retrieve" } - let(:response) { OpenAI::Client.new.conversations.retrieve(id: conversation_id) } + let(:response) { ShopifAi::Client.new.conversations.retrieve(id: conversation_id) } it "succeeds" do VCR.use_cassette(cassette) do @@ -38,7 +38,7 @@ describe "#create" do let(:cassette) { "conversations create" } let(:response) do - OpenAI::Client.new.conversations.create(parameters: {}) + ShopifAi::Client.new.conversations.create(parameters: {}) end it "succeeds" do @@ -49,7 +49,7 @@ context "with parameters" do let(:response) do - OpenAI::Client.new.conversations.create( + ShopifAi::Client.new.conversations.create( parameters: { metadata: { purpose: "test" } } ) end @@ -65,7 +65,7 @@ describe "#modify" do let(:cassette) { "conversations modify" } let(:response) do - OpenAI::Client.new.conversations.modify( + ShopifAi::Client.new.conversations.modify( id: conversation_id, parameters: { metadata: { modified: "true" } } ) @@ -81,7 +81,7 @@ describe "#delete" do let(:cassette) { "conversations delete" } let(:response) do - OpenAI::Client.new.conversations.delete(id: conversation_id) + ShopifAi::Client.new.conversations.delete(id: conversation_id) end it "succeeds" do @@ -94,7 +94,7 @@ describe "#list_items" do let(:cassette) { "conversations list items" } let(:response) do - OpenAI::Client.new.conversations.list_items(conversation_id: conversation_id) + ShopifAi::Client.new.conversations.list_items(conversation_id: conversation_id) end before { item_id } @@ -107,7 +107,7 @@ context "with parameters" do let(:response) do - OpenAI::Client.new.conversations.list_items( + ShopifAi::Client.new.conversations.list_items( conversation_id: conversation_id, parameters: { limit: 5 } ) @@ -124,7 +124,7 @@ describe "#get_item" do let(:cassette) { "conversations get item" } let(:response) do - OpenAI::Client.new.conversations.get_item( + ShopifAi::Client.new.conversations.get_item( conversation_id: conversation_id, item_id: item_id ) @@ -140,7 +140,7 @@ describe "#create_items" do let(:cassette) { "conversations create items" } let(:response) do - OpenAI::Client.new.conversations.create_items( + ShopifAi::Client.new.conversations.create_items( conversation_id: conversation_id, parameters: { items: [ @@ -171,7 +171,7 @@ context "with multiple items" do let(:response) do - OpenAI::Client.new.conversations.create_items( + ShopifAi::Client.new.conversations.create_items( conversation_id: conversation_id, parameters: { items: [ @@ -205,7 +205,7 @@ describe "#delete_item" do let(:cassette) { "conversations delete item" } let(:response) do - OpenAI::Client.new.conversations.delete_item( + ShopifAi::Client.new.conversations.delete_item( conversation_id: conversation_id, item_id: item_id ) diff --git a/spec/openai/client/embeddings_spec.rb b/spec/shopif_ai/client/embeddings_spec.rb similarity index 88% rename from spec/openai/client/embeddings_spec.rb rename to spec/shopif_ai/client/embeddings_spec.rb index 52fcb386..28d73533 100644 --- a/spec/openai/client/embeddings_spec.rb +++ b/spec/shopif_ai/client/embeddings_spec.rb @@ -1,9 +1,9 @@ -RSpec.describe OpenAI::Client do +RSpec.describe ShopifAi::Client do describe "#embeddings", :vcr do let(:input) { "The food was delicious and the waiter..." } let(:cassette) { "#{model} embeddings #{input}".downcase } let(:response) do - OpenAI::Client.new.embeddings( + ShopifAi::Client.new.embeddings( parameters: { model: model, input: input diff --git a/spec/openai/client/files_spec.rb b/spec/shopif_ai/client/files_spec.rb similarity index 82% rename from spec/openai/client/files_spec.rb rename to spec/shopif_ai/client/files_spec.rb index da0f7747..5f2ede08 100644 --- a/spec/openai/client/files_spec.rb +++ b/spec/shopif_ai/client/files_spec.rb @@ -1,11 +1,11 @@ -RSpec.describe OpenAI::Client do +RSpec.describe ShopifAi::Client do describe "#files", :vcr do let(:filename) { "sentiment.jsonl" } let(:file) { File.join(RSPEC_ROOT, "fixtures/files", filename) } let(:upload_purpose) { "fine-tune" } let(:upload) do VCR.use_cassette(upload_cassette) do - OpenAI::Client.new.files.upload(parameters: { file: file, purpose: upload_purpose }) + ShopifAi::Client.new.files.upload(parameters: { file: file, purpose: upload_purpose }) end end let(:upload_id) { upload["id"] } @@ -26,13 +26,13 @@ it "logs a warning" do expected_message = "The purpose 'invalid' for file 'sentiment.jsonl' is not in the known " - expected_message += "purpose list: #{OpenAI::Files::PURPOSES.join(', ')}." + expected_message += "purpose list: #{ShopifAi::Files::PURPOSES.join(', ')}." - expect(OpenAI).to receive(:log_message) + expect(ShopifAi).to receive(:log_message) .with("Warning", expected_message, :warn) .and_call_original - allow_any_instance_of(OpenAI::Client).to receive(:multipart_post).and_return({}) + allow_any_instance_of(ShopifAi::Client).to receive(:multipart_post).and_return({}) upload end @@ -71,7 +71,7 @@ describe "#list" do let(:cassette) { "files list" } let(:upload_cassette) { "#{cassette} upload" } - let(:response) { OpenAI::Client.new.files.list(parameters: { purpose: "fine-tune" }) } + let(:response) { ShopifAi::Client.new.files.list(parameters: { purpose: "fine-tune" }) } before { upload } @@ -85,7 +85,7 @@ describe "#retrieve" do let(:cassette) { "files retrieve" } let(:upload_cassette) { "#{cassette} upload" } - let(:response) { OpenAI::Client.new.files.retrieve(id: upload_id, parameters: {}) } + let(:response) { ShopifAi::Client.new.files.retrieve(id: upload_id, parameters: {}) } it "succeeds" do VCR.use_cassette(cassette) do @@ -97,7 +97,7 @@ describe "#content" do let(:cassette) { "files content" } let(:upload_cassette) { "#{cassette} upload" } - let(:response) { OpenAI::Client.new.files.content(id: upload_id, parameters: {}) } + let(:response) { ShopifAi::Client.new.files.content(id: upload_id, parameters: {}) } it "succeeds" do VCR.use_cassette(cassette) do @@ -111,14 +111,14 @@ let(:upload_cassette) { "#{cassette} upload" } let(:retrieve_cassette) { "#{cassette} retrieve" } let(:response) do - OpenAI::Client.new.files.delete(id: upload_id) + ShopifAi::Client.new.files.delete(id: upload_id) end before do # We need to check the file has been processed by OpenAI # before we can delete it. retrieved = VCR.use_cassette(retrieve_cassette) do - OpenAI::Client.new.files.retrieve(id: upload_id) + ShopifAi::Client.new.files.retrieve(id: upload_id) end tries = 0 until retrieved["status"] == "processed" @@ -126,7 +126,7 @@ sleep(1) retrieved = VCR.use_cassette(retrieve_cassette, record: :all) do - OpenAI::Client.new.files.retrieve(id: upload_id) + ShopifAi::Client.new.files.retrieve(id: upload_id) end tries += 1 end @@ -147,13 +147,13 @@ let(:filename) { "image.png" } let(:file) { File.join(RSPEC_ROOT, "fixtures/files", filename) } let(:upload_purpose) { "vision" } - let(:response) { OpenAI::Client.new.files.content(id: upload_id) } + let(:response) { ShopifAi::Client.new.files.content(id: upload_id) } before do # We need to check the file has been processed by OpenAI # before we can delete it. retrieved = VCR.use_cassette(retrieve_cassette) do - OpenAI::Client.new.files.retrieve(id: upload_id) + ShopifAi::Client.new.files.retrieve(id: upload_id) end tries = 0 until retrieved["status"] == "processed" @@ -161,7 +161,7 @@ sleep(1) retrieved = VCR.use_cassette(retrieve_cassette, record: :all) do - OpenAI::Client.new.files.retrieve(id: upload_id) + ShopifAi::Client.new.files.retrieve(id: upload_id) end tries += 1 end diff --git a/spec/openai/client/finetunes_spec.rb b/spec/shopif_ai/client/finetunes_spec.rb similarity index 82% rename from spec/openai/client/finetunes_spec.rb rename to spec/shopif_ai/client/finetunes_spec.rb index 81878bf9..bbcaaa03 100644 --- a/spec/openai/client/finetunes_spec.rb +++ b/spec/shopif_ai/client/finetunes_spec.rb @@ -1,10 +1,10 @@ -RSpec.describe OpenAI::Client do +RSpec.describe ShopifAi::Client do describe "#finetunes", :vcr do let(:model) { "gpt-4o-2024-08-06" } describe "#list" do let(:cassette) { "finetunes list" } - let(:response) { OpenAI::Client.new.finetunes.list } + let(:response) { ShopifAi::Client.new.finetunes.list } it "succeeds" do VCR.use_cassette(cassette) do @@ -19,21 +19,21 @@ let(:cassette) { "finetunes" } let(:upload_id) do response = VCR.use_cassette("finetunes files upload") do - OpenAI::Client.new.files.upload(parameters: { file: file, purpose: "fine-tune" }) + ShopifAi::Client.new.files.upload(parameters: { file: file, purpose: "fine-tune" }) end response["id"] end let(:retrieve_cassette) { "#{cassette} retrieve for create" } let(:file_id) do VCR.use_cassette(retrieve_cassette) do - OpenAI::Client.new.files.retrieve(id: upload_id) + ShopifAi::Client.new.files.retrieve(id: upload_id) end upload_id end let(:response) do VCR.use_cassette("#{cassette} create") do - OpenAI::Client.new.finetunes.create( + ShopifAi::Client.new.finetunes.create( parameters: { training_file: file_id, model: model @@ -49,7 +49,7 @@ describe "#retrieve" do let(:cassette) { "finetunes retrieve" } - let(:response) { OpenAI::Client.new.finetunes.retrieve(id: 123) } + let(:response) { ShopifAi::Client.new.finetunes.retrieve(id: 123) } it "succeeds" do VCR.use_cassette(cassette) do @@ -65,7 +65,7 @@ describe "#cancel" do let(:cassette) { "finetunes cancel" } - let(:response) { OpenAI::Client.new.finetunes.cancel(id: 123) } + let(:response) { ShopifAi::Client.new.finetunes.cancel(id: 123) } it "succeeds" do VCR.use_cassette(cassette) do @@ -81,7 +81,7 @@ describe "#list_events" do let(:cassette) { "finetunes event list" } - let(:response) { OpenAI::Client.new.finetunes.list_events(id: 123) } + let(:response) { ShopifAi::Client.new.finetunes.list_events(id: 123) } it "succeeds" do VCR.use_cassette(cassette) do diff --git a/spec/openai/client/http_spec.rb b/spec/shopif_ai/client/http_spec.rb similarity index 81% rename from spec/openai/client/http_spec.rb rename to spec/shopif_ai/client/http_spec.rb index 4c5814dc..939c5b01 100644 --- a/spec/openai/client/http_spec.rb +++ b/spec/shopif_ai/client/http_spec.rb @@ -1,8 +1,8 @@ -RSpec.describe OpenAI::HTTP do +RSpec.describe ShopifAi::HTTP do describe "extra_headers" do include WebMock::API - let(:client) { OpenAI::Client.new } + let(:client) { ShopifAi::Client.new } let(:custom_headers) { { "X-Custom-Header" => "custom-value", "X-Another" => "another-value" } } let(:chat_url) { "https://api.openai.com/v1/chat/completions" } @@ -53,17 +53,17 @@ before do VCR.turn_off! WebMock.allow_net_connect! - OpenAI.configuration.request_timeout = timeout + ShopifAi.configuration.request_timeout = timeout end after do VCR.turn_on! WebMock.disable_net_connect! - OpenAI.configuration.request_timeout = OpenAI::Configuration::DEFAULT_REQUEST_TIMEOUT + ShopifAi.configuration.request_timeout = ShopifAi::Configuration::DEFAULT_REQUEST_TIMEOUT end describe ".get" do - let(:response) { OpenAI::Client.new.models.list } + let(:response) { ShopifAi::Client.new.models.list } it "times out" do expect { response }.to raise_error do |error| @@ -74,7 +74,7 @@ describe ".json_post" do let(:response) do - OpenAI::Client.new.chat(parameters: parameters) + ShopifAi::Client.new.chat(parameters: parameters) end let(:parameters) do @@ -122,7 +122,7 @@ let(:file) { File.join(RSPEC_ROOT, "fixtures/files", filename) } let(:upload_purpose) { "fine-tune" } let(:response) do - OpenAI::Client.new.files.upload( + ShopifAi::Client.new.files.upload( parameters: { file: file, purpose: upload_purpose } ) end @@ -136,7 +136,7 @@ describe ".delete" do let(:response) do - OpenAI::Client.new.files.delete(id: "1a") + ShopifAi::Client.new.files.delete(id: "1a") end it "times out" do @@ -153,7 +153,7 @@ it "raises an HTTP error" do VCR.use_cassette(cassette, record: :none) do - OpenAI::Client.new.models.retrieve(id: "text-ada-001") + ShopifAi::Client.new.models.retrieve(id: "text-ada-001") rescue Faraday::Error => e expect(e.response).to include(status: 400) else @@ -166,14 +166,14 @@ describe ".parse_json" do context "with a jsonl string" do let(:body) { "{\"prompt\":\":)\"}\n{\"prompt\":\":(\"}\n" } - let(:parsed) { OpenAI::Client.new.send(:parse_json, body) } + let(:parsed) { ShopifAi::Client.new.send(:parse_json, body) } it { expect(parsed).to eq([{ "prompt" => ":)" }, { "prompt" => ":(" }]) } end context "with a non-json string containing newline-brace pattern" do let(:body) { "Hello}\n{World" } - let(:parsed) { OpenAI::Client.new.send(:parse_json, body) } + let(:parsed) { ShopifAi::Client.new.send(:parse_json, body) } it "returns the original string when JSON parsing fails" do expect(parsed).to eq("Hello}\n{World") @@ -183,17 +183,17 @@ describe ".uri" do let(:path) { "/chat" } - let(:uri) { OpenAI::Client.new.send(:uri, path: path) } + let(:uri) { ShopifAi::Client.new.send(:uri, path: path) } it { expect(uri).to eq("https://api.openai.com/v1/chat") } context "uri_base with version included" do before do - OpenAI.configuration.uri_base = "https://api.openai.com/v1/" + ShopifAi.configuration.uri_base = "https://api.openai.com/v1/" end after do - OpenAI.configuration.uri_base = "https://api.openai.com/" + ShopifAi.configuration.uri_base = "https://api.openai.com/" end it { expect(uri).to eq("https://api.openai.com/v1/chat") } @@ -201,11 +201,11 @@ context "uri_base without trailing slash" do before do - OpenAI.configuration.uri_base = "https://api.openai.com" + ShopifAi.configuration.uri_base = "https://api.openai.com" end after do - OpenAI.configuration.uri_base = "https://api.openai.com/" + ShopifAi.configuration.uri_base = "https://api.openai.com/" end it { expect(uri).to eq("https://api.openai.com/v1/chat") } @@ -213,17 +213,17 @@ describe "with Azure" do before do - OpenAI.configuration.uri_base = uri_base - OpenAI.configuration.api_type = :azure + ShopifAi.configuration.uri_base = uri_base + ShopifAi.configuration.api_type = :azure end after do - OpenAI.configuration.uri_base = "https://api.openai.com/" - OpenAI.configuration.api_type = nil + ShopifAi.configuration.uri_base = "https://api.openai.com/" + ShopifAi.configuration.api_type = nil end let(:path) { "/chat" } - let(:uri) { OpenAI::Client.new.send(:uri, path: path) } + let(:uri) { ShopifAi::Client.new.send(:uri, path: path) } context "with a trailing slash" do let(:uri_base) { "https://custom-domain.openai.azure.com/openai/deployments/gpt-35-turbo/" } @@ -239,10 +239,10 @@ describe ".headers" do before do - OpenAI.configuration.api_type = :nil + ShopifAi.configuration.api_type = :nil end - let(:headers) { OpenAI::Client.new.send(:headers) } + let(:headers) { ShopifAi::Client.new.send(:headers) } it "includes expected headers" do expect(headers).to have_key("Authorization") @@ -253,14 +253,14 @@ describe "with Azure" do before do - OpenAI.configuration.api_type = :azure + ShopifAi.configuration.api_type = :azure end after do - OpenAI.configuration.api_type = nil + ShopifAi.configuration.api_type = nil end - let(:headers) { OpenAI::Client.new.send(:headers) } + let(:headers) { ShopifAi::Client.new.send(:headers) } it "includes expected headers" do expect(headers).to have_key("api-key") @@ -285,7 +285,7 @@ it "is disabled by default" do VCR.use_cassette(cassette, record: :none) do - expect { OpenAI::Client.new.models.retrieve(id: "text-ada-001") } + expect { ShopifAi::Client.new.models.retrieve(id: "text-ada-001") } .to raise_error Faraday::Error $stdout.rewind @@ -299,7 +299,7 @@ it "logs errors" do VCR.use_cassette(cassette, record: :none) do - expect { OpenAI::Client.new(log_errors: log_errors).models.retrieve(id: "text-ada-001") } + expect { ShopifAi::Client.new(log_errors: log_errors).models.retrieve(id: "text-ada-001") } .to raise_error Faraday::Error $stdout.rewind @@ -314,7 +314,7 @@ it "does not log errors" do VCR.use_cassette(cassette, record: :none) do - expect { OpenAI::Client.new(log_errors: log_errors).models.retrieve(id: "text-ada-001") } + expect { ShopifAi::Client.new(log_errors: log_errors).models.retrieve(id: "text-ada-001") } .to raise_error Faraday::Error $stdout.rewind diff --git a/spec/openai/client/images_spec.rb b/spec/shopif_ai/client/images_spec.rb similarity index 93% rename from spec/openai/client/images_spec.rb rename to spec/shopif_ai/client/images_spec.rb index a639f18b..ffff25b2 100644 --- a/spec/openai/client/images_spec.rb +++ b/spec/shopif_ai/client/images_spec.rb @@ -1,9 +1,9 @@ -RSpec.describe OpenAI::Client do +RSpec.describe ShopifAi::Client do describe "#images" do describe "#dall-e-2" do describe "#generate", :vcr do let(:response) do - OpenAI::Client.new.images.generate( + ShopifAi::Client.new.images.generate( parameters: { prompt: prompt, size: size, @@ -25,7 +25,7 @@ describe "#edit", :vcr do let(:response) do - OpenAI::Client.new.images.edit( + ShopifAi::Client.new.images.edit( parameters: { image: image, mask: mask, @@ -53,7 +53,7 @@ describe "#variations", :vcr do let(:response) do - OpenAI::Client.new.images.variations( + ShopifAi::Client.new.images.variations( parameters: { image: image, n: 2, @@ -78,7 +78,7 @@ describe "#generate" do describe "#standard", :vcr do let(:response) do - OpenAI::Client.new.images.generate( + ShopifAi::Client.new.images.generate( parameters: { prompt: prompt, size: size, @@ -100,7 +100,7 @@ describe "#hd", :vcr do let(:response) do - OpenAI::Client.new.images.generate( + ShopifAi::Client.new.images.generate( parameters: { prompt: prompt, size: size, @@ -126,7 +126,7 @@ describe "with multiple images", :vcr do let(:response) do - OpenAI::Client.new.images.edit( + ShopifAi::Client.new.images.edit( parameters: { image: [ File.join(RSPEC_ROOT, "fixtures/files", "image.png"), diff --git a/spec/openai/client/messages_spec.rb b/spec/shopif_ai/client/messages_spec.rb similarity index 81% rename from spec/openai/client/messages_spec.rb rename to spec/shopif_ai/client/messages_spec.rb index 317ad888..d5c07e2c 100644 --- a/spec/openai/client/messages_spec.rb +++ b/spec/shopif_ai/client/messages_spec.rb @@ -1,13 +1,13 @@ -RSpec.describe OpenAI::Client do +RSpec.describe ShopifAi::Client do describe "#messages" do let(:thread_id) do VCR.use_cassette("#{cassette} thread setup") do - OpenAI::Client.new.threads.create(parameters: {})["id"] + ShopifAi::Client.new.threads.create(parameters: {})["id"] end end let(:message_id) do VCR.use_cassette("#{cassette} message setup") do - OpenAI::Client.new.messages.create( + ShopifAi::Client.new.messages.create( thread_id: thread_id, parameters: { role: "user", @@ -20,7 +20,7 @@ describe "#retrieve" do let(:cassette) { "messages retrieve" } let(:response) do - OpenAI::Client.new.messages.retrieve(thread_id: thread_id, id: message_id) + ShopifAi::Client.new.messages.retrieve(thread_id: thread_id, id: message_id) end it "succeeds" do @@ -33,7 +33,7 @@ describe "#list" do let(:cassette) { "messages list" } let(:response) do - OpenAI::Client.new.messages.list(thread_id: thread_id, parameters: { order: "asc" }) + ShopifAi::Client.new.messages.list(thread_id: thread_id, parameters: { order: "asc" }) end it "succeeds" do @@ -46,7 +46,7 @@ describe "#create" do let(:cassette) { "messages create" } let(:response) do - OpenAI::Client.new.messages.create( + ShopifAi::Client.new.messages.create( thread_id: thread_id, parameters: { role: "user", @@ -65,7 +65,7 @@ describe "#modify" do let(:cassette) { "messages modify" } let(:response) do - OpenAI::Client.new.messages.modify( + ShopifAi::Client.new.messages.modify( id: message_id, thread_id: thread_id, parameters: { @@ -84,7 +84,7 @@ describe "#delete" do let(:cassette) { "messages delete" } let(:response) do - OpenAI::Client.new.messages.delete(thread_id: thread_id, id: message_id) + ShopifAi::Client.new.messages.delete(thread_id: thread_id, id: message_id) end it "succeeds" do diff --git a/spec/openai/client/models_spec.rb b/spec/shopif_ai/client/models_spec.rb similarity index 80% rename from spec/openai/client/models_spec.rb rename to spec/shopif_ai/client/models_spec.rb index 69297c73..e80f0087 100644 --- a/spec/openai/client/models_spec.rb +++ b/spec/shopif_ai/client/models_spec.rb @@ -1,7 +1,7 @@ -RSpec.describe OpenAI::Client do +RSpec.describe ShopifAi::Client do describe "#models" do describe "#list", :vcr do - let(:response) { OpenAI::Client.new.models.list } + let(:response) { ShopifAi::Client.new.models.list } let(:cassette) { "models list" } it "succeeds" do @@ -13,7 +13,7 @@ describe "#retrieve" do let(:cassette) { "models retrieve" } - let(:response) { OpenAI::Client.new.models.retrieve(id: "gpt-3.5-turbo-instruct") } + let(:response) { ShopifAi::Client.new.models.retrieve(id: "gpt-3.5-turbo-instruct") } it "succeeds" do VCR.use_cassette(cassette) do @@ -29,7 +29,7 @@ it "sends request to the correct endpoint" do VCR.use_cassette(cassette) do - OpenAI::Client.new.models.delete(id: model_id) + ShopifAi::Client.new.models.delete(id: model_id) rescue Faraday::ResourceNotFound => e error_expected = "The model '#{model_id}' does not exist" expect(e.response.dig(:body, "error", "message")).to eq(error_expected) diff --git a/spec/openai/client/moderations_spec.rb b/spec/shopif_ai/client/moderations_spec.rb similarity index 83% rename from spec/openai/client/moderations_spec.rb rename to spec/shopif_ai/client/moderations_spec.rb index bcb6b17e..93bfbb44 100644 --- a/spec/openai/client/moderations_spec.rb +++ b/spec/shopif_ai/client/moderations_spec.rb @@ -1,9 +1,9 @@ -RSpec.describe OpenAI::Client do +RSpec.describe ShopifAi::Client do describe "#moderations", :vcr do let(:input) { "Have a great day!" } let(:cassette) { "moderations #{input}".downcase } let(:response) do - OpenAI::Client.new.moderations( + ShopifAi::Client.new.moderations( parameters: { input: input } diff --git a/spec/openai/client/realtime_spec.rb b/spec/shopif_ai/client/realtime_spec.rb similarity index 92% rename from spec/openai/client/realtime_spec.rb rename to spec/shopif_ai/client/realtime_spec.rb index ad1be929..77035a6d 100644 --- a/spec/openai/client/realtime_spec.rb +++ b/spec/shopif_ai/client/realtime_spec.rb @@ -1,5 +1,5 @@ -RSpec.describe OpenAI::Realtime do - let(:client) { OpenAI::Client.new } +RSpec.describe ShopifAi::Realtime do + let(:client) { ShopifAi::Client.new } let(:realtime) { client.realtime } describe "#create" do diff --git a/spec/openai/client/responses_spec.rb b/spec/shopif_ai/client/responses_spec.rb similarity index 91% rename from spec/openai/client/responses_spec.rb rename to spec/shopif_ai/client/responses_spec.rb index 80f57cf2..13b8480e 100644 --- a/spec/openai/client/responses_spec.rb +++ b/spec/shopif_ai/client/responses_spec.rb @@ -1,4 +1,4 @@ -RSpec.describe OpenAI::Client do +RSpec.describe ShopifAi::Client do describe "#responses" do describe "#create", :vcr do let(:model) { "gpt-4o" } @@ -7,7 +7,7 @@ let(:uri_base) { nil } let(:parameters) { { model: model, input: input, stream: stream } } let(:response) do - OpenAI::Client.new({ uri_base: uri_base }).responses.create( + ShopifAi::Client.new({ uri_base: uri_base }).responses.create( parameters: parameters ) end @@ -29,7 +29,7 @@ previous_response_id: previous_response_id } end let(:followup_response) do - OpenAI::Client.new({ uri_base: uri_base }).responses.create( + ShopifAi::Client.new({ uri_base: uri_base }).responses.create( parameters: followup_parameters ) end @@ -156,7 +156,7 @@ def call(chunk, event) let(:model) { "gpt-4o" } let(:response_id) do VCR.use_cassette("responses retrieve setup") do - OpenAI::Client.new.responses.create( + ShopifAi::Client.new.responses.create( parameters: { model: model, input: "Hello, this is a test response" @@ -164,7 +164,7 @@ def call(chunk, event) )["id"] end end - let(:response) { OpenAI::Client.new.responses.retrieve(response_id: response_id) } + let(:response) { ShopifAi::Client.new.responses.retrieve(response_id: response_id) } let(:cassette) { "responses retrieve" } it "succeeds" do @@ -179,7 +179,7 @@ def call(chunk, event) let(:model) { "gpt-4o" } let(:response_id) do VCR.use_cassette("responses delete setup") do - OpenAI::Client.new.responses.create( + ShopifAi::Client.new.responses.create( parameters: { model: model, input: "Hello, this is a test response for deletion" @@ -187,7 +187,7 @@ def call(chunk, event) )["id"] end end - let(:response) { OpenAI::Client.new.responses.delete(response_id: response_id) } + let(:response) { ShopifAi::Client.new.responses.delete(response_id: response_id) } let(:cassette) { "responses delete" } it "succeeds" do @@ -202,7 +202,7 @@ def call(chunk, event) let(:model) { "gpt-4o" } let(:response_id) do VCR.use_cassette("responses input_items setup") do - OpenAI::Client.new.responses.create( + ShopifAi::Client.new.responses.create( parameters: { model: model, input: "Hello, this is a test response for listing input items" @@ -210,7 +210,7 @@ def call(chunk, event) )["id"] end end - let(:response) { OpenAI::Client.new.responses.input_items(response_id: response_id) } + let(:response) { ShopifAi::Client.new.responses.input_items(response_id: response_id) } let(:cassette) { "responses input_items" } it "succeeds" do diff --git a/spec/openai/client/run_steps_spec.rb b/spec/shopif_ai/client/run_steps_spec.rb similarity index 83% rename from spec/openai/client/run_steps_spec.rb rename to spec/shopif_ai/client/run_steps_spec.rb index 7efb0fb9..1bf19294 100644 --- a/spec/openai/client/run_steps_spec.rb +++ b/spec/shopif_ai/client/run_steps_spec.rb @@ -1,13 +1,13 @@ -RSpec.describe OpenAI::Client do +RSpec.describe ShopifAi::Client do describe "#run_steps" do let(:thread_id) do VCR.use_cassette("#{cassette} thread setup") do - OpenAI::Client.new.threads.create(parameters: {})["id"] + ShopifAi::Client.new.threads.create(parameters: {})["id"] end end let(:assistant_id) do VCR.use_cassette("#{cassette} assistant setup") do - OpenAI::Client.new.assistants.create( + ShopifAi::Client.new.assistants.create( parameters: { model: "gpt-4", name: "OpenAI-Ruby test assistant", @@ -18,7 +18,7 @@ end let(:run_id) do VCR.use_cassette("#{cassette} run setup") do - OpenAI::Client.new.runs.create( + ShopifAi::Client.new.runs.create( thread_id: thread_id, parameters: { assistant_id: assistant_id @@ -30,7 +30,7 @@ describe "#list" do let(:cassette) { "run_steps list" } let(:response) do - OpenAI::Client.new.run_steps.list( + ShopifAi::Client.new.run_steps.list( thread_id: thread_id, run_id: run_id, parameters: { order: "asc" } @@ -47,7 +47,7 @@ describe "#retrieve" do let(:cassette) { "run_steps retrieve" } let(:response) do - OpenAI::Client.new.run_steps.retrieve( + ShopifAi::Client.new.run_steps.retrieve( thread_id: thread_id, run_id: run_id, id: "step_123" diff --git a/spec/openai/client/runs_spec.rb b/spec/shopif_ai/client/runs_spec.rb similarity index 87% rename from spec/openai/client/runs_spec.rb rename to spec/shopif_ai/client/runs_spec.rb index 1469356d..482934f6 100644 --- a/spec/openai/client/runs_spec.rb +++ b/spec/shopif_ai/client/runs_spec.rb @@ -1,16 +1,16 @@ -RSpec.describe OpenAI::Client do +RSpec.describe ShopifAi::Client do let(:max_prompt_tokens) { 256 } let(:max_completion_tokens) { 16 } describe "#runs" do let(:thread_id) do VCR.use_cassette("#{cassette} thread setup") do - OpenAI::Client.new.threads.create(parameters: {})["id"] + ShopifAi::Client.new.threads.create(parameters: {})["id"] end end let(:assistant_id) do VCR.use_cassette("#{cassette} assistant setup") do - OpenAI::Client.new.assistants.create( + ShopifAi::Client.new.assistants.create( parameters: { model: "gpt-4", name: "OpenAI-Ruby test assistant", @@ -21,7 +21,7 @@ end let(:run_id) do VCR.use_cassette("#{cassette} run setup") do - OpenAI::Client.new.runs.create( + ShopifAi::Client.new.runs.create( thread_id: thread_id, parameters: { assistant_id: assistant_id, @@ -35,7 +35,7 @@ describe "#list" do let(:cassette) { "runs list" } let(:response) do - OpenAI::Client.new.runs.list(thread_id: thread_id, parameters: { order: "asc" }) + ShopifAi::Client.new.runs.list(thread_id: thread_id, parameters: { order: "asc" }) end before { run_id } @@ -50,7 +50,7 @@ describe "#retrieve" do let(:cassette) { "runs retrieve" } let(:response) do - OpenAI::Client.new.runs.retrieve(thread_id: thread_id, + ShopifAi::Client.new.runs.retrieve(thread_id: thread_id, id: run_id) end @@ -65,7 +65,7 @@ let(:stream) { false } let(:cassette) { "runs #{'streamed' if stream} create" } let(:response) do - OpenAI::Client.new.runs.create( + ShopifAi::Client.new.runs.create( thread_id: thread_id, parameters: { assistant_id: assistant_id, @@ -102,7 +102,7 @@ describe "#modify" do let(:cassette) { "runs modify" } let(:response) do - OpenAI::Client.new.runs.modify( + ShopifAi::Client.new.runs.modify( id: run_id, thread_id: thread_id, parameters: { @@ -123,7 +123,7 @@ context "for a run in progress" do let(:response) do - OpenAI::Client.new.runs.cancel( + ShopifAi::Client.new.runs.cancel( id: run_id, thread_id: thread_id ) @@ -140,7 +140,7 @@ describe "#create_thread_and_run" do let(:cassette) { "runs create thread and run" } let(:response) do - OpenAI::Client.new.runs.create_thread_and_run( + ShopifAi::Client.new.runs.create_thread_and_run( parameters: { assistant_id: assistant_id } @@ -157,7 +157,7 @@ describe "#submit_tool_outputs" do let(:cassette) { "runs submit_tool_outputs" } let(:response) do - OpenAI::Client.new.runs.submit_tool_outputs( + ShopifAi::Client.new.runs.submit_tool_outputs( thread_id: thread_id, run_id: run_id, parameters: { diff --git a/spec/openai/client/stream_spec.rb b/spec/shopif_ai/client/stream_spec.rb similarity index 97% rename from spec/openai/client/stream_spec.rb rename to spec/shopif_ai/client/stream_spec.rb index 47544e49..561606d9 100644 --- a/spec/openai/client/stream_spec.rb +++ b/spec/shopif_ai/client/stream_spec.rb @@ -1,6 +1,6 @@ -RSpec.describe OpenAI::Stream do +RSpec.describe ShopifAi::Stream do let(:user_proc) { proc { |data, event| [data, event] } } - let(:stream) { OpenAI::Stream.new(user_proc: user_proc) } + let(:stream) { ShopifAi::Stream.new(user_proc: user_proc) } let(:bytes) { 0 } let(:env) { Faraday::Env.new.tap { |env| env.status = 200 } } diff --git a/spec/openai/client/threads_spec.rb b/spec/shopif_ai/client/threads_spec.rb similarity index 77% rename from spec/openai/client/threads_spec.rb rename to spec/shopif_ai/client/threads_spec.rb index d79c3665..fac75cfd 100644 --- a/spec/openai/client/threads_spec.rb +++ b/spec/shopif_ai/client/threads_spec.rb @@ -1,14 +1,14 @@ -RSpec.describe OpenAI::Client do +RSpec.describe ShopifAi::Client do describe "#threads" do let(:thread_id) do VCR.use_cassette("#{cassette} setup") do - OpenAI::Client.new.threads.create(parameters: {})["id"] + ShopifAi::Client.new.threads.create(parameters: {})["id"] end end describe "#retrieve" do let(:cassette) { "threads retrieve" } - let(:response) { OpenAI::Client.new.threads.retrieve(id: thread_id) } + let(:response) { ShopifAi::Client.new.threads.retrieve(id: thread_id) } it "succeeds" do VCR.use_cassette(cassette) do @@ -20,7 +20,7 @@ describe "#create" do let(:cassette) { "threads create" } let(:response) do - OpenAI::Client.new.threads.create(parameters: {}) + ShopifAi::Client.new.threads.create(parameters: {}) end it "succeeds" do @@ -33,7 +33,7 @@ describe "#modify" do let(:cassette) { "threads modify" } let(:response) do - OpenAI::Client.new.threads.modify( + ShopifAi::Client.new.threads.modify( id: thread_id, parameters: { metadata: { modified: "true" } } ) @@ -49,7 +49,7 @@ describe "#delete" do let(:cassette) { "threads delete" } let(:response) do - OpenAI::Client.new.threads.delete(id: thread_id) + ShopifAi::Client.new.threads.delete(id: thread_id) end it "succeeds" do diff --git a/spec/openai/client/usage_spec.rb b/spec/shopif_ai/client/usage_spec.rb similarity index 92% rename from spec/openai/client/usage_spec.rb rename to spec/shopif_ai/client/usage_spec.rb index fcaa755a..d46bb719 100644 --- a/spec/openai/client/usage_spec.rb +++ b/spec/shopif_ai/client/usage_spec.rb @@ -1,7 +1,7 @@ -RSpec.describe OpenAI::Client do +RSpec.describe ShopifAi::Client do describe "#usage" do let(:some_time_ago) { 1_739_096_063 } - let(:client) { OpenAI::Client.new } + let(:client) { ShopifAi::Client.new } shared_examples "usage endpoint" do |endpoint_name| describe "##{endpoint_name}" do diff --git a/spec/openai/client/vector_store_file_batches_spec.rb b/spec/shopif_ai/client/vector_store_file_batches_spec.rb similarity index 81% rename from spec/openai/client/vector_store_file_batches_spec.rb rename to spec/shopif_ai/client/vector_store_file_batches_spec.rb index ffa61003..264f5f9b 100644 --- a/spec/openai/client/vector_store_file_batches_spec.rb +++ b/spec/shopif_ai/client/vector_store_file_batches_spec.rb @@ -1,8 +1,8 @@ -RSpec.describe OpenAI::Client do +RSpec.describe ShopifAi::Client do describe "#vector_store_file_batches" do let(:vector_store_id) do VCR.use_cassette("#{cassette} vector_store setup") do - OpenAI::Client.new.vector_stores.create(parameters: {})["id"] + ShopifAi::Client.new.vector_stores.create(parameters: {})["id"] end end @@ -11,13 +11,13 @@ let(:upload_purpose) { "assistants" } let(:file_id) do VCR.use_cassette("#{cassette} file setup") do - OpenAI::Client.new.files.upload(parameters: { file: file, purpose: upload_purpose })["id"] + ShopifAi::Client.new.files.upload(parameters: { file: file, purpose: upload_purpose })["id"] end end let(:file_batch_id) do VCR.use_cassette("#{cassette} vector_store_file_batch setup") do - OpenAI::Client.new.vector_store_file_batches.create( + ShopifAi::Client.new.vector_store_file_batches.create( vector_store_id: vector_store_id, parameters: { file_ids: [file_id] } )["id"] @@ -27,7 +27,7 @@ describe "#list" do let(:cassette) { "vector_store_file_batches list" } let(:response) do - OpenAI::Client.new.vector_store_file_batches.list(vector_store_id: vector_store_id, + ShopifAi::Client.new.vector_store_file_batches.list(vector_store_id: vector_store_id, id: file_batch_id) rescue Faraday::ServerError => e # 500 error is caused by the file batch not being processed yet, so we handle it here. @@ -50,7 +50,7 @@ describe "#retrieve" do let(:cassette) { "vector_store_file_batches retrieve" } let(:response) do - OpenAI::Client.new.vector_store_file_batches.retrieve(vector_store_id: vector_store_id, + ShopifAi::Client.new.vector_store_file_batches.retrieve(vector_store_id: vector_store_id, id: file_batch_id) end @@ -64,7 +64,7 @@ describe "#create" do let(:cassette) { "vector_store_file_batches create" } let(:response) do - OpenAI::Client.new.vector_store_file_batches.create( + ShopifAi::Client.new.vector_store_file_batches.create( vector_store_id: vector_store_id, parameters: { file_ids: [file_id] } ) @@ -80,7 +80,7 @@ describe "#cancel" do let(:cassette) { "vector_store_file_batches cancel" } let(:response) do - OpenAI::Client.new.vector_store_file_batches.cancel(vector_store_id: vector_store_id, + ShopifAi::Client.new.vector_store_file_batches.cancel(vector_store_id: vector_store_id, id: file_batch_id) end diff --git a/spec/openai/client/vector_store_files_spec.rb b/spec/shopif_ai/client/vector_store_files_spec.rb similarity index 78% rename from spec/openai/client/vector_store_files_spec.rb rename to spec/shopif_ai/client/vector_store_files_spec.rb index aaf16cea..048689c0 100644 --- a/spec/openai/client/vector_store_files_spec.rb +++ b/spec/shopif_ai/client/vector_store_files_spec.rb @@ -1,8 +1,8 @@ -RSpec.describe OpenAI::Client do +RSpec.describe ShopifAi::Client do describe "#vector_store_files" do let(:vector_store_id) do VCR.use_cassette("#{cassette} vector_store setup") do - OpenAI::Client.new.vector_stores.create(parameters: {})["id"] + ShopifAi::Client.new.vector_stores.create(parameters: {})["id"] end end @@ -11,13 +11,13 @@ let(:upload_purpose) { "assistants" } let(:file_id) do VCR.use_cassette("#{cassette} file setup") do - OpenAI::Client.new.files.upload(parameters: { file: file, purpose: upload_purpose })["id"] + ShopifAi::Client.new.files.upload(parameters: { file: file, purpose: upload_purpose })["id"] end end let(:vector_store_file_id) do VCR.use_cassette("#{cassette} vector_store_file setup") do - OpenAI::Client.new.vector_store_files.create( + ShopifAi::Client.new.vector_store_files.create( vector_store_id: vector_store_id, parameters: { file_id: file_id } )["id"] @@ -27,7 +27,7 @@ describe "#list" do let(:cassette) { "vector_store_files list" } let(:response) do - OpenAI::Client.new.vector_store_files.list(vector_store_id: vector_store_id) + ShopifAi::Client.new.vector_store_files.list(vector_store_id: vector_store_id) end before { vector_store_file_id } @@ -42,7 +42,7 @@ describe "#retrieve" do let(:cassette) { "vector_store_files retrieve" } let(:response) do - OpenAI::Client.new.vector_store_files.retrieve(vector_store_id: vector_store_id, + ShopifAi::Client.new.vector_store_files.retrieve(vector_store_id: vector_store_id, id: vector_store_file_id) end @@ -56,7 +56,7 @@ describe "#create" do let(:cassette) { "vector_store_files create" } let(:response) do - OpenAI::Client.new.vector_store_files.create( + ShopifAi::Client.new.vector_store_files.create( vector_store_id: vector_store_id, parameters: { file_id: file_id } ) @@ -72,7 +72,7 @@ describe "#delete" do let(:cassette) { "vector_store_files delete" } let(:response) do - OpenAI::Client.new.vector_store_files.delete(vector_store_id: vector_store_id, + ShopifAi::Client.new.vector_store_files.delete(vector_store_id: vector_store_id, id: vector_store_file_id) end diff --git a/spec/openai/client/vector_stores_spec.rb b/spec/shopif_ai/client/vector_stores_spec.rb similarity index 80% rename from spec/openai/client/vector_stores_spec.rb rename to spec/shopif_ai/client/vector_stores_spec.rb index 65c25dfd..70d14194 100644 --- a/spec/openai/client/vector_stores_spec.rb +++ b/spec/shopif_ai/client/vector_stores_spec.rb @@ -1,15 +1,15 @@ -RSpec.describe OpenAI::Client do +RSpec.describe ShopifAi::Client do describe "#vector_stores" do let(:vector_store_id) do VCR.use_cassette("#{cassette} setup") do - OpenAI::Client.new.vector_stores.create(parameters: {})["id"] + ShopifAi::Client.new.vector_stores.create(parameters: {})["id"] end end describe "#list" do let(:cassette) { "vector_stores list" } let(:response) do - OpenAI::Client.new.vector_stores.list(parameters: {}) + ShopifAi::Client.new.vector_stores.list(parameters: {}) end it "succeeds" do @@ -22,7 +22,7 @@ describe "#retrieve" do let(:cassette) { "vector_stores retrieve" } - let(:response) { OpenAI::Client.new.vector_stores.retrieve(id: vector_store_id) } + let(:response) { ShopifAi::Client.new.vector_stores.retrieve(id: vector_store_id) } it "succeeds" do VCR.use_cassette(cassette) do @@ -34,7 +34,7 @@ describe "#create" do let(:cassette) { "vector_stores create" } let(:response) do - OpenAI::Client.new.vector_stores.create(parameters: {}) + ShopifAi::Client.new.vector_stores.create(parameters: {}) end it "succeeds" do @@ -47,7 +47,7 @@ describe "#modify" do let(:cassette) { "vector_stores modify" } let(:response) do - OpenAI::Client.new.vector_stores.modify( + ShopifAi::Client.new.vector_stores.modify( id: vector_store_id, parameters: { metadata: { modified: "true" } } ) @@ -63,7 +63,7 @@ describe "#delete" do let(:cassette) { "vector_stores delete" } let(:response) do - OpenAI::Client.new.vector_stores.delete(id: vector_store_id) + ShopifAi::Client.new.vector_stores.delete(id: vector_store_id) end it "succeeds" do @@ -76,7 +76,7 @@ describe "#search" do let(:cassette) { "vector_stores search" } let(:response) do - OpenAI::Client.new.vector_stores.search( + ShopifAi::Client.new.vector_stores.search( id: vector_store_id, parameters: { query: "Test search query", diff --git a/spec/shopif_ai_spec.rb b/spec/shopif_ai_spec.rb new file mode 100644 index 00000000..d9bddf6d --- /dev/null +++ b/spec/shopif_ai_spec.rb @@ -0,0 +1,71 @@ +RSpec.describe ShopifAi do + it "has a version number" do + expect(ShopifAi::VERSION).not_to be nil + end + + describe "#configure" do + let(:access_token) { "abc123" } + let(:api_version) { "v2" } + let(:organization_id) { "def456" } + let(:custom_uri_base) { "ghi789" } + let(:custom_request_timeout) { 25 } + let(:extra_headers) { { "User-Agent" => "OpenAI Ruby Gem #{ShopifAi::VERSION}" } } + + before do + ShopifAi.configure do |config| + config.access_token = access_token + config.api_version = api_version + config.organization_id = organization_id + config.extra_headers = extra_headers + end + end + + it "returns the config" do + expect(ShopifAi.configuration.access_token).to eq(access_token) + expect(ShopifAi.configuration.api_version).to eq(api_version) + expect(ShopifAi.configuration.organization_id).to eq(organization_id) + expect(ShopifAi.configuration.uri_base).to eq("https://api.openai.com/") + expect(ShopifAi.configuration.request_timeout).to eq(120) + expect(ShopifAi.configuration.extra_headers).to eq(extra_headers) + end + + context "with custom timeout and uri base" do + before do + ShopifAi.configure do |config| + config.uri_base = custom_uri_base + config.request_timeout = custom_request_timeout + end + end + + it "returns the config" do + expect(ShopifAi.configuration.access_token).to eq(access_token) + expect(ShopifAi.configuration.api_version).to eq(api_version) + expect(ShopifAi.configuration.organization_id).to eq(organization_id) + expect(ShopifAi.configuration.uri_base).to eq(custom_uri_base) + expect(ShopifAi.configuration.request_timeout).to eq(custom_request_timeout) + expect(ShopifAi.configuration.extra_headers).to eq(extra_headers) + end + end + end + + describe "#rough_token_count" do + context "on a non-String" do + it "raises an error" do + expect { ShopifAi.rough_token_count([]) }.to raise_error(ArgumentError) + end + end + + context "on the empty string" do + it "returns 0" do + expect(ShopifAi.rough_token_count("")).to eq(0) + end + end + + context "on a string" do + let(:content) { "Red is my favorite color. Egg is not a necessary ingredient." } + it "estimates tokens" do + expect(ShopifAi.rough_token_count(content)).to eq(15) + end + end + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index deea1f03..77294b2c 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,6 +1,6 @@ require "bundler/setup" require "dotenv/load" -require "openai" +require "shopif_ai" require "vcr" require "byebug" @@ -18,7 +18,7 @@ %w[ACCESS_TOKEN ADMIN_TOKEN ORGANIZATION_ID USER_ID].each do |key| c.filter_sensitive_data("") do - key == "USER_ID" ? ENV.fetch("OPENAI_#{key}", nil) : OpenAI.configuration.send(key.downcase) + key == "USER_ID" ? ENV.fetch("OPENAI_#{key}", nil) : ShopifAi.configuration.send(key.downcase) end end end @@ -43,7 +43,7 @@ end c.before(:all) do - OpenAI.configure do |config| + ShopifAi.configure do |config| config.access_token = ENV.fetch("OPENAI_ACCESS_TOKEN", "dummy-token") config.admin_token = ENV.fetch("OPENAI_ADMIN_TOKEN", "dummy-token") config.organization_id = ENV.fetch("OPENAI_ORGANIZATION_ID", nil)