llama_bot_rails 0.1.4 β†’ 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9bd4c2d542ae02f6d430d6c6233792445b79dcff44b265d508c9d985db22b09b
4
- data.tar.gz: '09ad72a1840000cf121133633dc104517e5937a843be0cba48dadd0a3bf60a66'
3
+ metadata.gz: 44750a5b4dc8e228f8b3422c91f875024e8994a6800bccefd7a3c5303f1e0487
4
+ data.tar.gz: 4cb58030cd0100dbaf1d6a64f75ad2e12bc1840153f9d50661a6258aa429a55d
5
5
  SHA512:
6
- metadata.gz: 192fe783f3c6e91170bb3109dbb116d21ca7bb6c68ecb064a92435d416efa16a1e765e5ff59d07af5978e348724e9f70569dbbf2faaeab8ac9a432f7df1712e6
7
- data.tar.gz: 02362ff59435fd5a0b88038f276e2cc69d8fd70fac868b16ee4c1fa98bfb4ae36c298e541aec388a37856de636b9ee841bff81be971fbae50949925d2c9e3cd2
6
+ metadata.gz: f29e9c1d3ce80499e237bcbcfabe0bc6cd4ba6ab2271cef4b1d8f5bb4bec5d70753e66589368be68ea3f71b2f35dd613f2849a9c2f8beb2dc9cff530bcbc8fcf
7
+ data.tar.gz: e1eb3bf985687e22321804d7b572c027370ac57303fc82ef17ac088ec36af68a6d3030147ecad1a32fdc8cfe20e35bd4b72fdfa3195023db3570eeafa55072ff
data/README.md CHANGED
@@ -12,7 +12,7 @@ Chat with a powerful agent that has access to your models, your application cont
12
12
 
13
13
  ## πŸŽ₯ **See it in action** (30-Second Demo)
14
14
 
15
- πŸ‘‰ [Insert GIF or YouTube link here]
15
+ πŸ‘‰ ![LlamaBot Demo](https://llamapress-ai-image-uploads.s3.us-west-2.amazonaws.com/pp1s3l4iskwabnq0gi5tx8mi9mue)
16
16
  β€œWelcome to the future of Rails + AI.”
17
17
 
18
18
  ### The agent can:
@@ -38,6 +38,8 @@ rails generate llama_bot_rails:install
38
38
  # 3. Clone & run the LangGraph backend
39
39
  git clone https://github.com/kodykendall/llamabot
40
40
 
41
+ cd llamabot
42
+
41
43
  # 4. Set up your environment
42
44
  python3 -m venv venv
43
45
 
@@ -7,9 +7,25 @@ module LlamaBotRails
7
7
  # POST /agent/command
8
8
  def command
9
9
  input = params[:command]
10
+
11
+ # Capture both stdout and return value
12
+ output = StringIO.new
13
+ result = nil
14
+
15
+ $stdout = output
10
16
  result = safety_eval(input)
11
- render json: { result: result.inspect }
17
+ $stdout = STDOUT
18
+
19
+ # If result is a string and output has content, prefer output
20
+ final_result = if output.string.present?
21
+ output.string.strip
22
+ else
23
+ result
24
+ end
25
+
26
+ render json: { result: final_result }
12
27
  rescue => e
28
+ $stdout = STDOUT # Reset stdout on error
13
29
  render json: { error: e.class.name, message: e.message }, status: :unprocessable_entity
14
30
  end
15
31
 
@@ -53,12 +69,11 @@ module LlamaBotRails
53
69
  private
54
70
 
55
71
  def safety_eval(input)
56
- # VERY basic, sandbox for real use!
57
- result = eval(input)
58
-
59
- { result: result.inspect }
60
- rescue => e
61
- { error: e.class.name, message: e.message }
72
+ # Change to Rails root directory for file operations
73
+ Dir.chdir(Rails.root) do
74
+ # Create a safer evaluation context
75
+ binding.eval(input)
76
+ end
62
77
  end
63
78
 
64
79
  def authenticate_agent!
@@ -509,9 +509,17 @@
509
509
  }
510
510
  }
511
511
  </style>
512
- <%= javascript_importmap_tags %>
512
+
513
+ <% if defined?(javascript_importmap_tags) %> <!-- Rails 7+ -->
514
+ <%= javascript_importmap_tags %>
515
+ <% else %> <!-- Rails 6 -->
516
+ <%= javascript_include_tag "application" %>
517
+ <% end %>
518
+
513
519
  <%= javascript_include_tag "llama_bot_rails/application" %>
514
- <%= action_cable_meta_tag %>
520
+ <% if defined?(action_cable_meta_tag) %>
521
+ <%= action_cable_meta_tag %>
522
+ <% end %>
515
523
  <!-- Add Snarkdown CDN -->
516
524
  <script src="https://unpkg.com/snarkdown/dist/snarkdown.umd.js"></script>
517
525
  </head>
@@ -3,6 +3,11 @@ module LlamaBotRails
3
3
  module Generators
