lex-llm 0.1.2 → 0.1.3

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.
Files changed (165) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/CHANGELOG.md +7 -1
  4. data/Gemfile +1 -19
  5. data/README.md +22 -25
  6. data/lex-llm.gemspec +2 -2
  7. data/lib/legion/extensions/llm/agent.rb +366 -0
  8. data/lib/legion/extensions/llm/aliases.rb +42 -0
  9. data/lib/legion/extensions/llm/attachment.rb +229 -0
  10. data/lib/legion/extensions/llm/chat.rb +355 -0
  11. data/lib/legion/extensions/llm/chunk.rb +10 -0
  12. data/lib/legion/extensions/llm/configuration.rb +82 -0
  13. data/lib/legion/extensions/llm/connection.rb +134 -0
  14. data/lib/legion/extensions/llm/content.rb +81 -0
  15. data/lib/legion/extensions/llm/context.rb +33 -0
  16. data/lib/legion/extensions/llm/embedding.rb +33 -0
  17. data/lib/legion/extensions/llm/error.rb +116 -0
  18. data/lib/legion/extensions/llm/image.rb +109 -0
  19. data/lib/legion/extensions/llm/message.rb +111 -0
  20. data/lib/legion/extensions/llm/mime_type.rb +75 -0
  21. data/lib/legion/extensions/llm/model/info.rb +117 -0
  22. data/lib/legion/extensions/llm/model/modalities.rb +26 -0
  23. data/lib/legion/extensions/llm/model/pricing.rb +52 -0
  24. data/lib/legion/extensions/llm/model/pricing_category.rb +50 -0
  25. data/lib/legion/extensions/llm/model/pricing_tier.rb +37 -0
  26. data/lib/legion/extensions/llm/model.rb +11 -0
  27. data/lib/legion/extensions/llm/models.rb +514 -0
  28. data/lib/{lex_llm → legion/extensions/llm}/models_schema.json +1 -1
  29. data/lib/legion/extensions/llm/moderation.rb +60 -0
  30. data/lib/legion/extensions/llm/provider/open_ai_compatible.rb +240 -0
  31. data/lib/legion/extensions/llm/provider.rb +282 -0
  32. data/lib/legion/extensions/llm/routing/lane_key.rb +57 -0
  33. data/lib/legion/extensions/llm/routing/model_offering.rb +173 -0
  34. data/lib/legion/extensions/llm/routing.rb +11 -0
  35. data/lib/legion/extensions/llm/stream_accumulator.rb +209 -0
  36. data/lib/legion/extensions/llm/streaming.rb +181 -0
  37. data/lib/legion/extensions/llm/thinking.rb +53 -0
  38. data/lib/legion/extensions/llm/tokens.rb +51 -0
  39. data/lib/legion/extensions/llm/tool.rb +258 -0
  40. data/lib/legion/extensions/llm/tool_call.rb +29 -0
  41. data/lib/legion/extensions/llm/transcription.rb +39 -0
  42. data/lib/legion/extensions/llm/utils.rb +95 -0
  43. data/lib/legion/extensions/llm/version.rb +9 -0
  44. data/lib/legion/extensions/llm.rb +85 -6
  45. metadata +40 -122
  46. data/lib/generators/lex_llm/agent/agent_generator.rb +0 -36
  47. data/lib/generators/lex_llm/agent/templates/agent.rb.tt +0 -6
  48. data/lib/generators/lex_llm/agent/templates/instructions.txt.erb.tt +0 -0
  49. data/lib/generators/lex_llm/chat_ui/chat_ui_generator.rb +0 -256
  50. data/lib/generators/lex_llm/chat_ui/templates/controllers/chats_controller.rb.tt +0 -38
  51. data/lib/generators/lex_llm/chat_ui/templates/controllers/messages_controller.rb.tt +0 -21
  52. data/lib/generators/lex_llm/chat_ui/templates/controllers/models_controller.rb.tt +0 -14
  53. data/lib/generators/lex_llm/chat_ui/templates/helpers/messages_helper.rb.tt +0 -25
  54. data/lib/generators/lex_llm/chat_ui/templates/jobs/chat_response_job.rb.tt +0 -12
  55. data/lib/generators/lex_llm/chat_ui/templates/tailwind/views/chats/_chat.html.erb.tt +0 -16
  56. data/lib/generators/lex_llm/chat_ui/templates/tailwind/views/chats/_form.html.erb.tt +0 -31
  57. data/lib/generators/lex_llm/chat_ui/templates/tailwind/views/chats/index.html.erb.tt +0 -31
  58. data/lib/generators/lex_llm/chat_ui/templates/tailwind/views/chats/new.html.erb.tt +0 -9
  59. data/lib/generators/lex_llm/chat_ui/templates/tailwind/views/chats/show.html.erb.tt +0 -27
  60. data/lib/generators/lex_llm/chat_ui/templates/tailwind/views/messages/_assistant.html.erb.tt +0 -14
  61. data/lib/generators/lex_llm/chat_ui/templates/tailwind/views/messages/_content.html.erb.tt +0 -1
  62. data/lib/generators/lex_llm/chat_ui/templates/tailwind/views/messages/_error.html.erb.tt +0 -13
  63. data/lib/generators/lex_llm/chat_ui/templates/tailwind/views/messages/_form.html.erb.tt +0 -23
  64. data/lib/generators/lex_llm/chat_ui/templates/tailwind/views/messages/_system.html.erb.tt +0 -10
  65. data/lib/generators/lex_llm/chat_ui/templates/tailwind/views/messages/_tool.html.erb.tt +0 -2
  66. data/lib/generators/lex_llm/chat_ui/templates/tailwind/views/messages/_tool_calls.html.erb.tt +0 -4
  67. data/lib/generators/lex_llm/chat_ui/templates/tailwind/views/messages/_user.html.erb.tt +0 -14
  68. data/lib/generators/lex_llm/chat_ui/templates/tailwind/views/messages/tool_calls/_default.html.erb.tt +0 -13
  69. data/lib/generators/lex_llm/chat_ui/templates/tailwind/views/messages/tool_results/_default.html.erb.tt +0 -21
  70. data/lib/generators/lex_llm/chat_ui/templates/tailwind/views/models/_model.html.erb.tt +0 -17
  71. data/lib/generators/lex_llm/chat_ui/templates/tailwind/views/models/index.html.erb.tt +0 -40
  72. data/lib/generators/lex_llm/chat_ui/templates/tailwind/views/models/show.html.erb.tt +0 -27
  73. data/lib/generators/lex_llm/chat_ui/templates/views/chats/_chat.html.erb.tt +0 -16
  74. data/lib/generators/lex_llm/chat_ui/templates/views/chats/_form.html.erb.tt +0 -29
  75. data/lib/generators/lex_llm/chat_ui/templates/views/chats/index.html.erb.tt +0 -28
  76. data/lib/generators/lex_llm/chat_ui/templates/views/chats/new.html.erb.tt +0 -11
  77. data/lib/generators/lex_llm/chat_ui/templates/views/chats/show.html.erb.tt +0 -25
  78. data/lib/generators/lex_llm/chat_ui/templates/views/messages/_assistant.html.erb.tt +0 -9
  79. data/lib/generators/lex_llm/chat_ui/templates/views/messages/_content.html.erb.tt +0 -1
  80. data/lib/generators/lex_llm/chat_ui/templates/views/messages/_error.html.erb.tt +0 -8
  81. data/lib/generators/lex_llm/chat_ui/templates/views/messages/_form.html.erb.tt +0 -21
  82. data/lib/generators/lex_llm/chat_ui/templates/views/messages/_system.html.erb.tt +0 -6
  83. data/lib/generators/lex_llm/chat_ui/templates/views/messages/_tool.html.erb.tt +0 -2
  84. data/lib/generators/lex_llm/chat_ui/templates/views/messages/_tool_calls.html.erb.tt +0 -4
  85. data/lib/generators/lex_llm/chat_ui/templates/views/messages/_user.html.erb.tt +0 -9
  86. data/lib/generators/lex_llm/chat_ui/templates/views/messages/create.turbo_stream.erb.tt +0 -7
  87. data/lib/generators/lex_llm/chat_ui/templates/views/messages/tool_calls/_default.html.erb.tt +0 -8
  88. data/lib/generators/lex_llm/chat_ui/templates/views/messages/tool_results/_default.html.erb.tt +0 -16
  89. data/lib/generators/lex_llm/chat_ui/templates/views/models/_model.html.erb.tt +0 -15
  90. data/lib/generators/lex_llm/chat_ui/templates/views/models/index.html.erb.tt +0 -38
  91. data/lib/generators/lex_llm/chat_ui/templates/views/models/show.html.erb.tt +0 -17
  92. data/lib/generators/lex_llm/generator_helpers.rb +0 -214
  93. data/lib/generators/lex_llm/install/install_generator.rb +0 -109
  94. data/lib/generators/lex_llm/install/templates/add_references_to_chats_tool_calls_and_messages_migration.rb.tt +0 -9
  95. data/lib/generators/lex_llm/install/templates/chat_model.rb.tt +0 -3
  96. data/lib/generators/lex_llm/install/templates/create_chats_migration.rb.tt +0 -7
  97. data/lib/generators/lex_llm/install/templates/create_messages_migration.rb.tt +0 -19
  98. data/lib/generators/lex_llm/install/templates/create_models_migration.rb.tt +0 -39
  99. data/lib/generators/lex_llm/install/templates/create_tool_calls_migration.rb.tt +0 -21
  100. data/lib/generators/lex_llm/install/templates/initializer.rb.tt +0 -20
  101. data/lib/generators/lex_llm/install/templates/message_model.rb.tt +0 -4
  102. data/lib/generators/lex_llm/install/templates/model_model.rb.tt +0 -3
  103. data/lib/generators/lex_llm/install/templates/tool_call_model.rb.tt +0 -3
  104. data/lib/generators/lex_llm/schema/schema_generator.rb +0 -26
  105. data/lib/generators/lex_llm/schema/templates/schema.rb.tt +0 -2
  106. data/lib/generators/lex_llm/tool/templates/tool.rb.tt +0 -9
  107. data/lib/generators/lex_llm/tool/templates/tool_call.html.erb.tt +0 -13
  108. data/lib/generators/lex_llm/tool/templates/tool_result.html.erb.tt +0 -13
  109. data/lib/generators/lex_llm/tool/tool_generator.rb +0 -96
  110. data/lib/generators/lex_llm/upgrade_to_v1_10/templates/add_v1_10_message_columns.rb.tt +0 -19
  111. data/lib/generators/lex_llm/upgrade_to_v1_10/upgrade_to_v1_10_generator.rb +0 -50
  112. data/lib/generators/lex_llm/upgrade_to_v1_14/templates/add_v1_14_tool_call_columns.rb.tt +0 -7
  113. data/lib/generators/lex_llm/upgrade_to_v1_14/upgrade_to_v1_14_generator.rb +0 -49
  114. data/lib/generators/lex_llm/upgrade_to_v1_7/templates/migration.rb.tt +0 -145
  115. data/lib/generators/lex_llm/upgrade_to_v1_7/upgrade_to_v1_7_generator.rb +0 -122
  116. data/lib/generators/lex_llm/upgrade_to_v1_9/templates/add_v1_9_message_columns.rb.tt +0 -15
  117. data/lib/generators/lex_llm/upgrade_to_v1_9/upgrade_to_v1_9_generator.rb +0 -49
  118. data/lib/lex_llm/active_record/acts_as.rb +0 -180
  119. data/lib/lex_llm/active_record/acts_as_legacy.rb +0 -503
  120. data/lib/lex_llm/active_record/chat_methods.rb +0 -468
  121. data/lib/lex_llm/active_record/message_methods.rb +0 -131
  122. data/lib/lex_llm/active_record/model_methods.rb +0 -76
  123. data/lib/lex_llm/active_record/payload_helpers.rb +0 -26
  124. data/lib/lex_llm/active_record/tool_call_methods.rb +0 -15
  125. data/lib/lex_llm/agent.rb +0 -365
  126. data/lib/lex_llm/aliases.rb +0 -38
  127. data/lib/lex_llm/attachment.rb +0 -223
  128. data/lib/lex_llm/chat.rb +0 -351
  129. data/lib/lex_llm/chunk.rb +0 -6
  130. data/lib/lex_llm/configuration.rb +0 -81
  131. data/lib/lex_llm/connection.rb +0 -130
  132. data/lib/lex_llm/content.rb +0 -77
  133. data/lib/lex_llm/context.rb +0 -29
  134. data/lib/lex_llm/embedding.rb +0 -29
  135. data/lib/lex_llm/error.rb +0 -112
  136. data/lib/lex_llm/image.rb +0 -105
  137. data/lib/lex_llm/message.rb +0 -107
  138. data/lib/lex_llm/mime_type.rb +0 -71
  139. data/lib/lex_llm/model/info.rb +0 -113
  140. data/lib/lex_llm/model/modalities.rb +0 -22
  141. data/lib/lex_llm/model/pricing.rb +0 -48
  142. data/lib/lex_llm/model/pricing_category.rb +0 -46
  143. data/lib/lex_llm/model/pricing_tier.rb +0 -33
  144. data/lib/lex_llm/model.rb +0 -7
  145. data/lib/lex_llm/models.rb +0 -506
  146. data/lib/lex_llm/moderation.rb +0 -56
  147. data/lib/lex_llm/provider/open_ai_compatible.rb +0 -219
  148. data/lib/lex_llm/provider.rb +0 -278
  149. data/lib/lex_llm/railtie.rb +0 -35
  150. data/lib/lex_llm/routing/lane_key.rb +0 -51
  151. data/lib/lex_llm/routing/model_offering.rb +0 -169
  152. data/lib/lex_llm/routing.rb +0 -7
  153. data/lib/lex_llm/stream_accumulator.rb +0 -203
  154. data/lib/lex_llm/streaming.rb +0 -175
  155. data/lib/lex_llm/thinking.rb +0 -49
  156. data/lib/lex_llm/tokens.rb +0 -47
  157. data/lib/lex_llm/tool.rb +0 -254
  158. data/lib/lex_llm/tool_call.rb +0 -25
  159. data/lib/lex_llm/transcription.rb +0 -35
  160. data/lib/lex_llm/utils.rb +0 -91
  161. data/lib/lex_llm/version.rb +0 -5
  162. data/lib/lex_llm.rb +0 -96
  163. data/lib/tasks/lex_llm.rake +0 -23
  164. /data/lib/{lex_llm → legion/extensions/llm}/aliases.json +0 -0
  165. /data/lib/{lex_llm → legion/extensions/llm}/models.json +0 -0
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lex-llm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - LegionIO
@@ -196,130 +196,48 @@ files:
196
196
  - LICENSE
