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/batches.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,
lib/openai/vector_stores.rb,
lib/openai/vector_store_files.rb,
lib/openai/vector_store_file_batches.rb
Defined Under Namespace
Modules: HTTP, HTTPHeaders Classes: Assistants, Audio, Batches, Client, Configuration, ConfigurationError, Error, Files, Finetunes, Images, Messages, MiddlewareErrors, Models, RunSteps, Runs, Threads, VectorStoreFileBatches, VectorStoreFiles, VectorStores
Constant Summary collapse
- VERSION =
"7.3.1".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
73 74 75 |
# File 'lib/openai.rb', line 73 def self.configuration @configuration ||= OpenAI::Configuration.new end |
Class Method Details
.configure {|configuration| ... } ⇒ Object
77 78 79 |
# File 'lib/openai.rb', line 77 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
83 84 85 86 87 88 89 90 91 |
# File 'lib/openai.rb', line 83 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 |