dify_llm 1.7.1 → 1.8.0

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: d0f99a2d917ed4eec1d713f9485558da63d1682463151199705a11c067580d00
4
- data.tar.gz: c78eef62613a3295db307362b497367affc65687ed295889bd1bb87f2ec1898c
3
+ metadata.gz: 80cc1d17f6a70b28e6f8cfe72ceb5ac79398e5b569f2519a0ba9fe34cba3ae30
4
+ data.tar.gz: 429561f0d6191e55248ef5610eb42a52dc70acfb97bea116ee70ae53a0919c5f
5
5
  SHA512:
6
- metadata.gz: 6cccd8779101a2f72b73e65aec7b84def9ac63368fd4a07e36347c3c544e687a03ea44ccc7ad85208833e8e7058ccb76d8316d86507951d4adc21be98a7edc1d
7
- data.tar.gz: 4627baa37a9e94b0569ab25b7d7e39ceb5119022f13092c81f34c0a589c11f22d30b82cf02adf33e11914cf01b1304db111c4fc3253529dc91d7dc734631be0f
6
+ metadata.gz: f4477d96e5572468bb8128105d97eac680e661da7182d7638e789cf8a6908a48ac9719e884995f39eb40093edc10986afee5137f238129a80d5726bcd0881f8f
7
+ data.tar.gz: ea459447ae6000b3f044da995516c9aeed5683c2c8801ab633601d8c530470d5b35f8076b4592525dc501b36d8a867224be2fcb47cbedbbb3d6ba6bd4dc3b863
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=8)](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)
@@ -41,6 +41,7 @@ chat.ask "What's the best way to learn Ruby?"
41
41
  ```ruby
42
42
  # Analyze any file type
43
43
  chat.ask "What's in this image?", with: "ruby_conf.jpg"
44
+ chat.ask "What's happening in this video?", with: "video.mp4"
44
45
  chat.ask "Describe this meeting", with: "meeting.wav"
45
46
  chat.ask "Summarize this document", with: "contract.pdf"
46
47
  chat.ask "Explain this code", with: "app.rb"
@@ -68,6 +69,11 @@ RubyLLM.paint "a sunset over mountains in watercolor style"
68
69
  RubyLLM.embed "Ruby is elegant and expressive"
69
70
  ```
70
71
 
72
+ ```ruby
73
+ # Moderate content for safety
74
+ RubyLLM.moderate("Check if this text is safe").flagged? # => false
75
+ ```
76
+
71
77
  ```ruby
72
78
  # Let AI use your code
73
79
  class Weather < RubyLLM::Tool
@@ -100,11 +106,12 @@ response = chat.with_schema(ProductSchema).ask "Analyze this product", with: "pr
100
106
  ## Features
101
107
 
102
108
  * **Chat:** Conversational AI with `RubyLLM.chat`
103
- * **Vision:** Analyze images and screenshots
109
+ * **Vision:** Analyze images and videos
104
110
  * **Audio:** Transcribe and understand speech
105
111
  * **Documents:** Extract from PDFs, CSVs, JSON, any file type
106
112
  * **Image generation:** Create images with `RubyLLM.paint`
107
113
  * **Embeddings:** Vector search with `RubyLLM.embed`
114
+ * **Moderation:** Content safety with `RubyLLM.moderate`
108
115
  * **Tools:** Let AI call your Ruby methods
109
116
  * **Structured output:** JSON schemas that just work
110
117
  * **Streaming:** Real-time responses with blocks
@@ -132,7 +139,11 @@ end
132
139
  ## Rails
133
140
 
134
141
  ```bash
142
+ # Install database models
135
143
  rails generate ruby_llm:install
144
+
145
+ # Add chat UI (optional)
146
+ rails generate ruby_llm:chat_ui
136
147
  ```
137
148
 
138
149
  ```ruby
@@ -140,10 +151,12 @@ class Chat < ApplicationRecord
140
151
  acts_as_chat
141
152
  end
142
153
 
143
- chat = Chat.create! model_id: "claude-sonnet-4"
154
+ chat = Chat.create! model: "claude-sonnet-4"
144
155
  chat.ask "What's in this file?", with: "report.pdf"
145
156
  ```
146
157
 
158
+ Visit `http://localhost:3000/chats` for a ready-to-use chat interface!
159
+
147
160
  ## Documentation
148
161
 
