Class: Hellm::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/hellm/builder.rb

Constant Summary collapse

SUPPORTED_SKILL_ATTRIBUTEES =
["name", "description", "argument_hint"]
SUPPORTED_AGENT_ATTRIBUTEES =
["model", "name", "description", "tools", "agents"]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project_dir: nil, stream_adapter: nil, openai_api_key: nil) ⇒ Builder

Returns a new instance of Builder.

Raises:

  • (ArgumentError)


13
14
15
16
17
18
19
20
21
22
23
# File 'lib/hellm/builder.rb', line 13

def initialize(project_dir: nil, stream_adapter: nil, openai_api_key: nil)
  @project_dir = project_dir
  @hellm_dir = File.join(project_dir, ".hellm")
  @hellm_dir = File.join(project_dir, ".github") if !Dir.exist?(@hellm_dir)
  raise ArgumentError, "not found: #{project_dir}/.hellm" unless Dir.exist?(@hellm_dir)

  @stream_adapter = stream_adapter
  @openai_api_key = openai_api_key

  add_builtin_tools_to_registry
end

Instance Attribute Details

#hellm_dirObject

Returns the value of attribute hellm_dir.



8
9
10
# File 'lib/hellm/builder.rb', line 8

def hellm_dir
  @hellm_dir
end

#project_dirObject

Returns the value of attribute project_dir.



8
9
10
# File 'lib/hellm/builder.rb', line 8

def project_dir
  @project_dir
end

#stream_adapterObject

Returns the value of attribute stream_adapter.



8
9
10
# File 'lib/hellm/builder.rb', line 8

def stream_adapter
  @stream_adapter
end

Instance Method Details

#build(talking_to: nil) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/hellm/builder.rb', line 25

def build(talking_to: nil)
  agents = get_agents_from_project_dir
  skills = get_skills_from_project_dir
  skill_tool = Hellm::Tools::SkillTool.new
  skill_tool.add(*skills)
  Hellm::Tools::Registry.instance.add(:skill, skill_tool)
  Hellm::Tools::Registry.instance.add_agents(*agents)

  if agents.empty?
    agent = Hellm::Agent.new
  else
    agent = agents.find{ |agent| agent.name == talking_to }
    raise ArgumentError, "Agent not found: #{talking_to}" if agent.nil?
  end
  agent
end