Module: GigaChat

Defined in:
lib/gigachat.rb,
lib/gigachat/http.rb,
lib/gigachat/client.rb,
lib/gigachat/models.rb,
lib/gigachat/version.rb,
lib/gigachat/http_headers.rb

Defined Under Namespace

Modules: HTTP, HTTPHeaders Classes: Client, Configuration, ConfigurationError, Error, MiddlewareErrors, Models

Constant Summary collapse

VERSION =
'0.1.0'

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configurationObject



58
59
60
# File 'lib/gigachat.rb', line 58

def self.configuration
  @configuration ||= GigaChat::Configuration.new
end

Class Method Details

.configure {|configuration| ... } ⇒ Object

Yields:



62
63
64
# File 'lib/gigachat.rb', line 62

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

Raises:

  • (ArgumentError)


68
69
70
71
72
73
74
75
76
# File 'lib/gigachat.rb', line 68

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