ruby_llm 1.8.0 → 1.8.1

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: def0767fe1f3e052f42bfddc4d3b69733d51cf8d39d057a08145307ef5f362a0
4
- data.tar.gz: fba9605e4458efb173dff1d131f0124c8252c4d71ca7a23527eb0d0a2543c75a
3
+ metadata.gz: c8662c9b8b38e5941ea7e66882d59e8583989135285bc4b7eaaf5b83c8c2326e
4
+ data.tar.gz: 33c168dc4d68d4cffb18bb0761adc42da51288a43aee78633d30f669bffaa47f
5
5
  SHA512:
6
- metadata.gz: 622b3b02ba5fb0cc0c49d7bc2d515e92abd0fa5714db70c8b0af64868cee9229b05ddefa6a990ab5f3788e7e07589628bd9f347f921346449a2154575e1e1ac1
7
- data.tar.gz: 890020ebc2817a3a388278510eaa2b31699eb660cce29ed1c19ebd5a67b3775f8ff83d9be58b31bac825719c6683d7ffcc321251a6f89dc58bafd135ea51ec25
6
+ metadata.gz: 6f94e7adcf5b6f50aca97718c615d8dfa681a483da841ca8214f3970ca918a2a8e384f07a494dad9db83da269068a502ab8caf14a441a2ecb86909617e06fdf9
7
+ data.tar.gz: 8342ae03bb413eb4b65b55c73629b1729b319e96e6976172fcaaa8ed19231280b5773eb8acccf4f563d63c801a78a03b20be5552189f86a4a7e435fb426c354f
data/README.md CHANGED
@@ -9,7 +9,7 @@
9
9
 
