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

Commit 6c81ca8

Browse files
committed
prompt engineering to better explain storage api
1 parent c2ef8e2 commit 6c81ca8

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

app/controllers/discourse_ai/ai_bot/artifacts_controller.rb

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,18 @@ def prepare_javascript(js)
100100
js
101101
end
102102

103+
def user_data
104+
{
105+
username: current_user ? current_user.username : nil,
106+
user_id: current_user ? current_user.id : nil,
107+
name: current_user ? current_user.name : nil,
108+
}
109+
end
110+
103111
def build_iframe_javascript
104112
<<~JAVASCRIPT
105113
<script>
106-
window._discourse_user_data = {
107-
#{current_user ? "username: #{current_user.username.to_json}" : "username: null"}
108-
};
114+
window._discourse_user_data = #{user_data.to_json};
109115
110116
window.discourseArtifactReady = new Promise(resolve => {
111117
window._resolveArtifactData = resolve;

lib/personas/tools/create_artifact.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,14 @@ def self.storage_api
321321
322322
- avatar_template: string - URL template for user avatars, MUST replace {size} with desired size in pixels (eg: 22)
323323
324+
### User info:
325+
326+
To get current user info:
327+
const initData = await window.discourseArtifactReady;
328+
initData.username; // current username
329+
initData.name; // current user's name
330+
initData.user_id; // current user ID
331+
324332
### Storage Rules:
325333
- Each user can store up to 100 keys per artifact
326334
- Keys are scoped to the current user and artifact

lib/personas/web_artifact_creator.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ def system_prompt
2121
- Write clean, efficient code
2222
- Build progressively (HTML structure → CSS styling → JavaScript interactivity)
2323
- Artifacts run in a sandboxed IFRAME environmment
24-
- Artifacts optionally have support for a Discourse user persistent storage
24+
- Artifacts Discourse persistent storage - requires storage support
25+
- Artifacts have access to current user data (username, name, id) - requires storage support
2526
2627
When creating:
2728
1. Understand the desired user experience

0 commit comments

Comments
 (0)