Class: RSmolagent::LLMProvider

Inherits:
Object
  • Object
show all
Defined in:
lib/rsmolagent/llm_provider.rb

Direct Known Subclasses

ClaudeProvider, OpenAIProvider

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model_id:, **options) ⇒ LLMProvider

Returns a new instance of LLMProvider.



5
6
7
8
9
10
# File 'lib/rsmolagent/llm_provider.rb', line 5

def initialize(model_id:, **options)
  @model_id = model_id
  @options = options
  @last_prompt_tokens = 0
  @last_completion_tokens = 0
end

Instance Attribute Details

#last_completion_tokensObject (readonly)

Returns the value of attribute last_completion_tokens.



3
4
5
# File 'lib/rsmolagent/llm_provider.rb', line 3

def last_completion_tokens
  @last_completion_tokens
end

#last_prompt_tokensObject (readonly)

Returns the value of attribute last_prompt_tokens.



3
4
5
# File 'lib/rsmolagent/llm_provider.rb', line 3

def last_prompt_tokens
  @last_prompt_tokens
end

Instance Method Details

#chat(messages, tools: nil, tool_choice: nil) ⇒ Object

Raises:

  • (NotImplementedError)


12
13
14
# File 'lib/rsmolagent/llm_provider.rb', line 12

def chat(messages, tools: nil, tool_choice: nil)
  raise NotImplementedError, "Subclasses must implement the 'chat' method"
end

#extract_tool_calls(response) ⇒ Object

Raises:

  • (NotImplementedError)


16
17
18
# File 'lib/rsmolagent/llm_provider.rb', line 16

def extract_tool_calls(response)
  raise NotImplementedError, "Subclasses must implement the 'extract_tool_calls' method"
end

#parse_json_if_needed(text) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/rsmolagent/llm_provider.rb', line 20

def parse_json_if_needed(text)
  return text unless text.is_a?(String)
  
  begin
    JSON.parse(text)
  rescue JSON::ParserError
    text
  end
end