197
197
  - README.md
198
198
  - lex-llm.gemspec
199
- - lib/generators/lex_llm/agent/agent_generator.rb
200
- - lib/generators/lex_llm/agent/templates/agent.rb.tt
201
- - lib/generators/lex_llm/agent/templates/instructions.txt.erb.tt
202
- - lib/generators/lex_llm/chat_ui/chat_ui_generator.rb
203
- - lib/generators/lex_llm/chat_ui/templates/controllers/chats_controller.rb.tt
204
- - lib/generators/lex_llm/chat_ui/templates/controllers/messages_controller.rb.tt
205
- - lib/generators/lex_llm/chat_ui/templates/controllers/models_controller.rb.tt
206
- - lib/generators/lex_llm/chat_ui/templates/helpers/messages_helper.rb.tt
207
- - lib/generators/lex_llm/chat_ui/templates/jobs/chat_response_job.rb.tt
208
- - lib/generators/lex_llm/chat_ui/templates/tailwind/views/chats/_chat.html.erb.tt
209
- - lib/generators/lex_llm/chat_ui/templates/tailwind/views/chats/_form.html.erb.tt
210
- - lib/generators/lex_llm/chat_ui/templates/tailwind/views/chats/index.html.erb.tt
211
- - lib/generators/lex_llm/chat_ui/templates/tailwind/views/chats/new.html.erb.tt
212
- - lib/generators/lex_llm/chat_ui/templates/tailwind/views/chats/show.html.erb.tt
213
- - lib/generators/lex_llm/chat_ui/templates/tailwind/views/messages/_assistant.html.erb.tt
214
- - lib/generators/lex_llm/chat_ui/templates/tailwind/views/messages/_content.html.erb.tt
215
- - lib/generators/lex_llm/chat_ui/templates/tailwind/views/messages/_error.html.erb.tt
216
- - lib/generators/lex_llm/chat_ui/templates/tailwind/views/messages/_form.html.erb.tt
217
- - lib/generators/lex_llm/chat_ui/templates/tailwind/views/messages/_system.html.erb.tt
218
- - lib/generators/lex_llm/chat_ui/templates/tailwind/views/messages/_tool.html.erb.tt
219
- - lib/generators/lex_llm/chat_ui/templates/tailwind/views/messages/_tool_calls.html.erb.tt
220
- - lib/generators/lex_llm/chat_ui/templates/tailwind/views/messages/_user.html.erb.tt
221
- - lib/generators/lex_llm/chat_ui/templates/tailwind/views/messages/tool_calls/_default.html.erb.tt
222
- - lib/generators/lex_llm/chat_ui/templates/tailwind/views/messages/tool_results/_default.html.erb.tt
223
- - lib/generators/lex_llm/chat_ui/templates/tailwind/views/models/_model.html.erb.tt
224
- - lib/generators/lex_llm/chat_ui/templates/tailwind/views/models/index.html.erb.tt
225
- - lib/generators/lex_llm/chat_ui/templates/tailwind/views/models/show.html.erb.tt
226
- - lib/generators/lex_llm/chat_ui/templates/views/chats/_chat.html.erb.tt
227
- - lib/generators/lex_llm/chat_ui/templates/views/chats/_form.html.erb.tt
228
- - lib/generators/lex_llm/chat_ui/templates/views/chats/index.html.erb.tt
229
- - lib/generators/lex_llm/chat_ui/templates/views/chats/new.html.erb.tt
230
- - lib/generators/lex_llm/chat_ui/templates/views/chats/show.html.erb.tt
231
- - lib/generators/lex_llm/chat_ui/templates/views/messages/_assistant.html.erb.tt
232
- - lib/generators/lex_llm/chat_ui/templates/views/messages/_content.html.erb.tt
233
- - lib/generators/lex_llm/chat_ui/templates/views/messages/_error.html.erb.tt
234
- - lib/generators/lex_llm/chat_ui/templates/views/messages/_form.html.erb.tt
235
- - lib/generators/lex_llm/chat_ui/templates/views/messages/_system.html.erb.tt
236
- - lib/generators/lex_llm/chat_ui/templates/views/messages/_tool.html.erb.tt
237
- - lib/generators/lex_llm/chat_ui/templates/views/messages/_tool_calls.html.erb.tt
238
- - lib/generators/lex_llm/chat_ui/templates/views/messages/_user.html.erb.tt
239
- - lib/generators/lex_llm/chat_ui/templates/views/messages/create.turbo_stream.erb.tt
240
- - lib/generators/lex_llm/chat_ui/templates/views/messages/tool_calls/_default.html.erb.tt
241
- - lib/generators/lex_llm/chat_ui/templates/views/messages/tool_results/_default.html.erb.tt
242
- - lib/generators/lex_llm/chat_ui/templates/views/models/_model.html.erb.tt
243
- - lib/generators/lex_llm/chat_ui/templates/views/models/index.html.erb.tt
244
- - lib/generators/lex_llm/chat_ui/templates/views/models/show.html.erb.tt
245
- - lib/generators/lex_llm/generator_helpers.rb
246
- - lib/generators/lex_llm/install/install_generator.rb
247
- - lib/generators/lex_llm/install/templates/add_references_to_chats_tool_calls_and_messages_migration.rb.tt
248
- - lib/generators/lex_llm/install/templates/chat_model.rb.tt
249
- - lib/generators/lex_llm/install/templates/create_chats_migration.rb.tt
250
- - lib/generators/lex_llm/install/templates/create_messages_migration.rb.tt
251
- - lib/generators/lex_llm/install/templates/create_models_migration.rb.tt
252
- - lib/generators/lex_llm/install/templates/create_tool_calls_migration.rb.tt
253
- - lib/generators/lex_llm/install/templates/initializer.rb.tt
254
- - lib/generators/lex_llm/install/templates/message_model.rb.tt
255
- - lib/generators/lex_llm/install/templates/model_model.rb.tt
256
- - lib/generators/lex_llm/install/templates/tool_call_model.rb.tt
257
- - lib/generators/lex_llm/schema/schema_generator.rb
258
- - lib/generators/lex_llm/schema/templates/schema.rb.tt
259
- - lib/generators/lex_llm/tool/templates/tool.rb.tt
260
- - lib/generators/lex_llm/tool/templates/tool_call.html.erb.tt
261
- - lib/generators/lex_llm/tool/templates/tool_result.html.erb.tt
262
- - lib/generators/lex_llm/tool/tool_generator.rb
263
- - lib/generators/lex_llm/upgrade_to_v1_10/templates/add_v1_10_message_columns.rb.tt
264
- - lib/generators/lex_llm/upgrade_to_v1_10/upgrade_to_v1_10_generator.rb
265
- - lib/generators/lex_llm/upgrade_to_v1_14/templates/add_v1_14_tool_call_columns.rb.tt
266
- - lib/generators/lex_llm/upgrade_to_v1_14/upgrade_to_v1_14_generator.rb
267
- - lib/generators/lex_llm/upgrade_to_v1_7/templates/migration.rb.tt
268
- - lib/generators/lex_llm/upgrade_to_v1_7/upgrade_to_v1_7_generator.rb
269
- - lib/generators/lex_llm/upgrade_to_v1_9/templates/add_v1_9_message_columns.rb.tt
270
- - lib/generators/lex_llm/upgrade_to_v1_9/upgrade_to_v1_9_generator.rb
271
199
  - lib/legion/extensions/llm.rb
