Skip to content

Commit

Permalink
Merge pull request #344 from nkwangleiGIT/main
Browse files Browse the repository at this point in the history
Fix some issues and add streamlit app samples
  • Loading branch information
nkwangleiGIT authored Dec 10, 2023
2 parents 873f519 + 957b966 commit a956e47
Show file tree
Hide file tree
Showing 13 changed files with 120 additions and 9 deletions.
2 changes: 1 addition & 1 deletion config/samples/app_retrievalqachain_knowledgebase.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ spec:
nextNodeName: ["chain-node"]
- name: chain-node
displayName: "RetrievalQA chain"
description: "chain是langchain的核心概念,RetrievalQAChain用于从retriver中提取信息,供llm调用"
description: "chain是langchain的核心概念,RetrievalQAChain用于从 retriever 中提取信息,供llm调用"
ref:
apiGroup: chain.arcadia.kubeagi.k8s.com.cn
kind: RetrievalQAChain
Expand Down
2 changes: 1 addition & 1 deletion deploy/charts/arcadia/templates/dataprocess.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ spec:
value: {{ .Values.dataprocess.env.minio.apiURL }}
- name: MINIO_SECURE
value: "{{ .Values.dataprocess.env.minio.secure }}"
- name: ZHIPU_AI_KEY
- name: ZHIPUAI_API_KEY
value: "to-be-replaced"
- name: KNOWLEDGE_CHUNK_SIZE
value: "{{ .Values.dataprocess.env.knowledge.chunkSize }}"
Expand Down
2 changes: 1 addition & 1 deletion deploy/charts/arcadia/templates/post-models.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: arcadia.kubeagi.k8s.com.cn/v1alpha1
kind: Model
metadata:
name: baichuan2-7b
name: baichuan2-7b-chat
annotations:
"helm.sh/hook": post-install
"helm.sh/hook-weight": "1"
Expand Down
10 changes: 10 additions & 0 deletions deploy/charts/arcadia/templates/rbac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -549,3 +549,13 @@ rules:
- get
- patch
- update
- apiGroups:
- networking.k8s.io
resources:
- ingresses
verbs:
- get
- list
- watch
- create
- delete
5 changes: 4 additions & 1 deletion deploy/charts/arcadia/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ dataprocess:
port: 28888
env:
minio:
apiURL: http://arcadia-minio:9000
secure: "False"
apiURL: arcadia-minio:9000
knowledge:
chunkSize: 500
chunkOverlap: 50
Expand All @@ -134,5 +135,7 @@ chromadb:
image:
repository: ghcr.io/amikos-tech/chromadb-chart/chroma
chromadb:
auth:
enabled: false
dataVolumeStorageClass: "openebs-hostpath"
apiVersion: "0.4.14"
17 changes: 17 additions & 0 deletions examples/app-ui-using-streamlit/README.md
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 examples/app-ui-using-streamlit/chat_app_english_teacher.py
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)
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)
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>
4 changes: 3 additions & 1 deletion pkg/application/retriever/knowledgebaseretriever.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,10 @@ func NewKnowledgeBaseRetriever(ctx context.Context, baseNode base.BaseNode, cli
if err != nil {
return nil, err
}
// TODO: allow to configure how many relevant documents should be returned
// and the threshold of similiarity(0-1), use 5 and 0.3 by default for now
return &KnowledgeBaseRetriever{
vectorstores.ToRetriever(s, 5),
vectorstores.ToRetriever(s, 5, vectorstores.WithScoreThreshold(0.3)),
baseNode,
}, nil
default:
Expand Down
6 changes: 4 additions & 2 deletions pkg/llms/zhipuai/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,13 @@ type Prompt struct {
}

func DefaultModelParams() ModelParams {
// TODO: should allow user to configure the temperature and top_p of inference
// use 0.8 and 0.7 for now
return ModelParams{
Model: ZhiPuAILite,
Method: ZhiPuAIInvoke,
Temperature: 0.95, // zhipuai official
TopP: 0.7, // zhipuai official
Temperature: 0.8, // more accurate?
TopP: 0.7,
Prompt: []Prompt{},
}
}
Expand Down
5 changes: 4 additions & 1 deletion tests/deploy-values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ dataprocess:
port: 28888
env:
minio:
apiURL: http://arcadia-minio:9000
secure: "False"
apiURL: arcadia-minio:9000
knowledge:
chunkSize: 500
chunkOverlap: 50
Expand All @@ -135,5 +136,7 @@ chromadb:
image:
repository: ghcr.io/amikos-tech/chromadb-chart/chroma
chromadb:
auth:
enabled: false
dataVolumeStorageClass: "standard"
apiVersion: "0.4.14"
3 changes: 2 additions & 1 deletion tests/example-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ else
exit 1
fi

info "8 check app work fine"
info "8 validation:simple app of llmchain can work normally"
kubectl apply -f config/samples/app_llmchain_englishteacher.yaml
waitCRDStatusReady "Application" "arcadia" "base-chat-english-teacher"
kubectl port-forward svc/arcadia-apiserver -n arcadia 8081:8081 >/dev/null 2>&1 &
Expand All @@ -258,6 +258,7 @@ info "port-forward portal in pid: $portal_pid"
sleep 3
curl -XPOST http://127.0.0.1:8081/chat --data '{"query":"hi, how are you?","response_mode":"blocking","conversion_id":"","app_name":"base-chat-english-teacher", "app_namespace":"arcadia"}' | jq -e '.message'

info "9 validation:QA app using knowledgebase can work normally"
kubectl apply -f config/samples/app_retrievalqachain_knowledgebase.yaml
waitCRDStatusReady "Application" "arcadia" "base-chat-with-knowledgebase"
sleep 3
Expand Down

0 comments on commit a956e47

Please sign in to comment.