Class: Candle::GenerationConfig
- Inherits:
-
Object
- Object
- Candle::GenerationConfig
- Defined in:
- lib/candle/llm.rb
Class Method Summary collapse
-
.balanced(**opts) ⇒ Object
Create a balanced configuration (moderate temperature, random seed).
-
.creative(**opts) ⇒ Object
Create a creative configuration (higher temperature, random seed).
-
.deterministic(**opts) ⇒ Object
Create a deterministic configuration (temperature = 0, fixed seed).
Instance Method Summary collapse
-
#inspect ⇒ Object
Inspect method for debugging and exploration.
-
#with(**overrides) ⇒ Object
Convenience method to create config with overrides.
Class Method Details
.balanced(**opts) ⇒ Object
Create a balanced configuration (moderate temperature, random seed)
427 428 429 430 431 432 433 434 |
# File 'lib/candle/llm.rb', line 427 def self.balanced(**opts) defaults = { temperature: 0.7, top_p: 0.9, top_k: 40 } new(defaults.merge(opts)) end |
.creative(**opts) ⇒ Object
Create a creative configuration (higher temperature, random seed)
416 417 418 419 420 421 422 423 424 |
# File 'lib/candle/llm.rb', line 416 def self.creative(**opts) defaults = { temperature: 1.0, top_p: 0.95, top_k: 50, repetition_penalty: 1.2 } new(defaults.merge(opts)) end |
.deterministic(**opts) ⇒ Object
Create a deterministic configuration (temperature = 0, fixed seed)
405 406 407 408 409 410 411 412 413 |
# File 'lib/candle/llm.rb', line 405 def self.deterministic(**opts) defaults = { temperature: 0.0, top_p: nil, top_k: 1, seed: 42 } new(defaults.merge(opts)) end |
Instance Method Details
#inspect ⇒ Object
Inspect method for debugging and exploration
437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 |
# File 'lib/candle/llm.rb', line 437 def inspect opts = rescue {} parts = ["#<Candle::GenerationConfig"] # Add key configuration parameters parts << "temp=#{opts["temperature"]}" if opts["temperature"] parts << "max=#{opts["max_length"]}" if opts["max_length"] parts << "top_p=#{opts["top_p"]}" if opts["top_p"] parts << "top_k=#{opts["top_k"]}" if opts["top_k"] parts << "seed=#{opts["seed"]}" if opts["seed"] # Add flags flags = [] flags << "debug" if opts["debug_tokens"] flags << "constraint" if opts["has_constraint"] flags << "stop_on_match" if opts["stop_on_match"] parts << "flags=[#{flags.join(",")}]" if flags.any? parts.join(" ") + ">" end |
#with(**overrides) ⇒ Object
Convenience method to create config with overrides
388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 |
# File 'lib/candle/llm.rb', line 388 def with(**overrides) current_config = { max_length: max_length, temperature: temperature, top_p: top_p, top_k: top_k, repetition_penalty: repetition_penalty, seed: seed, stop_sequences: stop_sequences, include_prompt: include_prompt, constraint: defined?(@constraint) ? @constraint : nil }.compact self.class.new(current_config.merge(overrides)) end |