200
+ - lib/legion/extensions/llm/agent.rb
201
+ - lib/legion/extensions/llm/aliases.json
202
+ - lib/legion/extensions/llm/aliases.rb
203
+ - lib/legion/extensions/llm/attachment.rb
204
+ - lib/legion/extensions/llm/chat.rb
205
+ - lib/legion/extensions/llm/chunk.rb
206
+ - lib/legion/extensions/llm/configuration.rb
207
+ - lib/legion/extensions/llm/connection.rb
208
+ - lib/legion/extensions/llm/content.rb
209
+ - lib/legion/extensions/llm/context.rb
210
+ - lib/legion/extensions/llm/embedding.rb
211
+ - lib/legion/extensions/llm/error.rb
212
+ - lib/legion/extensions/llm/image.rb
213
+ - lib/legion/extensions/llm/message.rb
214
+ - lib/legion/extensions/llm/mime_type.rb
215
+ - lib/legion/extensions/llm/model.rb
216
+ - lib/legion/extensions/llm/model/info.rb
217
+ - lib/legion/extensions/llm/model/modalities.rb
218
+ - lib/legion/extensions/llm/model/pricing.rb
219
+ - lib/legion/extensions/llm/model/pricing_category.rb
220
+ - lib/legion/extensions/llm/model/pricing_tier.rb
221
+ - lib/legion/extensions/llm/models.json
222
+ - lib/legion/extensions/llm/models.rb
223
+ - lib/legion/extensions/llm/models_schema.json
224
+ - lib/legion/extensions/llm/moderation.rb
225
+ - lib/legion/extensions/llm/provider.rb
226
+ - lib/legion/extensions/llm/provider/open_ai_compatible.rb
272
227
  - lib/legion/extensions/llm/provider_settings.rb
