Class: RSmolagent::LLMProvider
- Inherits:
-
Object
- Object
- RSmolagent::LLMProvider
- Defined in:
- lib/rsmolagent/llm_provider.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#last_completion_tokens ⇒ Object
readonly
Returns the value of attribute last_completion_tokens.
-
#last_prompt_tokens ⇒ Object
readonly
Returns the value of attribute last_prompt_tokens.
Instance Method Summary collapse
- #chat(messages, tools: nil, tool_choice: nil) ⇒ Object
- #extract_tool_calls(response) ⇒ Object
-
#initialize(model_id:, **options) ⇒ LLMProvider
constructor
A new instance of LLMProvider.
- #parse_json_if_needed(text) ⇒ Object
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:, **) @model_id = model_id @options = @last_prompt_tokens = 0 @last_completion_tokens = 0 end |
Instance Attribute Details
#last_completion_tokens ⇒ Object (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_tokens ⇒ Object (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
12 13 14 |
# File 'lib/rsmolagent/llm_provider.rb', line 12 def chat(, tools: nil, tool_choice: nil) raise NotImplementedError, "Subclasses must implement the 'chat' method" end |
#extract_tool_calls(response) ⇒ Object
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 |