1313# export OPENAI_API_KEY='your-key-here'
1414# ruby examples/docker_chat.rb
1515#
16+ # Debug mode:
17+ # ruby examples/docker_chat.rb --debug # Enable debug output
18+ # DOCKER_CHAT_DEBUG=true ruby examples/docker_chat.rb # Via environment variable
19+ #
1620# Commands:
1721# /exit - Exit the chat
1822# /help - Show available Docker tools
1923# /tools - List all loaded tools
2024# /clear - Clear the screen
25+ # /debug - Toggle debug mode on/off
2126# anything else - Send to OpenAI with Docker tools available
2227
2328require_relative '../lib/ruby_llm/docker'
@@ -31,6 +36,7 @@ class DockerChat
3136 def initialize
3237 check_environment
3338 configure_ruby_llm
39+ setup_debug_mode
3440 setup_chat
3541 @running = true
3642 end
@@ -57,8 +63,29 @@ def configure_ruby_llm
5763 end
5864 end
5965
66+ def setup_debug_mode
67+ # Check for debug mode via environment variable or command line argument
68+ @debug_mode = ENV [ 'DOCKER_CHAT_DEBUG' ] == 'true' || ARGV . include? ( '--debug' ) || ARGV . include? ( '-d' )
69+ debug_puts 'π Debug mode enabled' if @debug_mode
70+ end
71+
72+ def debug_puts ( message )
73+ puts message if @debug_mode
74+ end
75+
6076 def setup_chat
77+ # rubocop:disable Layout/BlockAlignment
78+ # rubocop:disable Style/MultilineBlockChain
6179 @chat = RubyLLM . chat ( model : 'gpt-4' )
80+ . on_tool_call do |tool_call |
81+ debug_puts "π§ Calling tool: #{ tool_call . name } "
82+ debug_puts "π Arguments: #{ tool_call . arguments } "
83+ end
84+ . on_tool_result do |result |
85+ debug_puts "β
Tool returned: #{ result } "
86+ end
87+ # rubocop:enable Layout/BlockAlignment
88+ # rubocop:enable Style/MultilineBlockChain
6289
6390 # Add all Docker tools to the chat
6491 RubyLLM ::Docker . add_all_tools_to_chat ( @chat )
@@ -81,9 +108,11 @@ def show_welcome
81108 puts ' /help - Show available Docker tools'
82109 puts ' /tools - List all loaded tools'
83110 puts ' /clear - Clear the screen'
111+ puts ' /debug - Toggle debug mode on/off'
84112 puts
85113 puts 'π Ready! Type your questions or commands...'
86114 puts
115+ debug_puts 'π Debug mode is currently enabled. Use /debug to toggle.'
87116 end
88117
89118 def main_loop
@@ -121,6 +150,8 @@ def process_input(input)
121150 show_tools
122151 when '/clear' , '/c'
123152 clear_screen
153+ when '/debug' , '/d'
154+ toggle_debug_mode
124155 when input . start_with? ( '/' )
125156 puts "β Unknown command: #{ input } "
126157 puts ' Type /help for available commands'
@@ -211,6 +242,13 @@ def clear_screen
211242 puts 'π³ Docker Chat - Screen cleared'
212243 end
213244
245+ def toggle_debug_mode
246+ @debug_mode = !@debug_mode
247+ status = @debug_mode ? 'enabled' : 'disabled'
248+ puts "π Debug mode #{ status } "
249+ debug_puts 'Debug output will now be shown for tool calls and results' if @debug_mode
250+ end
251+
214252 def show_goodbye
215253 puts "\n π Thanks for using Docker Chat!"
216254 puts ' Hope you found it helpful for managing your Docker environment.'
0 commit comments