228
+ - lib/legion/extensions/llm/routing.rb
229
+ - lib/legion/extensions/llm/routing/lane_key.rb
230
+ - lib/legion/extensions/llm/routing/model_offering.rb
231
+ - lib/legion/extensions/llm/stream_accumulator.rb
232
+ - lib/legion/extensions/llm/streaming.rb
233
+ - lib/legion/extensions/llm/thinking.rb
234
+ - lib/legion/extensions/llm/tokens.rb
235
+ - lib/legion/extensions/llm/tool.rb
236
+ - lib/legion/extensions/llm/tool_call.rb
237
+ - lib/legion/extensions/llm/transcription.rb
273
238
  - lib/legion/extensions/llm/transport/fleet_lane.rb
274
- - lib/lex_llm.rb
275
- - lib/lex_llm/active_record/acts_as.rb
276
- - lib/lex_llm/active_record/acts_as_legacy.rb
277
- - lib/lex_llm/active_record/chat_methods.rb
278
- - lib/lex_llm/active_record/message_methods.rb
279
- - lib/lex_llm/active_record/model_methods.rb
280
- - lib/lex_llm/active_record/payload_helpers.rb
281
- - lib/lex_llm/active_record/tool_call_methods.rb
282
- - lib/lex_llm/agent.rb
283
- - lib/lex_llm/aliases.json
284
- - lib/lex_llm/aliases.rb
285
- - lib/lex_llm/attachment.rb
286
- - lib/lex_llm/chat.rb
287
- - lib/lex_llm/chunk.rb
288
- - lib/lex_llm/configuration.rb
289
- - lib/lex_llm/connection.rb
290
- - lib/lex_llm/content.rb
291
- - lib/lex_llm/context.rb
292
- - lib/lex_llm/embedding.rb
293
- - lib/lex_llm/error.rb
294
- - lib/lex_llm/image.rb
295
- - lib/lex_llm/message.rb
296
- - lib/lex_llm/mime_type.rb
297
- - lib/lex_llm/model.rb
298
- - lib/lex_llm/model/info.rb
299
- - lib/lex_llm/model/modalities.rb
300
- - lib/lex_llm/model/pricing.rb
301
- - lib/lex_llm/model/pricing_category.rb
302
- - lib/lex_llm/model/pricing_tier.rb
303
- - lib/lex_llm/models.json
304
- - lib/lex_llm/models.rb
305
- - lib/lex_llm/models_schema.json
306
- - lib/lex_llm/moderation.rb
307
- - lib/lex_llm/provider.rb
308
- - lib/lex_llm/provider/open_ai_compatible.rb
309
- - lib/lex_llm/railtie.rb
310
- - lib/lex_llm/routing.rb
311
- - lib/lex_llm/routing/lane_key.rb
312
- - lib/lex_llm/routing/model_offering.rb
313
- - lib/lex_llm/stream_accumulator.rb
314
- - lib/lex_llm/streaming.rb
315
- - lib/lex_llm/thinking.rb
316
- - lib/lex_llm/tokens.rb
317
- - lib/lex_llm/tool.rb
318
- - lib/lex_llm/tool_call.rb
319
- - lib/lex_llm/transcription.rb
320
- - lib/lex_llm/utils.rb
321
- - lib/lex_llm/version.rb
322
- - lib/tasks/lex_llm.rake
239
+ - lib/legion/extensions/llm/utils.rb
240
+ - lib/legion/extensions/llm/version.rb
323
241
  homepage: https://github.com/LegionIO/lex-llm
