Skip to content

Commit

Permalink
Add new application panel and update chatbot command list
Browse files Browse the repository at this point in the history
A new application panel file (01_🎛️应用面板.py) is added which has a list of applications and their relevant information. Changes are made to the chatbot to handle education-related commands more effectively. This includes an update on the chatbot's command list and the addition of a quickly selectable command list in the sidebar in the context of educational applications. The Streamlit learning example has also been renamed.
  • Loading branch information
jamiesun committed Dec 11, 2023
1 parent 9d014f6 commit 166c810
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 9 deletions.
28 changes: 21 additions & 7 deletions apps/chatbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
load_dotenv()


def get_chatbot_page(state_prefix, knowledge_name, sysmsg_func):
def get_chatbot_page(state_prefix, knowledge_name, sysmsg_func, is_edu=False, show_libs=False):
page_state = PageSessionState(state_prefix)
# st.sidebar.markdown("# 💡Python 编程导师")

Expand All @@ -22,6 +22,7 @@ def get_chatbot_page(state_prefix, knowledge_name, sysmsg_func):
page_state.initn_attr("last_user_msg_processed", True)
# 用于标记流式输出是否结束
page_state.initn_attr("streaming_end", True)
page_state.initn_attr("quick_command", "")

def end_chat_streaming():
"""当停止按钮被点击时执行,用于修改处理标志"""
Expand All @@ -33,6 +34,15 @@ def start_chat_streaming():
page_state.streaming_end = False
page_state.last_user_msg_processed = False

def on_input_prompt(iprompt: str):
if iprompt.strip() == "":
return
page_state.chat_prompt = iprompt
start_chat_streaming()
page_state.add_chat_msg("messages", {"role": "user", "content": page_state.chat_prompt})
with st.chat_message("user"):
st.write(page_state.chat_prompt)

for msg in page_state.messages:
with st.chat_message(msg["role"]):
st.write(msg["content"])
Expand All @@ -47,11 +57,15 @@ def clear_chat_history():
st.chat_input("请等待上一条消息处理完毕", disabled=True)
else:
if prompt := st.chat_input("输入你的问题"):
page_state.chat_prompt = prompt
start_chat_streaming()
page_state.add_chat_msg("messages", {"role": "user", "content": page_state.chat_prompt})
with st.chat_message("user"):
st.write(page_state.chat_prompt)
on_input_prompt(prompt)

if is_edu:
qprompt = st.sidebar.selectbox("快速命令列表", ["", "/plan", "/start", "/continue",
"/test choice", "/test program", "/result",
"/help", "/config 中文",
], index=0)
if st.sidebar.button("发送命令"):
on_input_prompt(qprompt)

stop_action = st.sidebar.empty()
if not page_state.streaming_end:
Expand All @@ -65,7 +79,7 @@ def clear_chat_history():
with st.spinner("Thinking..."):
# 检索知识库
kmsg = search_knowledge(knowledge_name, page_state.chat_prompt)
if kmsg != "":
if kmsg != "" and show_libs:
st.expander("📚 知识库检索结果", expanded=False).markdown(kmsg)
sysmsg = sysmsg_func(kmsg)
response = openai_streaming(sysmsg, page_state.messages[-10:])
Expand Down
3 changes: 2 additions & 1 deletion libs/prompts.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,11 @@ def get_codeboy_sysmsg(kmsg: str) -> str:
* Middle School
### Commands
* /test: Test students' knowledge, comprehension, and problem-solving skills.
* /plan <topic>: Create a lesson plan based on the student's needs and preferences.
* /start <lesson>: Start the specified lesson plan.
* /continue: Continue from the previous operation.
* /test <type>: Tests students' knowledge, understanding, and problem-solving skills. choice stands for multiple-choice and program stands for programming.
* /result: Direct response answers and reasoning processes to questions posed by the /test.
* /config setup your configuration .
* /language <lang> Setting the conversation language.
* /help: Respond to the list of commands and their usage descriptions.
Expand Down
77 changes: 77 additions & 0 deletions pages/01_🎛️应用面板.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import streamlit as st
from urllib.parse import quote as urlencode

st.set_page_config(page_title="CoolStudy 应用面板", page_icon="🎛️")

st.sidebar.markdown("# 🎛️ 应用面板")

# List of apps
apps = [
{
"name": "💥 方程式杀手",
"remark": "`一个简单的工具,用于化简和解决方程式`",
"link": urlencode("方程式杀手"),
},
{
"name": "🔬 图像分析",
"remark": "`通过 AI 分析图像中的内容,提供有用的信息`",
"link": urlencode("图像分析"),
},
{
"name": "✨ 智能思维导图",
"remark": "`通过 AI 模型分析,生成智能思维导图`",
"link": urlencode("智能思维导图"),
},
{
"name": "🎙️ 语音转录",
"remark": "`通过 AI 模型识别语音内容,转录文本,并支持合成新语音`",
"link": urlencode("语音转录"),
},
{
"name": "🌐 酷学365",
"remark": "`一个 AI 学习助手, 解答学习上的任何问题`",
"link": urlencode("酷学365"),
},
{
"name": "🐍 Python_编程导师",
"remark": "`一个 Python 学习助手,可以设计学习计划、解答问题`",
"link": urlencode("Python_编程导师"),
},
{
"name": "🎨 图像生成",
"remark": "`通过 AI 模型生成图像,包括人脸、动漫人物、风景等`",
"link": urlencode("图像生成"),
},
{
"name": "🤖 Streamlit_组件学习",
"remark": "`一个 Streamlit 组件学习应用案例`",
"link": urlencode("Streamlit_组件学习"),
},
]

cols = st.columns(3)
# Iterating over the apps to create buttons in the UI
for i, app in enumerate(apps):
# Determine which column to place the app based on index
col = cols[i % 3]
# Create a button for each app in the respective column
with col.expander(app['name'], expanded=True):
st.markdown(app['remark'])
link = app['link']
name = app['name']
link_html = f"""
<a href="{link}" target="_self" style="
text-decoration: none;
color: RoyalBlue;
background-color: Gainsboro;
padding: 7px 14px;
border-radius: 5px;
font-size: 14px;
font-weight: bold;
">
{name}
</a>
"""
st.markdown(link_html, unsafe_allow_html=True)

# st.link_button(app['name'], app['link'])
3 changes: 2 additions & 1 deletion pages/07_🐍Python_编程导师.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
from dotenv import load_dotenv
from apps.chatbot import get_chatbot_page
from libs.prompts import get_codeboy_sysmsg
from libs.session import PageSessionState

sys.path.append(os.path.abspath('..'))
load_dotenv()


st.sidebar.markdown("# 💡Python 编程导师")

get_chatbot_page("codeboy", "codeboy", get_codeboy_sysmsg)
get_chatbot_page("codeboy", "codeboy", get_codeboy_sysmsg, is_edu=True)
File renamed without changes.

0 comments on commit 166c810

Please sign in to comment.