4
4
  class InstallGenerator < Rails::Generators::Base
5
5
  source_root File.expand_path("templates", __dir__)
6
+
7
+ def create_config_file
8
+ empty_directory "config/llama_bot"
9
+ copy_file "agent_prompt.txt", "config/llama_bot/agent_prompt.txt"
10
+ end
6
11
 
7
12
  def mount_engine
8
13
  say <<~MSG, :yellow
@@ -32,6 +37,7 @@ module LlamaBotRails
32
37
  create_file "config/initializers/llama_bot_rails.rb", <<~RUBY
33
38
  Rails.application.configure do
34
39
  config.llama_bot_rails.websocket_url = ENV.fetch("LLAMABOT_WEBSOCKET_URL", "ws://localhost:8000/ws")
40
+ config.llama_bot_rails.llamabot_api_url = ENV.fetch("LLAMABOT_API_URL", "http://localhost:8000")
35
41
  config.llama_bot_rails.enable_console_tool = !Rails.env.production?
36
42
  end
37
43
  RUBY
@@ -0,0 +1 @@
1
+ You are LlamaBot, a helpful assistant inside a Ruby on Rails app.
@@ -10,6 +10,7 @@ module LlamaBotRails
10
10
  user_message: @params[:message], # Rails param from JS/chat UI
11
11
  thread_id: @context[:thread_id],
12
12
  api_token: @context[:api_token],
13
+ agent_prompt: LlamaBotRails.agent_prompt_text,
13
14
  agent_name: "llamabot" #Very important. This routes to the appropriate LangGraph agent as defined in langgraph.json
14
15
  }
15
16
  end
@@ -14,7 +14,7 @@ module LlamaBotRails
14
14
  config.llama_bot_rails.websocket_url = 'ws://localhost:8000/ws' # <-- default
15
15
  config.llama_bot_rails.llamabot_api_url = "http://localhost:8000"
16
16
  config.llama_bot_rails.enable_console_tool = true
17
-
17
+
18
18
  initializer "llama_bot_rails.assets.precompile" do |app|
19
19
  app.config.assets.precompile += %w( llama_bot_rails/application.js )
20
20
  end
@@ -1,3 +1,3 @@
1
1
  module LlamaBotRails
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.6"
3
3
  end
@@ -6,5 +6,22 @@ module LlamaBotRails
6
6
  def config
7
7
  Rails.application.config.llama_bot_rails
8
8
  end
9
+
10
+ def agent_prompt_path
11
+ Rails.root.join("config", "llama_bot", "agent_prompt.txt")
12
+ end
13
+
14
+ def agent_prompt_text
15
+ if File.exist?(agent_prompt_path)
16
+ File.read(agent_prompt_path)
17
+ else
18
+ "You are LlamaBot, a helpful assistant." #Fallback default.
19
+ end
20
+ end
21
+
22
+ def add_instruction_to_agent_prompt!(new_instruction)
23
+ FileUtils.mkdir_p(agent_prompt_path.dirname)
24
+ File.write(agent_prompt_path, "\n#{new_instruction}", mode: 'a')
25
+ end
9
26
  end
10
27
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: llama_bot_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kody Kendall
@@ -15,7 +15,7 @@ dependencies:
15
15
  requirements:
16
16
  - - ">="
17
17
  - !ruby/object:Gem::Version
18
- version: '7.0'
18
+ version: '6.0'
19
19
  - - "<"
20
20
  - !ruby/object:Gem::Version
21
21
  version: '9.0'
@@ -25,7 +25,7 @@ dependencies:
25
25
  requirements:
26
26
  - - ">="
27
27
  - !ruby/object:Gem::Version
28
- version: '7.0'
28
+ version: '6.0'
29
29
  - - "<"
30
30
  - !ruby/object:Gem::Version
31
31
  version: '9.0'
@@ -35,7 +35,7 @@ dependencies:
35
35
  requirements:
36
36
  - - ">="
37
37
  - !ruby/object:Gem::Version
38
- version: '7.0'
38
+ version: '6.0'
39
39
  - - "<"
40
40
  - !ruby/object:Gem::Version
41
41
  version: '9.0'
@@ -45,7 +45,7 @@ dependencies:
45
45
  requirements:
46
46
  - - ">="
47
47
  - !ruby/object:Gem::Version
48
- version: '7.0'
48
+ version: '6.0'
49
49
  - - "<"
50
50
  - !ruby/object:Gem::Version
51
51
  version: '9.0'
@@ -122,6 +122,7 @@ files:
122
122
  - config/initializers/llama_bot_rails.rb
123
123
  - config/routes.rb
124
124
  - lib/generators/llama_bot_rails/install/install_generator.rb
125
+ - lib/generators/llama_bot_rails/install/templates/agent_prompt.txt
125
126
  - lib/llama_bot_rails.rb
126
127
  - lib/llama_bot_rails/agent_state_builder.rb
127
128
  - lib/llama_bot_rails/engine.rb