update
This commit is contained in:
parent
f5a3091964
commit
4e73a8d8b9
15
README.md
15
README.md
@ -189,3 +189,18 @@ pip install openai
|
|||||||
```
|
```
|
||||||
python -m streamlit run ./Yi_Spark.py --theme.base dark --server.port 8501
|
python -m streamlit run ./Yi_Spark.py --theme.base dark --server.port 8501
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### 7. 火山引擎 - Doubao_lite_32k
|
||||||
|
|
||||||
|
豆包大模型 - 火山引擎(有免费额度):https://www.volcengine.com/product/doubao
|
||||||
|
|
||||||
|
需要安装:
|
||||||
|
|
||||||
|
```
|
||||||
|
pip install volcengine-python-sdk
|
||||||
|
```
|
||||||
|
|
||||||
|
运行命令:
|
||||||
|
```
|
||||||
|
python -m streamlit run ./Doubao_lite_32k.py --theme.base dark --server.port 8501
|
||||||
|
```
|
74
模型API - 火山 - Doubao_lite_32k/Doubao_lite_32k.py
Normal file
74
模型API - 火山 - Doubao_lite_32k/Doubao_lite_32k.py
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
"""
|
||||||
|
This code is supported by the website: https://www.guanjihuan.com
|
||||||
|
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/38502
|
||||||
|
"""
|
||||||
|
|
||||||
|
import streamlit as st
|
||||||
|
st.set_page_config(
|
||||||
|
page_title="Chat",
|
||||||
|
layout='wide'
|
||||||
|
)
|
||||||
|
|
||||||
|
from volcenginesdkarkruntime import Ark
|
||||||
|
|
||||||
|
# 从官网获取 API_KEY
|
||||||
|
client = Ark(api_key='')
|
||||||
|
|
||||||
|
with st.sidebar:
|
||||||
|
with st.expander('参数', expanded=True):
|
||||||
|
top_p = st.slider('top_p', 0.01, 1.0, step=0.01, value=0.8, key='top_p_session')
|
||||||
|
temperature = st.slider('temperature', 0.51, 1.0, step=0.01, value=0.85, key='temperature_session')
|
||||||
|
def reset_parameter():
|
||||||
|
st.session_state['top_p_session'] = 0.8
|
||||||
|
st.session_state['temperature_session'] = 0.85
|
||||||
|
reset_parameter_button = st.button('重置', on_click=reset_parameter)
|
||||||
|
|
||||||
|
prompt = st.chat_input("在这里输入您的命令")
|
||||||
|
|
||||||
|
def clear_all():
|
||||||
|
st.session_state.messages = []
|
||||||
|
st.session_state.ai_response = []
|
||||||
|
|
||||||
|
if 'messages' not in st.session_state:
|
||||||
|
st.session_state.messages = []
|
||||||
|
if 'ai_response' not in st.session_state:
|
||||||
|
st.session_state.ai_response = []
|
||||||
|
|
||||||
|
for ai_response in st.session_state.ai_response:
|
||||||
|
with st.chat_message(ai_response["role"], avatar=ai_response.get("avatar")):
|
||||||
|
st.markdown(ai_response["content"])
|
||||||
|
|
||||||
|
prompt_placeholder = st.chat_message("user", avatar='user')
|
||||||
|
with st.chat_message("robot", avatar="assistant"):
|
||||||
|
message_placeholder = st.empty()
|
||||||
|
|
||||||
|
def response_of_doubao(prompt):
|
||||||
|
st.session_state.messages.append({'role': 'user', 'content': prompt})
|
||||||
|
stream = client.chat.completions.create(
|
||||||
|
model="",
|
||||||
|
messages = st.session_state.messages,
|
||||||
|
stream=True,
|
||||||
|
top_p=top_p,
|
||||||
|
temperature=temperature,
|
||||||
|
)
|
||||||
|
full_content = ''
|
||||||
|
for chunk in stream:
|
||||||
|
if not chunk.choices:
|
||||||
|
continue
|
||||||
|
response = chunk.choices[0].delta.content
|
||||||
|
full_content += response
|
||||||
|
message_placeholder.markdown(full_content)
|
||||||
|
if stop_button:
|
||||||
|
break
|
||||||
|
st.session_state.messages.append({'role': 'assistant', 'content': full_content})
|
||||||
|
st.session_state.ai_response.append({"role": "robot", "content": full_content, "avatar": "assistant"})
|
||||||
|
return full_content
|
||||||
|
|
||||||
|
if prompt:
|
||||||
|
prompt_placeholder.markdown(prompt)
|
||||||
|
st.session_state.ai_response.append({"role": "user", "content": prompt, "avatar": 'user'})
|
||||||
|
stop = st.empty()
|
||||||
|
stop_button = stop.button('停止', key='break_response')
|
||||||
|
response_of_doubao(prompt)
|
||||||
|
stop.empty()
|
||||||
|
button_clear = st.button("清空", on_click=clear_all, key='clear')
|
Loading…
x
Reference in New Issue
Block a user