Class: AISpec::Core::Contract
- Inherits:
-
Object
- Object
- AISpec::Core::Contract
- Defined in:
- lib/aispec/core/contract.rb
Instance Attribute Summary collapse
-
#assertions ⇒ Object
readonly
Returns the value of attribute assertions.
-
#dataset_items ⇒ Object
readonly
Returns the value of attribute dataset_items.
-
#dataset_path ⇒ Object
readonly
Returns the value of attribute dataset_path.
-
#file_path ⇒ Object
readonly
Returns the value of attribute file_path.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#prompt_template ⇒ Object
readonly
Returns the value of attribute prompt_template.
-
#provider_name ⇒ Object
readonly
Returns the value of attribute provider_name.
-
#raw_hash ⇒ Object
readonly
Returns the value of attribute raw_hash.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(hash, file_path: nil) ⇒ Contract
constructor
A new instance of Contract.
Constructor Details
#initialize(hash, file_path: nil) ⇒ Contract
Returns a new instance of Contract.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/aispec/core/contract.rb', line 21 def initialize(hash, file_path: nil) @raw_hash = hash @file_path = file_path @name = hash[:name] || (file_path ? File.basename(file_path, ".*") : "unnamed-contract") model_config = hash[:model] || {} if model_config.is_a?(Hash) @provider_name = (model_config[:provider] || AISpec.configuration.default_provider).to_s @model = (model_config[:model] || AISpec.configuration.default_model).to_s else @provider_name = AISpec.configuration.default_provider.to_s @model = model_config.to_s end @prompt_template = hash[:prompt] || "{{input}}" dataset_config = hash[:dataset] if dataset_config.is_a?(Hash) @dataset_path = dataset_config[:path] @dataset_items = dataset_config[:items] || [] elsif dataset_config.is_a?(Array) @dataset_items = dataset_config else @dataset_items = [] end load_external_dataset! if @dataset_path && @file_path raw_contracts = hash[:contracts] || hash[:assertions] || [] @assertions = parse_assertions(raw_contracts) end |
Instance Attribute Details
#assertions ⇒ Object (readonly)
Returns the value of attribute assertions.
8 9 10 |
# File 'lib/aispec/core/contract.rb', line 8 def assertions @assertions end |
#dataset_items ⇒ Object (readonly)
Returns the value of attribute dataset_items.
8 9 10 |
# File 'lib/aispec/core/contract.rb', line 8 def dataset_items @dataset_items end |
#dataset_path ⇒ Object (readonly)
Returns the value of attribute dataset_path.
8 9 10 |
# File 'lib/aispec/core/contract.rb', line 8 def dataset_path @dataset_path end |
#file_path ⇒ Object (readonly)
Returns the value of attribute file_path.
8 9 10 |
# File 'lib/aispec/core/contract.rb', line 8 def file_path @file_path end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
8 9 10 |
# File 'lib/aispec/core/contract.rb', line 8 def model @model end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
8 9 10 |
# File 'lib/aispec/core/contract.rb', line 8 def name @name end |
#prompt_template ⇒ Object (readonly)
Returns the value of attribute prompt_template.
8 9 10 |
# File 'lib/aispec/core/contract.rb', line 8 def prompt_template @prompt_template end |
#provider_name ⇒ Object (readonly)
Returns the value of attribute provider_name.
8 9 10 |
# File 'lib/aispec/core/contract.rb', line 8 def provider_name @provider_name end |
#raw_hash ⇒ Object (readonly)
Returns the value of attribute raw_hash.
8 9 10 |
# File 'lib/aispec/core/contract.rb', line 8 def raw_hash @raw_hash end |
Class Method Details
.from_hash(hash) ⇒ Object
17 18 19 |
# File 'lib/aispec/core/contract.rb', line 17 def self.from_hash(hash) new(hash) end |
.load_file(path) ⇒ Object
10 11 12 13 14 15 |
# File 'lib/aispec/core/contract.rb', line 10 def self.load_file(path) raise ArgumentError, "Contract file not found: #{path}" unless File.exist?(path) hash = YAML.safe_load(File.read(path), symbolize_names: true, aliases: true) || {} new(hash, file_path: path) end |