Class: Rasti::AI::Assistant
- Inherits:
-
Object
- Object
- Rasti::AI::Assistant
- Defined in:
- lib/rasti/ai/assistant.rb
Direct Known Subclasses
Rasti::AI::Anthropic::Assistant, Gemini::Assistant, OpenAI::Assistant
Constant Summary collapse
- VALID_THINKING_LEVELS =
%w[low medium high].freeze
Instance Attribute Summary collapse
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#state ⇒ Object
readonly
Returns the value of attribute state.
-
#thinking ⇒ Object
readonly
Returns the value of attribute thinking.
Instance Method Summary collapse
- #call(prompt) ⇒ Object
-
#initialize(client: nil, json_schema: nil, state: nil, model: nil, thinking: nil, tools: [], mcp_servers: {}, logger: nil) ⇒ Assistant
constructor
A new instance of Assistant.
Constructor Details
#initialize(client: nil, json_schema: nil, state: nil, model: nil, thinking: nil, tools: [], mcp_servers: {}, logger: nil) ⇒ Assistant
Returns a new instance of Assistant.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/rasti/ai/assistant.rb', line 9 def initialize(client:nil, json_schema:nil, state:nil, model:nil, thinking:nil, tools:[], mcp_servers:{}, logger:nil) raise ArgumentError, "Invalid thinking level '#{thinking}'. Valid: #{VALID_THINKING_LEVELS.join(', ')}" if thinking && !VALID_THINKING_LEVELS.include?(thinking) @client = client || build_default_client @json_schema = json_schema @state = state || AssistantState.new @model = model @thinking = thinking @tools = {} @serialized_tools = [] @logger = logger || Rasti::AI.logger register_tools(tools) register_mcp_servers(mcp_servers) end |
Instance Attribute Details
#model ⇒ Object (readonly)
Returns the value of attribute model.
5 6 7 |
# File 'lib/rasti/ai/assistant.rb', line 5 def model @model end |
#state ⇒ Object (readonly)
Returns the value of attribute state.
5 6 7 |
# File 'lib/rasti/ai/assistant.rb', line 5 def state @state end |
#thinking ⇒ Object (readonly)
Returns the value of attribute thinking.
5 6 7 |
# File 'lib/rasti/ai/assistant.rb', line 5 def thinking @thinking end |
Instance Method Details
#call(prompt) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/rasti/ai/assistant.rb', line 25 def call(prompt) << (prompt) loop do response = request_completion tool_calls = parse_tool_calls(response) if tool_calls.any? << (response) tool_calls.each do |tool_call| name, args = extract_tool_call_info(tool_call) result = call_tool(name, args) << (tool_call, name, result) end else content = parse_content(response) << (content) return content if finished?(response) end end end |