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

Commit 3c02ed1

Browse files
committed
Make behavior more robust by echoing artifact.
This means that the architect model can provide better instructions.
1 parent b976d5a commit 3c02ed1

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

lib/ai_bot/personas/persona.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ def craft_prompt(context, llm: nil)
201201

202202
prompt.max_pixels = self.class.vision_max_pixels if self.class.vision_enabled
203203
prompt.tools = available_tools.map(&:signature) if available_tools
204-
204+
available_tools.each { |tool| tool.inject_prompt(prompt: prompt, context: context) }
205205
prompt
206206
end
207207

lib/ai_bot/tools/create_artifact.rb

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,41 @@ def self.signature
6666
}
6767
end
6868

69+
def self.inject_prompt(prompt:, context:)
70+
# we inject the current artifact content into the last user message
71+
if topic_id = context[:topic_id]
72+
posts = Post.where(topic_id: topic_id)
73+
artifact = AiArtifact.order("id desc").where(post: posts).first
74+
if artifact
75+
latest_version = artifact.versions.order(version_number: :desc).first
76+
current = latest_version || artifact
77+
78+
artifact_source = <<~MSG
79+
Current Artifact:
80+
81+
### HTML
82+
```html
83+
#{current.html}
84+
```
85+
86+
### CSS
87+
```css
88+
#{current.css}
89+
```
90+
91+
### JavaScript
92+
```javascript
93+
#{current.js}
94+
```
95+
96+
MSG
97+
98+
last_message = prompt.messages.last
99+
last_message[:content] = "#{artifact_source}\n\n#{last_message[:content]}"
100+
end
101+
end
102+
end
103+
69104
def invoke
70105
yield parameters[:name] || "New Artifact"
71106

lib/ai_bot/tools/tool.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ def custom_system_message
4242
def allow_partial_tool_calls?
4343
false
4444
end
45+
46+
def inject_prompt(prompt:, context:)
47+
end
4548
end
4649

4750
attr_accessor :custom_raw, :parameters

0 commit comments

Comments
 (0)