feat: support user to cumtom prompt for current conversation - #1214
feat: support user to cumtom prompt for current conversation#1214dalton-ly wants to merge 1 commit into
Conversation
0a933b9 to
dbe6584
Compare
|
9fc23a0 to
df7a530
Compare
|
0608 fix bug and rebased |
| "strings" | ||
|
|
||
| "github.com/beego/beego" | ||
| "github.com/beego/beego/logs" |
| // @Param prompt body string true "The custom prompt" | ||
| // @Success 200 {object} controllers.Response "Success" | ||
| // @router /set-chat-prompt [post] | ||
| func (c *ApiController) SetChatPrompt() { |
| )} | ||
| </Card> | ||
|
|
||
| <Modal |
There was a problem hiding this comment.
The new modal UI should be in a new JS file
|
|
||
| return ( | ||
| <div style={{position: "absolute", bottom: 0, left: 0, right: 0, padding: "16px 24px", zIndex: 1}}> | ||
| <div style={{ |
There was a problem hiding this comment.
Don't change original code format
|
|
||
| promptToUse := store.Prompt | ||
| if chat.CustomPrompt != "" { | ||
| promptToUse = chat.CustomPrompt |
There was a problem hiding this comment.
Don't replace store.Prompt, append is better
| // @Param id query string true "The id of chat" | ||
| // @Success 200 {object} controllers.Response "Success" | ||
| // @router /get-chat-prompt [get] | ||
| func (c *ApiController) GetChatPrompt() { |
| }).then(res => res.json()); | ||
| } | ||
|
|
||
| export function getChatPrompt(id) { |
| }).then(res => res.json()); | ||
| } | ||
|
|
||
| export function setChatPrompt(id, prompt) { |
7f76b33 to
7fda78d
Compare
There was a problem hiding this comment.
Pull Request Overview
This PR adds support for setting a custom prompt on a per-conversation basis in both the front-end chat UI and the back-end message handling.
- Introduces a
PromptModalcomponent for editing prompts. - Extends
ChatInput,ChatBox, andChatPageto manage prompt state, persist it inlocalStorage, and pass it through the UI. - Updates the Go backend (
message.goandmessage_answer.go) to store and append the custom prompt when querying the model.
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| web/src/chat/PromptModal.js | New modal allowing users to view/edit prompts |
| web/src/chat/ChatInput.js | Adds a settings button for opening the prompt modal |
| web/src/ChatPage.js | Manages chatPrompt state, load/save from localStorage |
| web/src/ChatBox.js | Integrates PromptModal, passes prompt through props |
| object/message.go | Adds CustomPrompt field to Message struct |
| controllers/message_answer.go | Appends CustomPrompt to the model query string |
Comments suppressed due to low confidence (1)
web/src/ChatPage.js:169
- The new
updateChatPromptmethod (and relatedloadChatPrompt) aren’t covered by existing tests. Consider adding unit or integration tests to verify prompt persistence and retrieval.
updateChatPrompt = (prompt) => {
| AgentMessages: messages, | ||
| } | ||
| modelResult, err = model.QueryTextWithTools(modelProviderObj, question, writer, history, store.Prompt, knowledge, agentInfo) | ||
| modelResult, err = model.QueryTextWithTools(modelProviderObj, question, writer, history, store.Prompt+customPrompt, knowledge, agentInfo) |
There was a problem hiding this comment.
Concatenating store.Prompt and customPrompt without a separator can merge sentences. Consider inserting a newline or space between them, e.g., store.Prompt + "\n" + customPrompt.
| padding: "20px 24px", | ||
| }} | ||
| > | ||
| <textarea |
There was a problem hiding this comment.
The <textarea> lacks an explicit aria-label or associated <label>. Adding one will improve screen reader support.
| value={editingPrompt} | ||
| onChange={(e) => setEditingPrompt(e.target.value)} | ||
| placeholder={i18next.t("chat:Set a custom prompt for this conversation")} | ||
| style={{ |
There was a problem hiding this comment.
[nitpick] This component has a large inline style block. Extracting styles into a CSS module or styled-component could improve readability and reuse.
|
@dark-Qy @IsAurora6 plz review |
| ErrorText string `xorm:"mediumtext" json:"errorText"` | ||
| FileName string `xorm:"varchar(100)" json:"fileName"` | ||
| Comment string `xorm:"mediumtext" json:"comment"` | ||
| CustomPrompt string `xorm:"mediumtext" json:"customPrompt"` |
There was a problem hiding this comment.
Why use message object to store custom prompt instead of chat object?
|
|
||
| this.setState({chatPrompt: prompt}); | ||
|
|
||
| const chatId = this.state.chat.owner + "/" + this.state.chat.name; |
There was a problem hiding this comment.
Since message object is used, why does the frontend use chatPrompt_${chatId} as key to store prompt in localStorage - this is inconsistent
| this.setState({chatPrompt: prompt}); | ||
|
|
||
| const chatId = this.state.chat.owner + "/" + this.state.chat.name; | ||
| localStorage.setItem(`chatPrompt_${chatId}`, prompt); |
There was a problem hiding this comment.
Why use localStorage in frontend? Data will be lost when switching devices
b0af169 to
1beb94c
Compare
4f4385d to
c484e8b
Compare
16e8006 to
57f99cb
Compare
8be752c to
1ba19a5
Compare
0c1315e to
41f7b24
Compare
1c86c55 to
bfd6eca
Compare
0d5f732 to
5b80c35
Compare
008ecd9 to
ed8fc87
Compare
937a559 to
2f734e0
Compare
36714c2 to
6369263
Compare
b8bb53e to
dc5af21
Compare


support #979