Skip to content

Commit

Permalink
Make behavior more robust by echoing artifact.
Browse files Browse the repository at this point in the history
This means that the architect model can provide better instructions.
  • Loading branch information
SamSaffron committed Jan 28, 2025
1 parent b976d5a commit 3c02ed1
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/ai_bot/personas/persona.rb
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def craft_prompt(context, llm: nil)

prompt.max_pixels = self.class.vision_max_pixels if self.class.vision_enabled
prompt.tools = available_tools.map(&:signature) if available_tools

available_tools.each { |tool| tool.inject_prompt(prompt: prompt, context: context) }
prompt
end

Expand Down
35 changes: 35 additions & 0 deletions lib/ai_bot/tools/create_artifact.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,41 @@ def self.signature
}
end

def self.inject_prompt(prompt:, context:)
# we inject the current artifact content into the last user message
if topic_id = context[:topic_id]
posts = Post.where(topic_id: topic_id)
artifact = AiArtifact.order("id desc").where(post: posts).first
if artifact
latest_version = artifact.versions.order(version_number: :desc).first
current = latest_version || artifact

artifact_source = <<~MSG
Current Artifact:
### HTML
```html
#{current.html}
```
### CSS
```css
#{current.css}
```
### JavaScript
```javascript
#{current.js}
```
MSG

last_message = prompt.messages.last
last_message[:content] = "#{artifact_source}\n\n#{last_message[:content]}"
end
end
end

def invoke
yield parameters[:name] || "New Artifact"

Expand Down
3 changes: 3 additions & 0 deletions lib/ai_bot/tools/tool.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ def custom_system_message
def allow_partial_tool_calls?
false
end

def inject_prompt(prompt:, context:)
end
end

attr_accessor :custom_raw, :parameters
Expand Down

0 comments on commit 3c02ed1

Please sign in to comment.