-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #344 from nkwangleiGIT/main
Fix some issues and add streamlit app samples
- Loading branch information
Showing
13 changed files
with
120 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
Here are some web based applications built using streamlit. | ||
|
||
### Simple chat application - English teacher | ||
|
||
* application definition: refer to config/samples/app_llmchain_englishteacher.yaml | ||
* application code: chat_app_english_teacher.py | ||
* application name: base-chat-english-teacher | ||
* application namespace: kubeagi-system | ||
|
||
## Chat application using private knowledgebase | ||
|
||
* application definition: refer to config/samples/app_retrievalqachain_knowledgebase.yaml | ||
* application code: chat_using_private_knowledgebase.py | ||
* application name: base-chat-with-knowledgebase | ||
* application namespace: kubeagi-system | ||
|
||
You should update the application definition/code/name/namespace as your requirement, and then just copy the python script to the streamlit application folder and play with it. |
36 changes: 36 additions & 0 deletions
36
examples/app-ui-using-streamlit/chat_app_english_teacher.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import streamlit as st | ||
import requests | ||
import os | ||
|
||
with st.sidebar: | ||
server_url = st.text_input("服务 graphql-server/go-server 请求地址, 默认为 http://arcadia-apiserver.kubeagi-system.svc:8081/chat", key="url") | ||
conversion_id = st.text_input("如果想继续的话,可以输入上次的conversion_id,留空表示新对话", key="conversion_id") | ||
|
||
st.title("💬 Chat with kubeagi") | ||
st.caption("🚀 A chatbot powered by Kubeagi") | ||
if "messages" not in st.session_state: | ||
st.session_state["messages"] = [{"role": "assistant", "content": "Hello, I am English Teacher 🧑🏫 From KubeAGI 🤖"}] | ||
|
||
if "first_show" not in st.session_state: | ||
st.session_state["first_show"] = True | ||
|
||
if not server_url: | ||
server_url = "http://arcadia-apiserver.kubeagi-system.svc:8081/chat" | ||
|
||
for msg in st.session_state.messages: | ||
st.chat_message(msg["role"]).write(msg["content"]) | ||
|
||
if prompt := st.chat_input(): | ||
response = requests.post(server_url, | ||
json={"query":prompt,"response_mode":"blocking","conversion_id":conversion_id,"app_name":"base-chat-english-teacher", "app_namespace":"kubeagi-system"}) | ||
st.session_state.messages.append({"role": "user", "content": prompt}) | ||
st.chat_message("user").write(prompt) | ||
msg = response.json()["message"] | ||
conversion_id = response.json()["conversion_id"] | ||
|
||
if st.session_state["first_show"]: | ||
st.info('这次聊天的 conversion_id 是: '+conversion_id, icon="ℹ️") | ||
st.session_state["first_show"] = False | ||
|
||
st.session_state.messages.append({"role": "assistant", "content": msg}) | ||
st.chat_message("assistant").write(msg) |
36 changes: 36 additions & 0 deletions
36
examples/app-ui-using-streamlit/chat_using_private_knowledgebase.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import streamlit as st | ||
import requests | ||
import os | ||
|
||
with st.sidebar: | ||
server_url = st.text_input("服务 graphql-server/go-server 请求地址, 默认为 http://arcadia-apiserver.kubeagi-system.svc:8081/chat", key="url") | ||
conversion_id = st.text_input("如果想继续的话,可以输入上次的conversion_id,留空表示新对话", key="conversion_id") | ||
|
||
st.title("💬 Chat with kubeagi") | ||
st.caption("🚀 A chatbot powered by Kubeagi") | ||
if "messages" not in st.session_state: | ||
st.session_state["messages"] = [{"role": "assistant", "content": "您好,您可以问我任何关于考勤制度的问题,很高心为您服务。"}] | ||
|
||
if "first_show" not in st.session_state: | ||
st.session_state["first_show"] = True | ||
|
||
if not server_url: | ||
server_url = "http://arcadia-apiserver.kubeagi-system.svc:8081/chat" | ||
|
||
for msg in st.session_state.messages: | ||
st.chat_message(msg["role"]).write(msg["content"]) | ||
|
||
if prompt := st.chat_input(): | ||
response = requests.post(server_url, | ||
json={"query":prompt,"response_mode":"blocking","conversion_id":conversion_id,"app_name":"chat-with-kaoqin-kb", "app_namespace":"kubeagi-system"}) | ||
st.session_state.messages.append({"role": "user", "content": prompt}) | ||
st.chat_message("user").write(prompt) | ||
msg = response.json()["message"] | ||
conversion_id = response.json()["conversion_id"] | ||
|
||
if st.session_state["first_show"]: | ||
st.info('这次聊天的 conversion_id 是: '+conversion_id, icon="ℹ️") | ||
st.session_state["first_show"] = False | ||
|
||
st.session_state.messages.append({"role": "assistant", "content": msg}) | ||
st.chat_message("assistant").write(msg) |
1 change: 1 addition & 0 deletions
1
examples/app-ui-using-streamlit/private_knowledgebase_app_arch.drawio
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<mxfile host="1a7opr5i78445fv9uniqtn2ked5k1puu433g449aabv2089soieg" modified="2023-12-10T09:53:04.364Z" agent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_1) AppleWebKit/537.36 (KHTML, like Gecko) Code/1.84.2 Chrome/114.0.5735.289 Electron/25.9.2 Safari/537.36" etag="X-SmwY8ZSnY9aGVOz68e" version="12.2.4" pages="1"><diagram id="Zn4FlFsgrMPtoJGrlCBt" name="kao-qa-app-flow">7Vpfl5soHP00eUyOgibmsclMu3t2enbbeWjnkShRdoh4kEySfvqiQpTgZNLG/JvdeZgjP0Dh3uvlB6YHp4v1J46y5DOLMO0BJ1r34F0PgMAN5P8isKkCHoBVIOYkqkJuHXgkP7AKOiq6JBHOjYaCMSpIZgZDlqY4FEYMcc5WZrM5o+ZTMxRjK/AYImpHv5FIJGpaYFTH/8AkTvST3eG4qlkg3VjNJE9QxFaNELzvwSlnTFRXi/UU0wI7jUvV7+MrtduBcZyKQzoUdeU4xEZPDkdyrqrIuEhYzFJE7+vohLNlGuHiDo4s1W0eGMtk0JXBf7EQG0UcWgomQ4lYUFWL10R8b1w/Fbca+Kp0t1Z3LgsbXUgF33xvFhq9imLdrSzpfjYiCqScLXmo5gwUPwLxGKtmSpIFHI1+CsZPmC2wfIxswDFFgryY0kBKYfG23bbrP4zIkQBHvQwuVFLY6KE45i2qcapeNZXyojGMOlQS3E72+Fa4PoizM/EDwRv8VJrpgh81oxdEl2q0GWeLTPRTaaA9MKQSjMmMy6u4vEI57ocJEv0VEUn/OWUrWqBRxC2mTR5XCRH4MUMllivp0SZnr+L/grnA671w61p3B7aRKq9qw3R1LGmYpee8zpCB7R4g9bMvo/Ra3U+NmiOU7p1H6R7wTcp2qehO6Z6ldEoXSuYXFi4MTOG6ni3c8al0670r3fpn0u0Inku3vqVbLjsTLOV1Her1weXUO7TAkYsTSa8DGLibZvkt61EbMkEHyAS38lrXSXadVz81645JstXuqJljd76yHey0o5Y3eW7RJMUlTFQ5zskPNCsbFDPPClcpB+JPev6djCBK4lQGQokF5jJQiJTIzeMHVbEgUVRSTNEM0wkKn+OS7CmjjJfPhfPyrxXY4BXlb3e7anC95oay7Y3oOwNn7CscfteCdRM2n+f4WHe1OXl4+HxjeS8cgYGZRrU4sOv4ttH4XSQQ8H+nKULAtprOk5GDObHXxRuxGq2mjr1Gr8BX5DxaMA2O/tK2MpG28lVneTfmRt7YzHravMhvSXo68aKxhanEDC2KWaazPNvO8EJm9Ttnj+4Jzh71YXjTrIaXMiu9fdhDWmleb/B4jWam5Xi0mTkDMBwOr8m9Aos0ZViIfvkwLTZhN+Zb/s4hDBj6tnG5JzKull3+cYDMCaUNkUY+DiJPxnPB2TNu1ARgBqWyurF+dzTYPc/bpqaG/9so6thRKNrZfKcozoMQh2EbirPA9/y99vsLKOoX/TIY2i/2DWIIwe6WCATwfBjaacifabYUdu5BKcly/DaIKM+qj8pzsi6At9Fzyr+OrPDt7yjeiQ70oJ0M/L0UN4Sd55i6g8MzgufbKP0Ht+JQ/z6j+WVdwXv+9FaP5rYN1V7aGxZ7BkuF9onGHRLIQtLeBZiwpCzFOxiq0OF7gTZ+TAY7AByMd9NRe/1q8xHQhY/YedT7Btsbwd10oVXdJwPcTrreOeDAzHEhPCPYdna2f2PqoCyjEitBWHoAJXOWCr3ktvw47thsbNRium0fEeGvQyWL9c8Aq0OB+reU8P4n</diagram></mxfile> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters