Class: SqlChatbot::Services::GrammarPipeline
- Inherits:
-
Object
- Object
- SqlChatbot::Services::GrammarPipeline
- Defined in:
- lib/sql_chatbot/services/grammar_pipeline.rb
Instance Method Summary collapse
-
#initialize(registry:, call_llm:, confidence_threshold: 0.7, miss_log_path: nil) ⇒ GrammarPipeline
constructor
A new instance of GrammarPipeline.
- #try(question:, history: []) ⇒ Object
Constructor Details
#initialize(registry:, call_llm:, confidence_threshold: 0.7, miss_log_path: nil) ⇒ GrammarPipeline
Returns a new instance of GrammarPipeline.
10 11 12 13 14 15 |
# File 'lib/sql_chatbot/services/grammar_pipeline.rb', line 10 def initialize(registry:, call_llm:, confidence_threshold: 0.7, miss_log_path: nil) @registry = registry @call_llm = call_llm @confidence_threshold = confidence_threshold @miss_log_path = miss_log_path end |
Instance Method Details
#try(question:, history: []) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/sql_chatbot/services/grammar_pipeline.rb', line 17 def try(question:, history: []) intent = Grammar::IntentExtractor.extract( question: question, registry: @registry, history: history, call_llm: @call_llm, confidence_threshold: @confidence_threshold ) result = Grammar::TemplateCompiler.compile(intent, @registry) if result[:ok] result.merge(intent: intent) else log_miss(question, result[:reason], intent) result.merge(intent: intent) end rescue => e log_miss(question, "grammar_exception: #{e.}", nil) { ok: false, reason: "grammar_exception: #{e.}" } end |