Class: FlowEngine::LLM::Client
- Inherits:
-
Object
- Object
- FlowEngine::LLM::Client
- Defined in:
- lib/flowengine/llm/client.rb
Overview
High-level LLM client that parses introduction text into pre-filled answers. Wraps an Adapter and a model name, builds the system prompt from the flow Definition, and parses the structured JSON response.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#adapter ⇒ Object
readonly
Returns the value of attribute adapter.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
Instance Method Summary collapse
-
#initialize(adapter:, model: nil) ⇒ Client
constructor
A new instance of Client.
-
#parse_ai_intake(definition:, user_text:, answered: {}, conversation_history: []) ⇒ Hash
Sends user text to the LLM for an AI intake step and returns both extracted answers and an optional follow-up question.
-
#parse_introduction(definition:, introduction_text:) ⇒ Hash<Symbol, Object>
Sends the introduction text to the LLM with a system prompt built from the Definition, and returns a hash of extracted step answers.
- #to_s ⇒ Object
Constructor Details
#initialize(adapter:, model: nil) ⇒ Client
Returns a new instance of Client.
15 16 17 18 |
# File 'lib/flowengine/llm/client.rb', line 15 def initialize(adapter:, model: nil) @adapter = adapter @model = model || adapter.model end |
Instance Attribute Details
#adapter ⇒ Object (readonly)
Returns the value of attribute adapter.
11 12 13 |
# File 'lib/flowengine/llm/client.rb', line 11 def adapter @adapter end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
11 12 13 |
# File 'lib/flowengine/llm/client.rb', line 11 def model @model end |
Instance Method Details
#parse_ai_intake(definition:, user_text:, answered: {}, conversation_history: []) ⇒ Hash
Sends user text to the LLM for an AI intake step and returns both extracted answers and an optional follow-up question.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/flowengine/llm/client.rb', line 46 def parse_ai_intake(definition:, user_text:, answered: {}, conversation_history: []) system_prompt = IntakePromptBuilder.new( definition, answered: answered, conversation_history: conversation_history ).build response_text = adapter.chat( system_prompt: system_prompt, user_prompt: user_text, model: model ) parse_intake_response(response_text, definition) end |
#parse_introduction(definition:, introduction_text:) ⇒ Hash<Symbol, Object>
Sends the introduction text to the LLM with a system prompt built from the Definition, and returns a hash of extracted step answers.
27 28 29 30 31 32 33 34 35 |
# File 'lib/flowengine/llm/client.rb', line 27 def parse_introduction(definition:, introduction_text:) system_prompt = SystemPromptBuilder.new(definition).build response_text = adapter.chat( system_prompt: system_prompt, user_prompt: introduction_text, model: model ) parse_response(response_text, definition) end |
#to_s ⇒ Object
62 63 64 |
# File 'lib/flowengine/llm/client.rb', line 62 def to_s "#<#{self.class.name} adapter=#{adapter} model=#{model}>" end |