Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

添加Prompt管理 #53

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions examples/webui.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@
"icon": "hdd-stack",
"func": code_page,
},
# "Prompt管理": {
# "icon": "hdd-stack",
# "func": prompt_page,
# },
"Prompt管理": {
"icon": "hdd-stack",
"func": prompt_page,
}
}

with st.sidebar:
Expand Down
15 changes: 14 additions & 1 deletion examples/webui/prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,20 @@
from muagent.service.service_factory import get_kb_details, get_kb_doc_details
from muagent.orm import table_init

from .dialogue import chat_box

def list_to_converted_strings(lst: list) -> str:
converted_list = []
for item in lst:
role = item.get('role')
elements = item.get('elements')
if elements:
markdown_element = elements[0]
markdown_text = markdown_element.text if hasattr(markdown_element, 'text') else str(markdown_element)
# 将角色和文本组合成一个字符串,并添加到转换列表中
converted_list.append(f"{role}: {markdown_text}")
# 将转换后的列表连接成一个字符串,每个元素之间用换行符分隔
return '\n'.join(converted_list)

def prompt_page(api: ApiRequest):
# 判断表是否存在并进行初始化
Expand All @@ -32,7 +45,7 @@ def prompt_page(api: ApiRequest):

export_btn.download_button(
"导出记录",
"测试prompt",
list_to_converted_strings(chat_box.history),
file_name=f"{now:%Y-%m-%d %H.%M}_对话记录.md",
mime="text/markdown",
use_container_width=True,
Expand Down