Class: ActiveAI::Behavior::LLM

Inherits:
Base
  • Object
show all
Defined in:
lib/activeai/behavior/llm.rb

Defined Under Namespace

Classes: Conversation, FollowStructuredExamples, Unstructured, WriteFunctionCall

Constant Summary collapse

LINE_SEPARATOR =
"\n\n###\n\n"

Instance Method Summary collapse

Constructor Details

#initialize(llm) ⇒ LLM

Returns a new instance of LLM.



2
3
4
# File 'lib/activeai/behavior/llm.rb', line 2

def initialize(llm)
  @llm = llm
end

Instance Method Details

#complete(prompt, stop: nil) ⇒ Object



6
7
8
# File 'lib/activeai/behavior/llm.rb', line 6

def complete(prompt, stop: nil)
  @llm.complete(prompt: prompt, stop: stop)
end

#extract_keys(completion, extract) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/activeai/behavior/llm.rb', line 12

def extract_keys(completion, extract)
  matcher_string = extract.map{ |key| "#{key}:(.*)" }.join
  matches = completion.match(/#{matcher_string}/m)

  if matches
    matches[1..-1].map.with_index do |value, index|
      # TODO this seems hacky, gotta be a better way to extract?
      [extract[index], value.strip]
    end.to_h
  else
    nil
  end
end