Module: RubyConversations::Concerns::ConversationChat
- Extended by:
- ActiveSupport::Concern
- Included in:
- RubyConversations::ConversationManager
- Defined in:
- lib/ruby_conversations/concerns/conversation_chat.rb
Overview
Handles chat-related functionality for Conversation
Instance Attribute Summary collapse
-
#tools_optional ⇒ Object
Returns the value of attribute tools_optional.
Instance Method Summary collapse
- #call_llm(system_message: nil, &block) ⇒ Object (also: #execute)
- #enable_image_generation(size:, output_format:) ⇒ Object
- #llm ⇒ Object
- #tool_calls?(chat_messages) ⇒ Boolean
- #tool_names ⇒ Object
- #tools_configured? ⇒ Boolean
- #tools_required? ⇒ Boolean
- #validate_tool_calls(chat_messages) ⇒ Object
Instance Attribute Details
#tools_optional ⇒ Object
Returns the value of attribute tools_optional.
12 13 14 |
# File 'lib/ruby_conversations/concerns/conversation_chat.rb', line 12 def tools_optional @tools_optional end |
Instance Method Details
#call_llm(system_message: nil, &block) ⇒ Object Also known as: execute
18 19 20 21 22 23 24 25 |
# File 'lib/ruby_conversations/concerns/conversation_chat.rb', line 18 def call_llm(system_message: nil, &block) validate_conversation_state = generate_chat_response(, &block) validate_tool_calls() if tools_required? store_and_update_conversation() end |
#enable_image_generation(size:, output_format:) ⇒ Object
59 60 61 62 63 64 65 66 67 |
# File 'lib/ruby_conversations/concerns/conversation_chat.rb', line 59 def enable_image_generation(size:, output_format:) image_generation_tool_config = { type: 'image_generation', size:, output_format: }.compact chat.with_params(tools: [image_generation_tool_config]) end |
#llm ⇒ Object
55 56 57 |
# File 'lib/ruby_conversations/concerns/conversation_chat.rb', line 55 def llm model_identifier end |
#tool_calls?(chat_messages) ⇒ Boolean
51 52 53 |
# File 'lib/ruby_conversations/concerns/conversation_chat.rb', line 51 def tool_calls?() .any? { || .tool_calls.present? } end |
#tool_names ⇒ Object
47 48 49 |
# File 'lib/ruby_conversations/concerns/conversation_chat.rb', line 47 def tool_names tool&.name || tools&.map(&:name) end |
#tools_configured? ⇒ Boolean
43 44 45 |
# File 'lib/ruby_conversations/concerns/conversation_chat.rb', line 43 def tools_configured? tool.present? || tools&.present? end |
#tools_required? ⇒ Boolean
14 15 16 |
# File 'lib/ruby_conversations/concerns/conversation_chat.rb', line 14 def tools_required? !tools_optional end |
#validate_tool_calls(chat_messages) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/ruby_conversations/concerns/conversation_chat.rb', line 29 def validate_tool_calls() return unless tools_configured? return if tool_calls?() = .last&.content = "No tool call found for tool(s): '#{tool_names}'. Please check the prompt." raise RubyConversations::ToolCallValidationError.new( , last_message: , tool_names: tool_names ) end |