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)
563 564 565 566 567 568 569 570 |
# File 'lib/candle/llm.rb', line 563 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)
552 553 554 555 556 557 558 559 560 |
# File 'lib/candle/llm.rb', line 552 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)
541 542 543 544 545 546 547 548 549 |
# File 'lib/candle/llm.rb', line 541 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
573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 |
# File 'lib/candle/llm.rb', line 573 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
524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 |
# File 'lib/candle/llm.rb', line 524 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 |