10
10
  Battle tested at [<picture><source media="(prefers-color-scheme: dark)" srcset="https://chatwithwork.com/logotype-dark.svg"><img src="https://chatwithwork.com/logotype.svg" alt="Chat with Work" height="30" align="absmiddle"></picture>](https://chatwithwork.com) — *Claude Code for your documents*
11
11
 
12
- [![Gem Version](https://badge.fury.io/rb/ruby_llm.svg?a=9)](https://badge.fury.io/rb/ruby_llm)
12
+ [![Gem Version](https://badge.fury.io/rb/ruby_llm.svg?a=10)](https://badge.fury.io/rb/ruby_llm)
13
13
  [![Ruby Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://github.com/testdouble/standard)
14
14
  [![Gem Downloads](https://img.shields.io/gem/dt/ruby_llm)](https://rubygems.org/gems/ruby_llm)
15
15
  [![codecov](https://codecov.io/gh/crmne/ruby_llm/branch/main/graph/badge.svg?a=2)](https://codecov.io/gh/crmne/ruby_llm)
@@ -69,6 +69,11 @@ RubyLLM.paint "a sunset over mountains in watercolor style"
69
69
  RubyLLM.embed "Ruby is elegant and expressive"
70
70
  ```
71
71
 
72
+ ```ruby
73
+ # Moderate content for safety
74
+ RubyLLM.moderate("Check if this text is safe").flagged? # => false
75
+ ```
76
+
72
77
  ```ruby
73
78
  # Let AI use your code
74
79
  class Weather < RubyLLM::Tool
@@ -106,6 +111,7 @@ response = chat.with_schema(ProductSchema).ask "Analyze this product", with: "pr
106
111
  * **Documents:** Extract from PDFs, CSVs, JSON, any file type
107
112
  * **Image generation:** Create images with `RubyLLM.paint`
108
113
  * **Embeddings:** Vector search with `RubyLLM.embed`
114
+ * **Moderation:** Content safety with `RubyLLM.moderate`
109
115
  * **Tools:** Let AI call your Ruby methods
110
116
  * **Structured output:** JSON schemas that just work
111
117
  * **Streaming:** Real-time responses with blocks
@@ -133,7 +139,11 @@ end
133
139
  ## Rails
134
140
 
135
141
  ```bash
142
+ # Install database models
136
143
  rails generate ruby_llm:install
144
+
145
+ # Add chat UI (optional)
146
+ rails generate ruby_llm:chat_ui
137
147
  ```
138
148
 
139
149
  ```ruby
@@ -141,10 +151,12 @@ class Chat < ApplicationRecord
141
151
  acts_as_chat
142
152
  end
143
153
 
144
- chat = Chat.create! model_id: "claude-sonnet-4"
154
+ chat = Chat.create! model: "claude-sonnet-4"
145
155
  chat.ask "What's in this file?", with: "report.pdf"
146
156
  ```
147
157
 
158
+ Visit `http://localhost:3000/chats` for a ready-to-use chat interface!
159
+
148
160
  ## Documentation
149
161
 
150
162
  [rubyllm.com](https://rubyllm.com)
@@ -56,6 +56,7 @@ module RubyLLM
56
56
  # Message views
57
57
  template 'views/messages/_message.html.erb',
58
58
  "app/views/#{message_table_name}/_#{message_model_name.underscore}.html.erb"
59
+ template 'views/messages/_content.html.erb', "app/views/#{message_table_name}/_content.html.erb"
59
60
  template 'views/messages/_form.html.erb', "app/views/#{message_table_name}/_form.html.erb"
60
61
  template 'views/messages/create.turbo_stream.erb',
61
62
  "app/views/#{message_table_name}/create.turbo_stream.erb"
@@ -99,12 +100,23 @@ module RubyLLM
99
100
  chat_var = chat_model_name.underscore
100
101
  broadcasting_code = "broadcasts_to ->(#{msg_var}) { \"#{chat_var}_\#{#{msg_var}.#{chat_var}_id}\" }"
101
102
 
102
- inject_into_class "app/models/#{msg_var}.rb", message_model_name do
103
- "\n #{broadcasting_code}\n"
103
+ broadcast_append_chunk_method = <<-RUBY
104
+
105
+ def broadcast_append_chunk(content)
106
+ broadcast_append_to "#{chat_var}_\#{#{chat_var}_id}",
107
+ target: "#{msg_var}_\#{id}_content",
108
+ partial: "#{message_table_name}/content",
109
+ locals: { content: content }
110
+ end
111
+ RUBY
112
+
113
+ inject_into_file "app/models/#{msg_var}.rb", before: "end\n" do
114
+ " #{broadcasting_code}\n#{broadcast_append_chunk_method}"
104
115
  end
105
116
  rescue Errno::ENOENT
106
117
  say "#{message_model_name} model not found. Add broadcasting code to your model.", :yellow
107
118
  say " #{broadcasting_code}", :yellow
119
+ say broadcast_append_chunk_method, :yellow
108
120
  end
109
121
 
110
122
  def display_post_install_message
@@ -5,7 +5,7 @@ class <%= chat_model_name %>ResponseJob < ApplicationJob
5
5
  <%= chat_model_name.underscore %>.ask(content) do |chunk|
6
6
  if chunk.content && !chunk.content.blank?
7
7
  <%= message_model_name.underscore %> = <%= chat_model_name.underscore %>.<%= message_model_name.tableize %>.last
8
- <%= message_model_name.underscore %>.update!(content: <%= message_model_name.underscore %>.content + chunk.content)
8
+ <%= message_model_name.underscore %>.broadcast_append_chunk(chunk.content)
9
9
  end
10
10
  end
11
11
  end
@@ -3,7 +3,7 @@
3
3
  <div style="font-weight: bold; margin-bottom: 5px;">
4
4
  <%%= <%= message_model_name.underscore %>.role&.capitalize %>
5
5
  </div>
6
- <div style="white-space: pre-wrap;"><%%= <%= message_model_name.underscore %>.content %></div>
6
+ <div id="<%%= dom_id(<%= message_model_name.underscore %>) %>_content" style="white-space: pre-wrap;"><%%= <%= message_model_name.underscore %>.content %></div>
7
7
  <div style="font-size: 0.85em; color: #666; margin-top: 5px;">
8
8
  <%%= <%= message_model_name.underscore %>.created_at&.strftime("%I:%M %p") %>
9
9
  </div>