Class: SemanticCache::Configuration
- Inherits:
-
Object
- Object
- SemanticCache::Configuration
- Defined in:
- lib/semantic_cache/configuration.rb
Constant Summary collapse
- DEFAULT_MODEL_COSTS =
Cost per 1K tokens (USD)
{ # OpenAI "gpt-4" => { input: 0.03, output: 0.06 }, "gpt-4-turbo" => { input: 0.01, output: 0.03 }, "gpt-4o" => { input: 0.005, output: 0.015 }, "gpt-4o-mini" => { input: 0.00015, output: 0.0006 }, "gpt-3.5-turbo" => { input: 0.0005, output: 0.0015 }, # Anthropic "claude-sonnet-4-20250514" => { input: 0.003, output: 0.015 }, "claude-3-5-haiku-20241022" => { input: 0.001, output: 0.005 }, # Gemini "gemini-pro" => { input: 0.0005, output: 0.0015 }, "gemini-1.5-pro" => { input: 0.00125, output: 0.005 }, # Embedding (cost per 1K tokens) "text-embedding-3-small" => { input: 0.00002, output: 0.0 }, "text-embedding-3-large" => { input: 0.00013, output: 0.0 } }.freeze
Instance Attribute Summary collapse
-
#default_ttl ⇒ Object
Returns the value of attribute default_ttl.
-
#embedding_model ⇒ Object
Returns the value of attribute embedding_model.
-
#embedding_timeout ⇒ Object
Returns the value of attribute embedding_timeout.
-
#max_cache_size ⇒ Object
Returns the value of attribute max_cache_size.
-
#model_costs ⇒ Object
Returns the value of attribute model_costs.
-
#namespace ⇒ Object
Returns the value of attribute namespace.
-
#openai_api_key ⇒ Object
Returns the value of attribute openai_api_key.
-
#similarity_threshold ⇒ Object
Returns the value of attribute similarity_threshold.
-
#store ⇒ Object
Returns the value of attribute store.
-
#store_options ⇒ Object
Returns the value of attribute store_options.
-
#track_costs ⇒ Object
Returns the value of attribute track_costs.
Instance Method Summary collapse
- #cost_for(model) ⇒ Object
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/semantic_cache/configuration.rb', line 36 def initialize @similarity_threshold = 0.85 = "text-embedding-3-small" @openai_api_key = ENV["OPENAI_API_KEY"] @default_ttl = nil # No expiry by default @store = :memory = {} @track_costs = true @model_costs = DEFAULT_MODEL_COSTS.dup @namespace = "semantic_cache" = 30 # seconds @max_cache_size = nil # nil = unlimited end |
Instance Attribute Details
#default_ttl ⇒ Object
Returns the value of attribute default_ttl.
5 6 7 |
# File 'lib/semantic_cache/configuration.rb', line 5 def default_ttl @default_ttl end |
#embedding_model ⇒ Object
Returns the value of attribute embedding_model.
5 6 7 |
# File 'lib/semantic_cache/configuration.rb', line 5 def end |
#embedding_timeout ⇒ Object
Returns the value of attribute embedding_timeout.
5 6 7 |
# File 'lib/semantic_cache/configuration.rb', line 5 def end |
#max_cache_size ⇒ Object
Returns the value of attribute max_cache_size.
5 6 7 |
# File 'lib/semantic_cache/configuration.rb', line 5 def max_cache_size @max_cache_size end |
#model_costs ⇒ Object
Returns the value of attribute model_costs.
5 6 7 |
# File 'lib/semantic_cache/configuration.rb', line 5 def model_costs @model_costs end |
#namespace ⇒ Object
Returns the value of attribute namespace.
5 6 7 |
# File 'lib/semantic_cache/configuration.rb', line 5 def namespace @namespace end |
#openai_api_key ⇒ Object
Returns the value of attribute openai_api_key.
5 6 7 |
# File 'lib/semantic_cache/configuration.rb', line 5 def openai_api_key @openai_api_key end |
#similarity_threshold ⇒ Object
Returns the value of attribute similarity_threshold.
5 6 7 |
# File 'lib/semantic_cache/configuration.rb', line 5 def similarity_threshold @similarity_threshold end |
#store ⇒ Object
Returns the value of attribute store.
5 6 7 |
# File 'lib/semantic_cache/configuration.rb', line 5 def store @store end |
#store_options ⇒ Object
Returns the value of attribute store_options.
5 6 7 |
# File 'lib/semantic_cache/configuration.rb', line 5 def end |
#track_costs ⇒ Object
Returns the value of attribute track_costs.
5 6 7 |
# File 'lib/semantic_cache/configuration.rb', line 5 def track_costs @track_costs end |
Instance Method Details
#cost_for(model) ⇒ Object
50 51 52 |
# File 'lib/semantic_cache/configuration.rb', line 50 def cost_for(model) model_costs[model] || { input: 0.001, output: 0.002 } end |