Liyonghui commited on
Commit
6359174
1 Parent(s): 3614521

Upload 3 files

Browse files
Files changed (3) hide show
  1. app.py +63 -0
  2. logo.jpg +0 -0
  3. requirements.txt +2 -0
app.py ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import requests
2
+ import streamlit as st
3
+ from streamlit_chat import message
4
+ def getAnsByMiniMax(t):
5
+ group_id="1692579910526670"
6
+ api_key="eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJOYW1lIjoibXkiLCJTdWJqZWN0SUQiOiIxNjkyNTc5OTEwMTMyODYyIiwiUGhvbmUiOiIiLCJHcm91cElEIjoiMTY5MjU3OTkxMDUyNjY3MCIsIlBhZ2VOYW1lIjoiIiwiTWFpbCI6IjE4NzAzODAzODQzQDE2My5jb20iLCJDcmVhdGVUaW1lIjoiMjAyMy0wOC0yMSAwOToxMzoyMiIsImlzcyI6Im1pbmltYXgifQ.q8bEzUnNqxc_cabZ7A6OsS2UvQH9Cditkitrxp8yG-izKd0_uXOyJwM1ZmCPvIXdrlTjzu0O05ImvxEqDJ7D065BYKfMbtYrmlHoDUjJSZlpUbSiJSDChoFG5OytB1ZRnzPhwVeAZZYH5EdJwd-F0p_8OvDIyV3eTInprV1XzEKH_MLfgXwXtgVYE5Wxggw1WWZF_eUPcP-XWgEhuREPN82okQQE2fEWSVz9S_xMQeSRBEQbS86pZHoFkZyOQbOrI1yn0dsAb6a2SKkDjJqc-T2_I_Smc1GUvJZ7RSN640o9GiVbrsvwbXjryBhHnCJwlJpVTf5jyZEf8TT_w2C_dg"
7
+
8
+ url = "https://api.minimax.chat/v1/text/chatcompletion_pro?GroupId=" + group_id
9
+
10
+ payload = {
11
+ "bot_setting": [
12
+ {
13
+ "bot_name": "MM智能助理",
14
+ "content": "MM智能助理是一款由MiniMax自研的,没有调用其他产品的接口的大型语言模型。MiniMax是一家中国科技公司,一直致力于进行大模型相关的研究。",
15
+ }
16
+ ],
17
+ "messages": [{"sender_type": "USER", "sender_name": "小明", "text": t}],
18
+ "reply_constraints": {"sender_type": "BOT", "sender_name": "MM智能助理"},
19
+ "model": "abab5.5-chat",
20
+ "tokens_to_generate": 1034,
21
+ "temperature": 0.01,
22
+ "top_p": 0.95,
23
+ }
24
+ headers = {"Content-Type": "application/json", "Authorization": "Bearer " + api_key}
25
+
26
+ response = requests.request("POST", url, headers=headers, json=payload)
27
+ res = response.json()
28
+ res = res["reply"]
29
+ return res
30
+
31
+ if 'prompts' not in st.session_state:
32
+ st.session_state['prompts'] = []
33
+
34
+ if 'generated' not in st.session_state:
35
+ st.session_state['generated'] = []
36
+
37
+ if 'past' not in st.session_state:
38
+ st.session_state['past'] = []
39
+
40
+ def end_click():
41
+ st.session_state['prompts'] = []
42
+ st.session_state['past'] = []
43
+ st.session_state['generated'] = []
44
+ st.session_state['user'] = ""
45
+ def chat_click():
46
+ if st.session_state['user'] != '':
47
+ chat_input = st.session_state['user']
48
+ output = getAnsByMiniMax(chat_input)
49
+ st.session_state['past'].append(chat_input)
50
+ st.session_state['generated'].append(output)
51
+ st.session_state['prompts'].append(output)
52
+ st.session_state['user'] = ""
53
+ st.image("./logo.jpg", use_column_width='auto')
54
+ st.title("珠宝贝专属聊天机器人")
55
+
56
+ user_input = st.text_input("输入:", key="user")
57
+ chat_button = st.button("发送", on_click=chat_click)
58
+ end_button = st.button("新聊天", on_click=end_click)
59
+
60
+ if st.session_state['generated']:
61
+ for i in range(0, len(st.session_state['generated']), 1):
62
+ message(st.session_state['past'][i], is_user=True)
63
+ message(st.session_state['generated'][i], key=str(i))
logo.jpg ADDED
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ requests
2
+ streamlit_chat