Skip to content
This repository was archived by the owner on Jul 22, 2025. It is now read-only.

Commit 2ed1bec

Browse files
committed
lint
1 parent 3add2a9 commit 2ed1bec

File tree

11 files changed

+32
-22
lines changed

11 files changed

+32
-22
lines changed

app/controllers/discourse_ai/ai_bot/artifacts_controller.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
module DiscourseAi
44
module AiBot
55
class ArtifactsController < ApplicationController
6-
76
requires_plugin DiscourseAi::PLUGIN_NAME
87

98
skip_before_action :preload_json, :check_xhr, only: %i[show]

db/migrate/20241104053017_add_ai_artifacts.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ def change
55
t.integer :user_id, null: false
66
t.integer :post_id, null: false
77
t.string :name, null: false, limit: 255
8-
t.string :html, limit: 65535 # ~64KB limit
9-
t.string :css, limit: 65535 # ~64KB limit
10-
t.string :js, limit: 65535 # ~64KB limit
11-
t.jsonb :metadata # For any additional properties
8+
t.string :html, limit: 65_535 # ~64KB limit
9+
t.string :css, limit: 65_535 # ~64KB limit
10+
t.string :js, limit: 65_535 # ~64KB limit
11+
t.jsonb :metadata # For any additional properties
1212

1313
t.timestamps
1414
end

lib/ai_bot/personas/persona.rb

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,13 @@ def craft_prompt(context, llm: nil)
202202

203203
def find_tool(partial, bot_user:, llm:, context:, existing_tools: [])
204204
return nil if !partial.is_a?(DiscourseAi::Completions::ToolCall)
205-
tool_instance(partial, bot_user: bot_user, llm: llm, context: context, existing_tools: existing_tools)
205+
tool_instance(
206+
partial,
207+
bot_user: bot_user,
208+
llm: llm,
209+
context: context,
210+
existing_tools: existing_tools,
211+
)
206212
end
207213

208214
def allow_partial_tool_calls?
@@ -245,7 +251,8 @@ def tool_instance(tool_call, bot_user:, llm:, context:, existing_tools:)
245251
arguments[name.to_sym] = value if value
246252
end
247253

248-
tool_instance = existing_tools.find { |t| t.name == function_name && t.tool_call_id == function_id }
254+
tool_instance =
255+
existing_tools.find { |t| t.name == function_name && t.tool_call_id == function_id }
249256

250257
if tool_instance
251258
tool_instance.parameters = arguments

lib/ai_bot/playground.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -464,10 +464,10 @@ def reply_to(post, custom_instructions: nil, &blk)
464464
end
465465

466466
if post_streamer
467-
post_streamer.run_later {
467+
post_streamer.run_later do
468468
Discourse.redis.expire(redis_stream_key, 60)
469469
publish_update(reply_post, { raw: raw })
470-
}
470+
end
471471
end
472472
end
473473

lib/ai_bot/tools/create_artifact.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ def update_custom_html(artifact = nil)
9292
css = parameters[:css].to_s
9393
js = parameters[:js].to_s
9494

95-
artifact_div = "<div class=\"ai-artifact\" data-ai-artifact-id=#{artifact.id}></div>" if artifact
95+
artifact_div =
96+
"<div class=\"ai-artifact\" data-ai-artifact-id=#{artifact.id}></div>" if artifact
9697

9798
content = []
9899

lib/completions/endpoints/base.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,10 @@ def perform_completion!(
9696
raise CompletionFailed, response.body
9797
end
9898

99-
xml_tool_processor = XmlToolProcessor.new(partial_tool_calls: partial_tool_calls) if xml_tools_enabled? &&
100-
dialect.prompt.has_tools?
99+
xml_tool_processor =
100+
XmlToolProcessor.new(
101+
partial_tool_calls: partial_tool_calls,
102+
) if xml_tools_enabled? && dialect.prompt.has_tools?
101103

102104
to_strip = xml_tags_to_strip(dialect)
103105
xml_stripper =

plugin.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ module ::DiscourseAi
5050
require_relative "lib/engine"
5151

5252
after_initialize do
53-
5453
if defined?(Rack::MiniProfiler)
5554
Rack::MiniProfiler.config.skip_paths << "/discourse-ai/ai-bot/artifacts"
5655
end

spec/lib/completions/endpoints/anthropic_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@
186186

187187
expected_body = {
188188
model: "claude-3-opus-20240229",
189-
max_tokens: 3000,
189+
max_tokens: 4096,
190190
messages: [{ role: "user", content: "user1: hello" }],
191191
system: "You are hello bot",
192192
stream: true,
@@ -278,7 +278,7 @@
278278

279279
request_body = {
280280
model: "claude-3-opus-20240229",
281-
max_tokens: 3000,
281+
max_tokens: 4096,
282282
messages: [
283283
{
284284
role: "user",
@@ -376,7 +376,7 @@
376376

377377
expected_body = {
378378
model: "claude-3-opus-20240229",
379-
max_tokens: 3000,
379+
max_tokens: 4096,
380380
messages: [{ role: "user", content: "user1: hello" }],
381381
system: "You are hello bot",
382382
}

spec/lib/completions/endpoints/open_ai_spec.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,6 @@ def request_body(prompt, stream: false, tool_call: false)
572572
end
573573

574574
it "properly handles multiple params in partial tool calls" do
575-
576575
# this is not working and it is driving me nuts so I will use a sledghammer
577576
# text = plugin_file_from_fixtures("openai_artifact_call.txt", "bot")
578577

@@ -591,7 +590,10 @@ def request_body(prompt, stream: false, tool_call: false)
591590

592591
expect(partials.compact.length).to eq(128)
593592

594-
params = partials.map { |p| p.parameters if p.is_a?(DiscourseAi::Completions::ToolCall) && p.partial? }.compact
593+
params =
594+
partials
595+
.map { |p| p.parameters if p.is_a?(DiscourseAi::Completions::ToolCall) && p.partial? }
596+
.compact
595597

596598
lengths = {}
597599
params.each do |p|

spec/lib/modules/ai_bot/playground_spec.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -791,11 +791,12 @@
791791
expect(done_signal.data[:cooked]).to eq(reply.cooked)
792792

793793
expect(messages.first.data[:raw]).to eq("")
794-
messages[1..-1].each_with_index do |m, idx|
795-
expect(m.data[:raw]).to eq(expected_bot_response[0..idx])
796-
end
797794

798795
expect(reply.cooked).to eq(PrettyText.cook(expected_bot_response))
796+
797+
messages[1..-1].each do |m|
798+
expect(expected_bot_response.start_with?(m.data[:raw])).to eq(true)
799+
end
799800
end
800801
end
801802

0 commit comments

Comments
 (0)