Module: OpenAI
- Defined in:
- lib/openai.rb,
lib/openai/http.rb,
lib/openai/runs.rb,
lib/openai/audio.rb,
lib/openai/files.rb,
lib/openai/client.rb,
lib/openai/images.rb,
lib/openai/models.rb,
lib/openai/threads.rb,
lib/openai/version.rb,
lib/openai/messages.rb,
lib/openai/finetunes.rb,
lib/openai/run_steps.rb,
lib/openai/assistants.rb,
lib/openai/http_headers.rb
Defined Under Namespace
Modules: HTTP, HTTPHeaders Classes: Assistants, Audio, Client, Configuration, ConfigurationError, Error, Files, Finetunes, Images, Messages, MiddlewareErrors, Models, RunSteps, Runs, Threads
Constant Summary collapse
- VERSION =
"6.5.3".freeze
Class Attribute Summary collapse
Class Method Summary collapse
- .configure {|configuration| ... } ⇒ Object
-
.rough_token_count(content = "") ⇒ Object
Estimate the number of tokens in a string, using the rules of thumb from OpenAI: help.openai.com/en/articles/4936856-what-are-tokens-and-how-to-count-them.
Class Attribute Details
.configuration ⇒ Object
69 70 71 |
# File 'lib/openai.rb', line 69 def self.configuration @configuration ||= OpenAI::Configuration.new end |
Class Method Details
.configure {|configuration| ... } ⇒ Object
73 74 75 |
# File 'lib/openai.rb', line 73 def self.configure yield(configuration) end |
.rough_token_count(content = "") ⇒ Object
Estimate the number of tokens in a string, using the rules of thumb from OpenAI: help.openai.com/en/articles/4936856-what-are-tokens-and-how-to-count-them
79 80 81 82 83 84 85 86 87 |
# File 'lib/openai.rb', line 79 def self.rough_token_count(content = "") raise ArgumentError, "rough_token_count requires a string" unless content.is_a? String return 0 if content.empty? count_by_chars = content.size / 4.0 count_by_words = content.split.size * 4.0 / 3 estimate = ((count_by_chars + count_by_words) / 2.0).round [1, estimate].max end |