|
import requests |
|
import streamlit as st |
|
from streamlit_chat import message |
|
def getAnsByMiniMax(t): |
|
group_id="1692579910526670" |
|
api_key="eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJOYW1lIjoibXkiLCJTdWJqZWN0SUQiOiIxNjkyNTc5OTEwMTMyODYyIiwiUGhvbmUiOiIiLCJHcm91cElEIjoiMTY5MjU3OTkxMDUyNjY3MCIsIlBhZ2VOYW1lIjoiIiwiTWFpbCI6IjE4NzAzODAzODQzQDE2My5jb20iLCJDcmVhdGVUaW1lIjoiMjAyMy0wOC0yMSAwOToxMzoyMiIsImlzcyI6Im1pbmltYXgifQ.q8bEzUnNqxc_cabZ7A6OsS2UvQH9Cditkitrxp8yG-izKd0_uXOyJwM1ZmCPvIXdrlTjzu0O05ImvxEqDJ7D065BYKfMbtYrmlHoDUjJSZlpUbSiJSDChoFG5OytB1ZRnzPhwVeAZZYH5EdJwd-F0p_8OvDIyV3eTInprV1XzEKH_MLfgXwXtgVYE5Wxggw1WWZF_eUPcP-XWgEhuREPN82okQQE2fEWSVz9S_xMQeSRBEQbS86pZHoFkZyOQbOrI1yn0dsAb6a2SKkDjJqc-T2_I_Smc1GUvJZ7RSN640o9GiVbrsvwbXjryBhHnCJwlJpVTf5jyZEf8TT_w2C_dg" |
|
|
|
url = "https://api.minimax.chat/v1/text/chatcompletion_pro?GroupId=" + group_id |
|
|
|
payload = { |
|
"bot_setting": [ |
|
{ |
|
"bot_name": "MM智能助理", |
|
"content": "MM智能助理是一款由MiniMax自研的,没有调用其他产品的接口的大型语言模型。MiniMax是一家中国科技公司,一直致力于进行大模型相关的研究。", |
|
} |
|
], |
|
"messages": [{"sender_type": "USER", "sender_name": "小明", "text": t}], |
|
"reply_constraints": {"sender_type": "BOT", "sender_name": "MM智能助理"}, |
|
"model": "abab5.5-chat", |
|
"tokens_to_generate": 1034, |
|
"temperature": 0.01, |
|
"top_p": 0.95, |
|
} |
|
headers = {"Content-Type": "application/json", "Authorization": "Bearer " + api_key} |
|
|
|
response = requests.request("POST", url, headers=headers, json=payload) |
|
res = response.json() |
|
res = res["reply"] |
|
return res |
|
|
|
if 'prompts' not in st.session_state: |
|
st.session_state['prompts'] = [] |
|
|
|
if 'generated' not in st.session_state: |
|
st.session_state['generated'] = [] |
|
|
|
if 'past' not in st.session_state: |
|
st.session_state['past'] = [] |
|
|
|
def end_click(): |
|
st.session_state['prompts'] = [] |
|
st.session_state['past'] = [] |
|
st.session_state['generated'] = [] |
|
st.session_state['user'] = "" |
|
def chat_click(): |
|
if st.session_state['user'] != '': |
|
chat_input = st.session_state['user'] |
|
output = getAnsByMiniMax(chat_input) |
|
st.session_state['past'].append(chat_input) |
|
st.session_state['generated'].append(output) |
|
st.session_state['prompts'].append(output) |
|
st.session_state['user'] = "" |
|
st.image("./logo.jpg", use_column_width='auto') |
|
st.title("珠宝贝专属聊天机器人") |
|
|
|
user_input = st.text_input("输入:", key="user") |
|
chat_button = st.button("发送", on_click=chat_click) |
|
end_button = st.button("新聊天", on_click=end_click) |
|
|
|
if st.session_state['generated']: |
|
for i in range(0, len(st.session_state['generated']), 1): |
|
message(st.session_state['past'][i], is_user=True) |
|
message(st.session_state['generated'][i], key=str(i)) |