Class: ActiveAI::Behavior::LLM::FollowStructuredExamples
- Inherits:
-
ActiveAI::Behavior::LLM
- Object
- Base
- ActiveAI::Behavior::LLM
- ActiveAI::Behavior::LLM::FollowStructuredExamples
- Defined in:
- lib/activeai/behavior/llm/follow_structured_examples.rb
Constant Summary
Constants inherited from ActiveAI::Behavior::LLM
Instance Method Summary collapse
- #base_prompt ⇒ Object
-
#call(input = {}, extract: []) ⇒ Object
TODO cool splat stuff?.
-
#initialize(llm, state) ⇒ FollowStructuredExamples
constructor
state is an instruction, and a list of examples with key/value pairs would be nice to do casting, but not now i dont think..
Methods inherited from ActiveAI::Behavior::LLM
Constructor Details
#initialize(llm, state) ⇒ FollowStructuredExamples
state is an instruction, and a list of examples with key/value pairs would be nice to do casting, but not now i dont think..
5 6 7 8 9 |
# File 'lib/activeai/behavior/llm/follow_structured_examples.rb', line 5 def initialize(llm, state) super(llm) @state = state # TODO raise errors if not expected thingies available in the config end |
Instance Method Details
#base_prompt ⇒ Object
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/activeai/behavior/llm/follow_structured_examples.rb', line 11 def base_prompt [ @state['instruction'], @state['examples'].map do |example| example.map do |key, value| "#{key}: #{value}" end.join("\n") end.join(LINE_SEPARATOR) ].join(LINE_SEPARATOR) end |
#call(input = {}, extract: []) ⇒ Object
TODO cool splat stuff?
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/activeai/behavior/llm/follow_structured_examples.rb', line 22 def call(input={}, extract: []) # TODO cool splat stuff? prompt = base_prompt + LINE_SEPARATOR prompt += input.map do |key, value| "#{key}: #{value}" end.join("\n") complete_result = complete(prompt) completion = complete_result['choices'][0]['text'] return extract_keys(completion, extract) end |