324
242
  licenses:
325
243
  - MIT
@@ -1,36 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'rails/generators'
4
-
5
- module LexLLM
6
- module Generators
7
- # Generator for LexLLM agent classes and prompt files.
8
- class AgentGenerator < Rails::Generators::NamedBase
9
- source_root File.expand_path('templates', __dir__)
10
-
11
- namespace 'lex_llm:agent'
12
-
13
- desc 'Creates a LexLLM agent class and default instructions prompt'
14
-
15
- def create_agent_file
16
- template 'agent.rb.tt', File.join('app/agents', class_path, "#{agent_file_name}.rb")
17
- end
18
-
19
- def create_prompt_file
20
- empty_directory File.join('app/prompts', class_path, agent_file_name)
21
- template 'instructions.txt.erb.tt',
22
- File.join('app/prompts', class_path, agent_file_name, 'instructions.txt.erb')
23
- end
24
-
25
- private
26
-
27
- def agent_class_name
28
- class_name.end_with?('Agent') ? class_name : "#{class_name}Agent"
29
- end
30
-
31
- def agent_file_name
32
- agent_class_name.demodulize.underscore
33
- end
34
- end
35
- end
36
- end
@@ -1,6 +0,0 @@
1
- class <%= agent_class_name %> < LexLLM::Agent
2
- # Change `Chat` to your app's chat model for Rails persistence.
3
- # Remove this line to skip persistence and use plain LexLLM chats.
4
- chat_model Chat
5
- instructions
6
- end
@@ -1,256 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'rails/generators'
4
- require_relative '../generator_helpers'
5
-
6
- module LexLLM
7
- module Generators
8
- # Generates a simple chat UI scaffold for LexLLM
9
- class ChatUIGenerator < Rails::Generators::Base
10
- include LexLLM::Generators::GeneratorHelpers
11
-
12
- source_root File.expand_path('templates', __dir__)
13
-
14
- namespace 'lex_llm:chat_ui'
15
-
16
- argument :model_mappings, type: :array, default: [], banner: 'chat:ChatName message:MessageName ...'
17
- class_option :ui, type: :string, default: 'auto', enum: %w[scaffold tailwind auto],
18
- desc: 'UI template style (scaffold, tailwind, auto)'
19
-
20
- desc 'Creates a chat UI scaffold with Turbo streaming\n' \
21
- 'Usage: bin/rails g lex_llm:chat_ui [chat:ChatName] [message:MessageName] ...'
22
-
23
- def check_model_exists
24
- model_path = "app/models/#{message_model_name.underscore}.rb"
25
- return if File.exist?(model_path)
26
-
27
- # Build the argument string for the install/upgrade commands
28
- args = []
29
- args << "chat:#{chat_model_name}" if chat_model_name != 'Chat'
30
- args << "message:#{message_model_name}" if message_model_name != 'Message'
31
- args << "model:#{model_model_name}" if model_model_name != 'Model'
32
- args << "tool_call:#{tool_call_model_name}" if tool_call_model_name != 'ToolCall'
33
- arg_string = args.any? ? " #{args.join(' ')}" : ''
34
-
35
- raise Thor::Error, <<~ERROR
36
- Model file not found: #{model_path}
37
-
38
- Please run the install generator first:
39
- bin/rails generate lex_llm:install#{arg_string}
40
-
41
- Or if upgrading from <= 1.6.x, run the upgrade generator:
42
- bin/rails generate lex_llm:upgrade_to_v1_7#{arg_string}
43
- ERROR
44
- end
45
-
46
- def create_views
47
- # Design contract:
48
- # - `scaffold` should stay close to Rails scaffold ERB output.
49
- # - `tailwind` should stay close to tailwindcss-rails scaffold output.
50
- # - Only small chat-specific affordances should be layered on top.
51
- # For namespaced models, use the proper Rails convention path
52
- chat_view_path = chat_model_name.underscore.pluralize
53
- message_view_path = message_model_name.underscore.pluralize
54
- model_view_path = model_model_name.underscore.pluralize
55
-
56
- # Chat views
57
- template ui_template('views/chats/index.html.erb'), "app/views/#{chat_view_path}/index.html.erb"
58
- template ui_template('views/chats/new.html.erb'), "app/views/#{chat_view_path}/new.html.erb"
59
- template ui_template('views/chats/show.html.erb'), "app/views/#{chat_view_path}/show.html.erb"
60
- template ui_template('views/chats/_chat.html.erb'),
61
- "app/views/#{chat_view_path}/_#{chat_model_name.demodulize.underscore}.html.erb"
62
- template ui_template('views/chats/_form.html.erb'), "app/views/#{chat_view_path}/_form.html.erb"
63
-
64
- # Message views
65
- template ui_template('views/messages/_assistant.html.erb'), "app/views/#{message_view_path}/_assistant.html.erb"
66
- template ui_template('views/messages/_user.html.erb'), "app/views/#{message_view_path}/_user.html.erb"
67
- template ui_template('views/messages/_system.html.erb'), "app/views/#{message_view_path}/_system.html.erb"
68
- template ui_template('views/messages/_tool.html.erb'), "app/views/#{message_view_path}/_tool.html.erb"
69
- template ui_template('views/messages/_error.html.erb'), "app/views/#{message_view_path}/_error.html.erb"
70
- template ui_template('views/messages/_tool_calls.html.erb'),
71
- "app/views/#{message_view_path}/_tool_calls.html.erb"
72
- empty_directory "app/views/#{message_view_path}/tool_calls"
73
- template ui_template('views/messages/tool_calls/_default.html.erb'),
74
- "app/views/#{message_view_path}/tool_calls/_default.html.erb"
75
- empty_directory "app/views/#{message_view_path}/tool_results"
76
- template ui_template('views/messages/tool_results/_default.html.erb'),
77
- "app/views/#{message_view_path}/tool_results/_default.html.erb"
78
- template ui_template('views/messages/create.turbo_stream.erb'),
79
- "app/views/#{message_view_path}/create.turbo_stream.erb"
80
- template ui_template('views/messages/_content.html.erb'), "app/views/#{message_view_path}/_content.html.erb"
81
- template ui_template('views/messages/_form.html.erb'), "app/views/#{message_view_path}/_form.html.erb"
82
-
83
- # Model views
84
- template ui_template('views/models/index.html.erb'), "app/views/#{model_view_path}/index.html.erb"
85
- template ui_template('views/models/show.html.erb'), "app/views/#{model_view_path}/show.html.erb"
86
- template ui_template('views/models/_model.html.erb'),
87
- "app/views/#{model_view_path}/_#{model_model_name.demodulize.underscore}.html.erb"
88
- end
89
-
90
- def create_controllers
91
- # For namespaced models, use the proper Rails convention path
92
- chat_controller_path = chat_model_name.underscore.pluralize
93
- message_controller_path = message_model_name.underscore.pluralize
94
- model_controller_path = model_model_name.underscore.pluralize
95
-
96
- template 'controllers/chats_controller.rb', "app/controllers/#{chat_controller_path}_controller.rb"
97
- template 'controllers/messages_controller.rb', "app/controllers/#{message_controller_path}_controller.rb"
98
- template 'controllers/models_controller.rb', "app/controllers/#{model_controller_path}_controller.rb"
99
- end
100
-
101
- def create_jobs
102
- template 'jobs/chat_response_job.rb', "app/jobs/#{variable_name_for(chat_model_name)}_response_job.rb"
103
- end
104
-
105
- def create_helpers
106
- template 'helpers/messages_helper.rb', "app/helpers/#{message_model_name.underscore.pluralize}_helper.rb"
107
- end
108
-
109
- def add_available_chat_models_to_application_controller
110
- path = 'app/controllers/application_controller.rb'
111
- return unless File.exist?(path)
112
-
113
- application_controller = File.read(path)
114
- return if application_controller.include?('def available_chat_models')
115
-
116
- inject_into_file path, <<-RUBY, before: /^end\s*\z/
117
- private
118
-
119
- def available_chat_models
120
- LexLLM.models.chat_models.all
121
- .sort_by { |model| [ model.provider.to_s, model.name.to_s ] }
122
- end
123
- RUBY
124
- end
125
-
126
- def add_routes
127
- # For namespaced models, use Rails convention with namespace blocks
128
- if chat_model_name.include?('::')
129
- namespace = chat_model_name.deconstantize.underscore
130
- chat_resource = chat_model_name.demodulize.underscore.pluralize
131
- message_resource = message_model_name.demodulize.underscore.pluralize
132
- model_resource = model_model_name.demodulize.underscore.pluralize
133
-
134
- routes_content = <<~ROUTES.strip
135
- namespace :#{namespace} do
136
- resources :#{model_resource}, only: [ :index, :show ] do
137
- collection do
138
- post :refresh
139
- end
140
- end
141
- resources :#{chat_resource} do
142
- resources :#{message_resource}, only: [ :create ]
143
- end
144
- end
145
- ROUTES
146
- route routes_content
147
- else
148
- model_routes = <<~ROUTES.strip
149
- resources :#{model_table_name}, only: [ :index, :show ] do
150
- collection do
151
- post :refresh
152
- end
153
- end
154
- ROUTES
155
- route model_routes
156
- chat_routes = <<~ROUTES.strip
157
- resources :#{chat_table_name} do
158
- resources :#{message_table_name}, only: [ :create ]
159
- end
160
- ROUTES
161
- route chat_routes
162
- end
163
- end
164
-
165
- def add_broadcasting_to_message_model
166
- msg_var = variable_name_for(message_model_name)
167
- chat_var = variable_name_for(chat_model_name)
168
- msg_path = message_model_name.underscore
169
-
170
- # For namespaced models, we need the association name which might be different
171
- # e.g., for LLM::Message, the chat association might be :llm_chat
172
- chat_association = chat_table_name.singularize
173
-
174
- broadcasting_callbacks = <<-RUBY
175
-
176
- broadcasts_to ->(#{msg_var}) { "#{chat_var}_\#{#{msg_var}.#{chat_association}_id}" }, inserts_by: :append
177
-
178
- def broadcast_append_chunk(content)
179
- broadcast_append_to "#{chat_var}_\#{#{chat_association}_id}",
180
- target: "#{msg_var}_\#{id}_content",
181
- content: ERB::Util.html_escape(content.to_s)
182
- end
183
- RUBY
184
-
185
- inject_into_file "app/models/#{msg_path}.rb", before: "end\n" do
186
- broadcasting_callbacks
187
- end
188
- rescue Errno::ENOENT
189
- say "#{message_model_name} model not found. Add broadcasting code to your model.", :yellow
190
- say broadcasting_callbacks, :yellow
191
- end
192
-
193
- def display_post_install_message
194
- return unless behavior == :invoke
195
-
196
- # Show the correct URL based on whether models are namespaced
197
- url_path = if chat_model_name.include?('::')
198
- chat_model_name.underscore.pluralize
199
- else
200
- chat_table_name
201
- end
202
-
203
- say "\n ✅ Chat UI installed!", :green
204
- say " UI template: #{ui_variant}", :cyan
205
- say "\n Start your server and visit http://localhost:3000/#{url_path}", :cyan
206
- say "\n"
207
- end
208
-
209
- private
210
-
211
- def ui_variant
212
- @ui_variant ||= case options[:ui]
213
- when 'tailwind'
214
- :tailwind
215
- when 'auto'
216
- tailwind_available? ? :tailwind : :scaffold
217
- else
218
- :scaffold
219
- end
220
- end
221
-
222
- def ui_template(template_path)
223
- return template_path unless ui_variant == :tailwind
224
-
225
- # Keep Tailwind templates as a separate set so we can mirror Rails/Tailwind
226
- # scaffold conventions without complicating scaffold templates.
227
- tailwind_template = "tailwind/#{template_path}"
228
- File.exist?(File.join(self.class.source_root, "#{tailwind_template}.tt")) ? tailwind_template : template_path
229
- end
230
-
231
- def message_helper_module_name
232
- if message_model_name.include?('::')
233
- "#{message_model_name.deconstantize}::#{message_model_name.demodulize.pluralize}Helper"
234
- else
235
- "#{message_model_name.pluralize}Helper"
236
- end
237
- end
238
-
239
- def tailwind_available?
240
- Rails.root.join('app/assets/tailwind/application.css').exist? ||
241
- Rails.root.join('config/tailwind.config.js').exist? ||
242
- gem_in_bundle?('tailwindcss-rails') ||
243
- gem_in_bundle?('cssbundling-rails')
244
- end
245
-
246
- def gem_in_bundle?(gem_name)
247
- gemfile_path = Rails.root.join('Gemfile')
248
- lockfile_path = Rails.root.join('Gemfile.lock')
249
-
250
- [gemfile_path, lockfile_path].any? do |path|
251
- path.exist? && path.read.include?(gem_name)
252
- end
253
- end
254
- end
255
- end
256
- end
@@ -1,38 +0,0 @@
1
- class <%= chat_controller_class_name %> < ApplicationController
2
- before_action :set_<%= chat_variable_name %>, only: [ :show, :destroy ]
3
-
4
- def index
5
- @<%= chat_table_name %> = <%= chat_model_name %>.order(created_at: :desc)
6
- end
7
-
8
- def new
9
- @<%= chat_variable_name %> = <%= chat_model_name %>.new
10
- @selected_model = params[:model]
11
- @chat_models = available_chat_models
12
- end
13
-
14
- def create
15
- prompt = params.dig(:<%= chat_variable_name %>, :prompt)
16
- if prompt.present?
17
- @<%= chat_variable_name %> = <%= chat_model_name %>.create!(model: params.dig(:<%= chat_variable_name %>, :model).presence)
18
- <%= chat_job_class_name %>.perform_later(@<%= chat_variable_name %>.id, prompt)
19
-
20
- redirect_to @<%= chat_variable_name %>, notice: "<%= chat_model_name.humanize %> was successfully created."
21
- end
22
- end
23
-
24
- def show
25
- @<%= message_variable_name %> = @<%= chat_variable_name %>.<%= message_table_name %>.build
26
- end
27
-
28
- def destroy
29
- @<%= chat_variable_name %>.destroy!
30
- redirect_to <%= chat_table_name %>_path, notice: "<%= chat_model_name.humanize %> was successfully destroyed.", status: :see_other
31
- end
32
-
33
- private
34
-
35
- def set_<%= chat_variable_name %>
36
- @<%= chat_variable_name %> = <%= chat_model_name %>.find(params[:id])
37
- end
38
- end
@@ -1,21 +0,0 @@
1
- class <%= message_controller_class_name %> < ApplicationController
2
- before_action :set_<%= chat_variable_name %>
3
-
4
- def create
5
- content = params.dig(:<%= message_variable_name %>, :content)
6
- if content.present?
7
- <%= chat_job_class_name %>.perform_later(@<%= chat_variable_name %>.id, content)
8
-
9
- respond_to do |format|
10
- format.turbo_stream
11
- format.html { redirect_to @<%= chat_variable_name %> }
12
- end
13
- end
14
- end
15
-
16
- private
17
-
18
- def set_<%= chat_variable_name %>
19
- @<%= chat_variable_name %> = <%= chat_model_name %>.find(params[:<%= chat_model_name.include?('::') ? chat_model_name.demodulize.underscore : chat_variable_name %>_id])
20
- end
21
- end
@@ -1,14 +0,0 @@
1
- class <%= model_controller_class_name %> < ApplicationController
2
- def index
3
- @<%= model_table_name %> = available_chat_models
4
- end
5
-
6
- def show
7
- @<%= model_variable_name %> = <%= model_model_name %>.find(params[:id])
8
- end
9
-
10
- def refresh
11
- <%= model_model_name %>.refresh!
12
- redirect_to <%= model_table_name %>_path, notice: "<%= model_model_name.pluralize %> refreshed successfully"
13
- end
14
- end
@@ -1,25 +0,0 @@
1
- module <%= message_helper_module_name %>
2
- def default_model_display_name
3
- "Default: #{LexLLM.models.find(LexLLM.config.default_model).label}"
4
- end
5
-
6
- def tool_result_partial(message)
7
- name = message.respond_to?(:parent_tool_call) ? message.parent_tool_call&.name.to_s : ""
8
- partial_for(prefix: "<%= message_model_name.underscore.pluralize %>/tool_results", name: name)
9
- end
10
-
11
- def tool_call_partial(tool_call)
12
- partial_for(prefix: "<%= message_model_name.underscore.pluralize %>/tool_calls", name: tool_call.name.to_s)
13
- end
14
-
15
- private
16
-
17
- def partial_for(prefix:, name:)
18
- normalized = name.to_s.underscore.tr("-", "_")
19
- if normalized.present? && lookup_context.exists?(normalized, [ prefix ], true)
20
- "#{prefix}/#{normalized}"
21
- else
22
- "#{prefix}/default"
23
- end
24
- end
25
- end
@@ -1,12 +0,0 @@
1
- class <%= chat_job_class_name %> < ApplicationJob
2
- def perform(<%= chat_variable_name %>_id, content)
3
- <%= chat_variable_name %> = <%= chat_model_name %>.find(<%= chat_variable_name %>_id)
4
-
5
- <%= chat_variable_name %>.ask(content) do |chunk|
6
- if chunk.content && !chunk.content.empty?
7
- <%= message_variable_name %> = <%= chat_variable_name %>.<%= message_table_name %>.last
8
- <%= message_variable_name %>.broadcast_append_chunk(chunk.content)
9
- end
10
- end
11
- end
12
- end
@@ -1,16 +0,0 @@
1
- <div id="<%%= dom_id <%= chat_model_name.demodulize.underscore %> %>" class="w-full sm:w-auto my-5 space-y-3">
2
- <div>
3
- <strong class="block font-medium mb-1">Model:</strong>
4
- <%%= <%= chat_model_name.demodulize.underscore %>.<%= model_table_name.singularize %>&.label || default_model_display_name %>
5
- </div>
6
-
7
- <div>
8
- <strong class="block font-medium mb-1">Messages:</strong>
9
- <%%= <%= chat_model_name.demodulize.underscore %>.<%= message_table_name %>.count %>
10
- </div>
11
-
12
- <div>
13
- <strong class="block font-medium mb-1">Created:</strong>
14
- <%%= <%= chat_model_name.demodulize.underscore %>.created_at.strftime("%B %d, %Y at %I:%M %p") %>
15
- </div>
16
- </div>
@@ -1,31 +0,0 @@
1
- <%%= form_with(model: <%= chat_variable_name %>, url: <%= chat_table_name %>_path, class: "contents") do |form| %>
2
- <%% if <%= chat_variable_name %>.errors.any? %>
3
- <div id="error_explanation" class="bg-red-50 text-red-500 px-3 py-2 font-medium rounded-md mt-3">
4
- <h2><%%= pluralize(<%= chat_variable_name %>.errors.count, "error") %> prohibited this <%= chat_table_name.singularize.humanize.downcase %> from being saved:</h2>
5
-
6
- <ul class="list-disc ml-6">
7
- <%% <%= chat_variable_name %>.errors.each do |error| %>
8
- <li><%%= error.full_message %></li>
9
- <%% end %>
10
- </ul>
11
- </div>
12
- <%% end %>
13
-
14
- <div class="my-5">
15
- <%%= form.label :model, "Select AI model:" %>
16
- <%%= form.select :model,
17
- options_for_select(@chat_models.map { |model| [model.label, model.id] }.unshift([default_model_display_name, nil]), @selected_model),
18
- {},
19
- class: ["block shadow-sm rounded-md border px-3 py-2 mt-2 w-full", {"border-gray-400 focus:outline-blue-600": <%= chat_variable_name %>.errors[:model].none?, "border-red-400 focus:outline-red-600": <%= chat_variable_name %>.errors[:model].any?}] %>
20
- </div>
21
-
22
- <div class="my-5">
23
- <%%= form.label :prompt, "Prompt" %>
24
- <%%= form.text_area :prompt, rows: 4, placeholder: "What would you like to discuss?", autofocus: true,
25
- class: ["block shadow-sm rounded-md border px-3 py-2 mt-2 w-full", {"border-gray-400 focus:outline-blue-600": <%= chat_variable_name %>.errors[:prompt].none?, "border-red-400 focus:outline-red-600": <%= chat_variable_name %>.errors[:prompt].any?}] %>
26
- </div>
27
-
28
- <div class="inline">
29
- <%%= form.submit "Start new <%= chat_table_name.singularize.humanize.downcase %>", class: "w-full sm:w-auto rounded-md px-3.5 py-2.5 bg-blue-600 hover:bg-blue-500 text-white inline-block font-medium cursor-pointer" %>
30
- </div>
31
- <%% end %>