Skip to content

feat: support user to cumtom prompt for current conversation - #1214

Open
dalton-ly wants to merge 1 commit into
the-open-agent:masterfrom
dalton-ly:add_prompt
Open

feat: support user to cumtom prompt for current conversation#1214
dalton-ly wants to merge 1 commit into
the-open-agent:masterfrom
dalton-ly:add_prompt

Conversation

@dalton-ly

Copy link
Copy Markdown
Contributor

support #979

@hsluoyz

hsluoyz commented May 26, 2025

Copy link
Copy Markdown
Contributor

@dalton-ly

  1. Should not contain the previous merged PR as below, needs to rebase
    image

  2. Provide a demo video

@dalton-ly
dalton-ly force-pushed the add_prompt branch 2 times, most recently from 0a933b9 to dbe6584 Compare May 26, 2025 14:21
@dalton-ly

dalton-ly commented May 26, 2025

Copy link
Copy Markdown
Contributor Author
  • rebased onto latest master
  • Demo in attachment

prompt_set_demo.zip
@hsluoyz

@dalton-ly
dalton-ly force-pushed the add_prompt branch 2 times, most recently from 9fc23a0 to df7a530 Compare June 8, 2025 08:48
@dalton-ly

Copy link
Copy Markdown
Contributor Author

0608 fix bug and rebased

Comment thread controllers/message_answer.go Outdated
"strings"

"github.com/beego/beego"
"github.com/beego/beego/logs"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't use Beego logs

Comment thread controllers/message_answer.go Outdated
// @Param prompt body string true "The custom prompt"
// @Success 200 {object} controllers.Response "Success"
// @router /set-chat-prompt [post]
func (c *ApiController) SetChatPrompt() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't need to add new API, see how this UI widget works:

image

Comment thread web/src/ChatBox.js Outdated
)}
</Card>

<Modal

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new modal UI should be in a new JS file

Comment thread web/src/chat/ChatInput.js Outdated

return (
<div style={{position: "absolute", bottom: 0, left: 0, right: 0, padding: "16px 24px", zIndex: 1}}>
<div style={{

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't change original code format

Comment thread controllers/message_answer.go Outdated

promptToUse := store.Prompt
if chat.CustomPrompt != "" {
promptToUse = chat.CustomPrompt

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't replace store.Prompt, append is better

Comment thread controllers/message_answer.go Outdated
// @Param id query string true "The id of chat"
// @Success 200 {object} controllers.Response "Success"
// @router /get-chat-prompt [get]
func (c *ApiController) GetChatPrompt() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't need to add new API

Comment thread web/src/backend/MessageBackend.js Outdated
}).then(res => res.json());
}

export function getChatPrompt(id) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't need to add new API

Comment thread web/src/backend/MessageBackend.js Outdated
}).then(res => res.json());
}

export function setChatPrompt(id, prompt) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't need to add new API

@dalton-ly
dalton-ly force-pushed the add_prompt branch 2 times, most recently from 7f76b33 to 7fda78d Compare June 22, 2025 15:18
@dalton-ly

Copy link
Copy Markdown
Contributor Author

@dalton-ly
dalton-ly requested a review from hsluoyz July 4, 2025 02:45
@hsluoyz
hsluoyz requested a review from Copilot July 8, 2025 00:39

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 PromptModal component for editing prompts.
  • Extends ChatInput, ChatBox, and ChatPage to manage prompt state, persist it in localStorage, and pass it through the UI.
  • Updates the Go backend (message.go and message_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 updateChatPrompt method (and related loadChatPrompt) 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)

Copilot AI Jul 8, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
padding: "20px 24px",
}}
>
<textarea

Copilot AI Jul 8, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The <textarea> lacks an explicit aria-label or associated <label>. Adding one will improve screen reader support.

Copilot uses AI. Check for mistakes.
value={editingPrompt}
onChange={(e) => setEditingPrompt(e.target.value)}
placeholder={i18next.t("chat:Set a custom prompt for this conversation")}
style={{

Copilot AI Jul 8, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] This component has a large inline style block. Extracting styles into a CSS module or styled-component could improve readability and reuse.

Copilot uses AI. Check for mistakes.
@hsluoyz

hsluoyz commented Jul 8, 2025

Copy link
Copy Markdown
Contributor

@dark-Qy @IsAurora6 plz review

Comment thread object/message.go
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"`

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why use message object to store custom prompt instead of chat object?

Comment thread web/src/ChatPage.js

this.setState({chatPrompt: prompt});

const chatId = this.state.chat.owner + "/" + this.state.chat.name;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since message object is used, why does the frontend use chatPrompt_${chatId} as key to store prompt in localStorage - this is inconsistent

Comment thread web/src/ChatPage.js
this.setState({chatPrompt: prompt});

const chatId = this.state.chat.owner + "/" + this.state.chat.name;
localStorage.setItem(`chatPrompt_${chatId}`, prompt);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why use localStorage in frontend? Data will be lost when switching devices

@hsluoyz
hsluoyz force-pushed the master branch 2 times, most recently from b0af169 to 1beb94c Compare August 2, 2025 02:01
@hsluoyz
hsluoyz force-pushed the master branch 3 times, most recently from 4f4385d to c484e8b Compare October 22, 2025 17:34
@hsluoyz
hsluoyz force-pushed the master branch 2 times, most recently from 16e8006 to 57f99cb Compare November 4, 2025 17:18
@hsluoyz
hsluoyz force-pushed the master branch 8 times, most recently from 8be752c to 1ba19a5 Compare November 8, 2025 17:08
@hsluoyz
hsluoyz force-pushed the master branch 2 times, most recently from 0c1315e to 41f7b24 Compare February 14, 2026 16:41
@hsluoyz
hsluoyz force-pushed the master branch 3 times, most recently from 1c86c55 to bfd6eca Compare May 3, 2026 06:53
@hsluoyz
hsluoyz force-pushed the master branch 2 times, most recently from 0d5f732 to 5b80c35 Compare May 23, 2026 09:17
@hsluoyz
hsluoyz force-pushed the master branch 2 times, most recently from 008ecd9 to ed8fc87 Compare June 3, 2026 08:28
@hsluoyz
hsluoyz force-pushed the master branch 2 times, most recently from 937a559 to 2f734e0 Compare June 12, 2026 15:02
@hsluoyz
hsluoyz force-pushed the master branch 2 times, most recently from 36714c2 to 6369263 Compare June 17, 2026 17:25
@hsluoyz
hsluoyz force-pushed the master branch 2 times, most recently from b8bb53e to dc5af21 Compare June 26, 2026 16:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants