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

Commit e70c3f0

Browse files
committed
wire multiple strategies
1 parent 91b6a0e commit e70c3f0

File tree

3 files changed

+27
-12
lines changed

3 files changed

+27
-12
lines changed

app/models/ai_persona.rb

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,6 @@ def class_instance
129129
tool_details
130130
]
131131

132-
persona_class = DiscourseAi::AiBot::Personas::Persona.system_personas_by_id[self.id]
133-
134132
instance_attributes = {}
135133
attributes.each do |attr|
136134
value = self.read_attribute(attr)
@@ -139,14 +137,6 @@ def class_instance
139137

140138
instance_attributes[:username] = user&.username_lower
141139

142-
if persona_class
143-
instance_attributes.each do |key, value|
144-
# description/name are localized
145-
persona_class.define_singleton_method(key) { value } if key != :description && key != :name
146-
end
147-
return persona_class
148-
end
149-
150140
options = {}
151141
force_tool_use = []
152142

@@ -179,6 +169,16 @@ def class_instance
179169
klass
180170
end
181171

172+
persona_class = DiscourseAi::AiBot::Personas::Persona.system_personas_by_id[self.id]
173+
if persona_class
174+
instance_attributes.each do |key, value|
175+
# description/name are localized
176+
persona_class.define_singleton_method(key) { value } if key != :description && key != :name
177+
end
178+
persona_class.define_method(:options) { options }
179+
return persona_class
180+
end
181+
182182
ai_persona_id = self.id
183183

184184
Class.new(DiscourseAi::AiBot::Personas::Persona) do

config/locales/server.en.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ en:
306306
description: "Language model to use for artifact edits"
307307
update_algorithm:
308308
name: "Update Algorithm"
309-
description: "Algorithm used for artifact updates (full vs diff)"
309+
description: "Ask LLM to fully replace, or use diff to update"
310310
google:
311311
base_query:
312312
name: "Base Search Query"

lib/ai_bot/tools/update_artifact.rb

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,24 @@ def invoke
6565
return error_response("Attempting to update an artifact you are not allowed to")
6666
end
6767

68+
llm =
69+
(
70+
options[:editor_llm].present? &&
71+
LlmModel.find_by(id: options[:editor_llm].to_i)&.to_llm
72+
) || self.llm
73+
74+
strategy =
75+
(
76+
if options[:update_algorithm] == "diff"
77+
ArtifactUpdateStrategies::Diff
78+
else
79+
ArtifactUpdateStrategies::Full
80+
end
81+
)
82+
6883
begin
6984
new_version =
70-
ArtifactUpdateStrategies::Full.new(
85+
strategy.new(
7186
llm: llm,
7287
post: post,
7388
user: post.user,

0 commit comments

Comments
 (0)