Class: Broadlistening::Config
- Inherits:
-
Object
- Object
- Broadlistening::Config
- Defined in:
- lib/broadlistening/config.rb
Constant Summary collapse
- DEFAULT_CLUSTER_NUMS =
[ 5, 15 ].freeze
- DEFAULT_WORKERS =
10- DEFAULT_AZURE_API_VERSION =
"2024-02-15-preview"
Instance Attribute Summary collapse
-
#api_base_url ⇒ Object
readonly
Returns the value of attribute api_base_url.
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#azure_api_version ⇒ Object
readonly
Returns the value of attribute azure_api_version.
-
#cluster_nums ⇒ Object
readonly
Returns the value of attribute cluster_nums.
-
#embedding_model ⇒ Object
readonly
Returns the value of attribute embedding_model.
-
#enable_source_link ⇒ Object
readonly
Returns the value of attribute enable_source_link.
-
#hidden_properties ⇒ Object
readonly
Returns the value of attribute hidden_properties.
-
#input ⇒ Object
readonly
Returns the value of attribute input.
-
#intro ⇒ Object
readonly
Returns the value of attribute intro.
-
#is_pubcom ⇒ Object
readonly
Returns the value of attribute is_pubcom.
-
#local_llm_address ⇒ Object
readonly
Returns the value of attribute local_llm_address.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#prompts ⇒ Object
readonly
Returns the value of attribute prompts.
-
#provider ⇒ Object
readonly
Returns the value of attribute provider.
-
#question ⇒ Object
readonly
Returns the value of attribute question.
-
#workers ⇒ Object
readonly
Returns the value of attribute workers.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Config
constructor
A new instance of Config.
- #property_names ⇒ Object
- #save_to_file(path) ⇒ Object
- #to_h ⇒ Object
- #to_json(*args) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Config
Returns a new instance of Config.
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/broadlistening/config.rb', line 53 def initialize( = {}) @local_llm_address = [:local_llm_address] || ENV.fetch("LOCAL_LLM_ADDRESS", "localhost:11434") @provider_obj = Provider.new( [:provider]&.to_sym || :openai, local_llm_address: @local_llm_address ) @provider = @provider_obj.name @model = [:model] || @provider_obj.default_model @embedding_model = [:embedding_model] || @provider_obj. @cluster_nums = [:cluster_nums] || DEFAULT_CLUSTER_NUMS.dup @workers = [:workers] || DEFAULT_WORKERS @prompts = default_prompts.merge([:prompts] || {}) @api_key = [:api_key] || @provider_obj.api_key @enable_source_link = .fetch(:enable_source_link, false) @hidden_properties = .fetch(:hidden_properties, {}) || {} @is_pubcom = .fetch(:is_pubcom, false) @api_base_url = [:api_base_url] || @provider_obj.base_url @azure_api_version = [:azure_api_version] || ENV.fetch("AZURE_API_VERSION", DEFAULT_AZURE_API_VERSION) @input = [:input] @question = [:question] @name = [:name] @intro = [:intro] validate! end |
Instance Attribute Details
#api_base_url ⇒ Object (readonly)
Returns the value of attribute api_base_url.
7 8 9 |
# File 'lib/broadlistening/config.rb', line 7 def api_base_url @api_base_url end |
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
7 8 9 |
# File 'lib/broadlistening/config.rb', line 7 def api_key @api_key end |
#azure_api_version ⇒ Object (readonly)
Returns the value of attribute azure_api_version.
7 8 9 |
# File 'lib/broadlistening/config.rb', line 7 def azure_api_version @azure_api_version end |
#cluster_nums ⇒ Object (readonly)
Returns the value of attribute cluster_nums.
7 8 9 |
# File 'lib/broadlistening/config.rb', line 7 def cluster_nums @cluster_nums end |
#embedding_model ⇒ Object (readonly)
Returns the value of attribute embedding_model.
7 8 9 |
# File 'lib/broadlistening/config.rb', line 7 def @embedding_model end |
#enable_source_link ⇒ Object (readonly)
Returns the value of attribute enable_source_link.
7 8 9 |
# File 'lib/broadlistening/config.rb', line 7 def enable_source_link @enable_source_link end |
#hidden_properties ⇒ Object (readonly)
Returns the value of attribute hidden_properties.
7 8 9 |
# File 'lib/broadlistening/config.rb', line 7 def hidden_properties @hidden_properties end |
#input ⇒ Object (readonly)
Returns the value of attribute input.
7 8 9 |
# File 'lib/broadlistening/config.rb', line 7 def input @input end |
#intro ⇒ Object (readonly)
Returns the value of attribute intro.
7 8 9 |
# File 'lib/broadlistening/config.rb', line 7 def intro @intro end |
#is_pubcom ⇒ Object (readonly)
Returns the value of attribute is_pubcom.
7 8 9 |
# File 'lib/broadlistening/config.rb', line 7 def is_pubcom @is_pubcom end |
#local_llm_address ⇒ Object (readonly)
Returns the value of attribute local_llm_address.
7 8 9 |
# File 'lib/broadlistening/config.rb', line 7 def local_llm_address @local_llm_address end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
7 8 9 |
# File 'lib/broadlistening/config.rb', line 7 def model @model end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/broadlistening/config.rb', line 7 def name @name end |
#prompts ⇒ Object (readonly)
Returns the value of attribute prompts.
7 8 9 |
# File 'lib/broadlistening/config.rb', line 7 def prompts @prompts end |
#provider ⇒ Object (readonly)
Returns the value of attribute provider.
7 8 9 |
# File 'lib/broadlistening/config.rb', line 7 def provider @provider end |
#question ⇒ Object (readonly)
Returns the value of attribute question.
7 8 9 |
# File 'lib/broadlistening/config.rb', line 7 def question @question end |
#workers ⇒ Object (readonly)
Returns the value of attribute workers.
7 8 9 |
# File 'lib/broadlistening/config.rb', line 7 def workers @workers end |
Class Method Details
.from_file(path) ⇒ Object
49 50 51 |
# File 'lib/broadlistening/config.rb', line 49 def self.from_file(path) from_json(File.read(path)) end |
.from_hash(hash) ⇒ Object
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 |
# File 'lib/broadlistening/config.rb', line 21 def self.from_hash(hash) prompts = hash[:prompts]&.transform_keys(&:to_sym) cluster_nums = hash[:cluster_nums] || hash.dig(:hierarchical_clustering, :cluster_nums) workers = hash[:workers] || hash.dig(:extraction, :workers) hidden_properties = hash[:hidden_properties] || hash.dig(:aggregation, :hidden_properties) new( api_key: hash[:api_key], model: hash[:model], embedding_model: hash[:embedding_model], provider: hash[:provider], cluster_nums: cluster_nums, workers: workers, prompts: prompts, enable_source_link: hash[:enable_source_link], hidden_properties: hidden_properties, is_pubcom: hash[:is_pubcom], api_base_url: hash[:api_base_url], local_llm_address: hash[:local_llm_address], azure_api_version: hash[:azure_api_version], input: hash[:input], question: hash[:question], name: hash[:name], intro: hash[:intro] ) end |
.from_json(json_string) ⇒ Object
16 17 18 19 |
# File 'lib/broadlistening/config.rb', line 16 def self.from_json(json_string) data = JSON.parse(json_string, symbolize_names: true) from_hash(data) end |
Instance Method Details
#property_names ⇒ Object
107 108 109 |
# File 'lib/broadlistening/config.rb', line 107 def property_names hidden_properties.keys end |
#save_to_file(path) ⇒ Object
103 104 105 |
# File 'lib/broadlistening/config.rb', line 103 def save_to_file(path) File.write(path, JSON.pretty_generate(to_h.merge(prompts: prompts))) end |
#to_h ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/broadlistening/config.rb', line 79 def to_h { model: model, embedding_model: , provider: provider, cluster_nums: cluster_nums, workers: workers, enable_source_link: enable_source_link, hidden_properties: hidden_properties, is_pubcom: is_pubcom, api_base_url: api_base_url, local_llm_address: local_llm_address, azure_api_version: azure_api_version, input: input, question: question, name: name, intro: intro }.compact end |
#to_json(*args) ⇒ Object
99 100 101 |
# File 'lib/broadlistening/config.rb', line 99 def to_json(*args) to_h.merge(prompts: prompts).to_json(*args) end |