149
162
  [rubyllm.com](https://rubyllm.com)
@@ -32,12 +32,12 @@ module RubyLLM
32
32
  migration_template 'create_chats_migration.rb.tt',
33
33
  "db/migrate/create_#{chat_table_name}.rb"
34
34
 
35
- # Then create messages table (must come before tool_calls due to foreign key)
35
+ # Then create messages table
36
36
  sleep 1 # Ensure different timestamp
37
37
  migration_template 'create_messages_migration.rb.tt',
38
38
  "db/migrate/create_#{message_table_name}.rb"
39
39
 
40
- # Then create tool_calls table (references messages)
40
+ # Then create tool_calls table
41
41
  sleep 1 # Ensure different timestamp
42
42
  migration_template 'create_tool_calls_migration.rb.tt',
43
43
  "db/migrate/create_#{tool_call_table_name}.rb"
@@ -46,6 +46,12 @@ module RubyLLM
46
46
  sleep 1 # Ensure different timestamp
47
47
  migration_template 'create_models_migration.rb.tt',
48
48
  "db/migrate/create_#{model_table_name}.rb"
49
+
50
+ # Add references to chats, tool_calls and messages.
51
+ sleep 1 # Ensure different timestamp
52
+ migration_template 'add_references_to_chats_tool_calls_and_messages_migration.rb.tt',
53
+ 'db/migrate/add_references_to_' \
54
+ "#{chat_table_name}_#{tool_call_table_name}_and_#{message_table_name}.rb"
49
55
  end
50
56
 
51
57
  def create_model_files
@@ -0,0 +1,9 @@
1
+ class AddReferencesTo<%= "#{chat_model_name.gsub('::', '').pluralize}#{tool_call_model_name.gsub('::', '').pluralize}And#{message_model_name.gsub('::', '').pluralize}" %> < ActiveRecord::Migration<%= migration_version %>
2
+ def change
3
+ add_reference :<%= chat_table_name %>, :<%= model_table_name.singularize %>, foreign_key: true
4
+ add_reference :<%= tool_call_table_name %>, :<%= message_table_name.singularize %>, null: false, foreign_key: true
5
+ add_reference :<%= message_table_name %>, :<%= chat_table_name.singularize %>, null: false, foreign_key: true
6
+ add_reference :<%= message_table_name %>, :<%= model_table_name.singularize %>, foreign_key: true
7
+ add_reference :<%= message_table_name %>, :<%= tool_call_table_name.singularize %>, foreign_key: true
8
+ end
9
+ end
@@ -1,7 +1,6 @@
1
1
  class Create<%= chat_model_name.gsub('::', '').pluralize %> < ActiveRecord::Migration<%= migration_version %>
2
2
  def change
3
3
  create_table :<%= chat_table_name %> do |t|
4
- t.references :<%= model_table_name.singularize %>, foreign_key: true
5
4
  t.timestamps
6
5
  end
7
6
  end
@@ -1,13 +1,10 @@
1
1
  class Create<%= message_model_name.gsub('::', '').pluralize %> < ActiveRecord::Migration<%= migration_version %>
2
2
  def change
3
3
  create_table :<%= message_table_name %> do |t|
4
- t.references :<%= chat_table_name.singularize %>, null: false, foreign_key: true
5
4
  t.string :role, null: false
6
5
  t.text :content
7
- t.references :<%= model_table_name.singularize %>, foreign_key: true
8
6
  t.integer :input_tokens
9
7
  t.integer :output_tokens
10
- t.references :<%= tool_call_table_name.singularize %>, foreign_key: true
11
8
  t.timestamps
12
9
  end
13
10
 
@@ -2,7 +2,6 @@
2
2
  class Create<%= tool_call_model_name.gsub('::', '').pluralize %> < ActiveRecord::Migration<%= migration_version %>
3
3
  def change
4
4
  create_table :<%= tool_call_table_name %> do |t|
5
- t.references :<%= message_table_name.singularize %>, null: false, foreign_key: true
6
5
  t.string :tool_call_id, null: false
7
6
  t.string :name, null: false
8
7
  t.<%= postgresql? ? 'jsonb' : 'json' %> :arguments, default: {}
@@ -83,6 +83,7 @@ module RubyLLM
83
83
  def type
84
84
  return :file_id unless @upload_file_id.nil?
85
85
  return :image if image?
86
+ return :video if video?
86
87
  return :audio if audio?
87
88
  return :pdf if pdf?
88
89
  return :text if text?
@@ -94,6 +95,10 @@ module RubyLLM
94
95
  RubyLLM::MimeType.image? mime_type
95
96
  end
96
97
 
98
+ def video?
99
+ RubyLLM::MimeType.video? mime_type
100
+ end
101
+
97
102
  def audio?
98
103
  RubyLLM::MimeType.audio? mime_type
99
104
  end
@@ -29,6 +29,7 @@ module RubyLLM
29
29
  # Default models
30
30
  :default_model,
31
31
  :default_embedding_model,
32
+ :default_moderation_model,
32
33
  :default_image_model,
33
34
  # Model registry
34
35
  :model_registry_class,
@@ -57,6 +58,7 @@ module RubyLLM
57
58
 
58
59
  @default_model = 'gpt-4.1-nano'
59
60
  @default_embedding_model = 'text-embedding-3-small'
61
+ @default_moderation_model = 'omni-moderation-latest'
60
62
  @default_image_model = 'gpt-image-1'
61
63
 
62
64
  @model_registry_class = 'Model'
@@ -15,6 +15,10 @@ module RubyLLM
15
15
  type.start_with?('image/')
16
16
  end
17
17
 
18
+ def video?(type)
19
+ type.start_with?('video/')
20
+ end
21
+
18
22
  def audio?(type)
19
23
  type.start_with?('audio/')
20
24
  end
@@ -56,6 +56,10 @@ module RubyLLM
56
56
  modalities.input.include?('image')
57
57
  end
58
58
 
59
+ def supports_video?
60
+ modalities.input.include?('video')
61
+ end
62
+
59
63
  def supports_functions?
60
64
  function_calling?
61
65
  end