Improve chat (#1084)

* refactor chat prompt

* update style
This commit is contained in:
an-lee
2024-09-19 06:33:25 +08:00
committed by GitHub
parent 5ea8fcb75d
commit 4a31c05433
5 changed files with 18 additions and 4 deletions

View File

@@ -60,8 +60,6 @@ export const NOT_SUPPORT_JSON_FORMAT_MODELS = [
export const CHAT_SYSTEM_PROMPT_TEMPLATE = `You are {name}.
{agent_prompt}
You are chatting in an online chat room.
{agent_chat_prompt}
[Rules must be followed]

View File

@@ -66,6 +66,16 @@ export class ChatMember extends Model<ChatMember> {
})
agent: ChatAgent;
@Column(DataType.VIRTUAL)
get name(): string {
if (this.userType === "User") {
return this.user.name;
} else if (this.userType === "Agent") {
return this.agent.name;
}
return "";
}
@Column(DataType.VIRTUAL)
get user(): {
name: string;

View File

@@ -385,7 +385,7 @@ const ChatUserMessageActions = (props: {
</div>
</CollapsibleTrigger>
<CollapsibleContent>
<div className="p-4 font-serif border-t">
<div className="p-4 font-serif border-t max-h-96 overflow-y-auto">
<MarkdownWrapper className="select-text prose dark:prose-invert">
{refinement}
</MarkdownWrapper>

View File

@@ -203,6 +203,7 @@ export const ChatSessionProvider = ({
const chain = prompt.pipe(llm);
setSubmitting(true);
const lastChatMessage = chatMessages[chatMessages.length - 1];
const reply = await chain.invoke({
name: member.agent.name,
agent_prompt: member.agent.config.prompt || "",
@@ -219,6 +220,7 @@ export const ChatSessionProvider = ({
})
.join("\n"),
history: chatMessages
.slice(0, chatMessages.length - 1)
.map(
(message) =>
`- ${(message.member.user || message.member.agent).name}: ${
@@ -226,7 +228,10 @@ export const ChatSessionProvider = ({
}(${dayjs(message.createdAt).fromNow()})`
)
.join("\n"),
input: chatMessages.length > 0 ? "Continue" : "Start the conversation",
input:
(lastChatMessage
? `${lastChatMessage.member.name}: ${lastChatMessage.content}\n`
: "") + `${member.agent.name}:`,
});
// the reply may contain the member's name like "Agent: xxx". We need to remove it.

View File

@@ -43,6 +43,7 @@ type ChatMemberType = {
introduction?: string;
[key: string]: any;
};
name: string;
agent?: ChatAgentType;
user?: UserType;
};