Skip to content

Commit a98ccdb

Browse files
author
xusenlin
committed
support base url in web
1 parent 2f78a23 commit a98ccdb

File tree

3 files changed

+22
-11
lines changed

3 files changed

+22
-11
lines changed

streamlit-demo/streamlit_app.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,19 @@ def main():
4242
if st.button("🗑️ 清空消息"):
4343
st.session_state.messages = []
4444

45+
with st.expander("✨ 模型配置", False):
46+
model_name = st.text_input(label="模型名称")
47+
base_url = st.text_input(label="模型接口地址", value=os.getenv("CHAT_API_BASE"))
48+
api_key = st.text_input(label="API KEY", value=os.getenv("API_KEY", "xxx"))
49+
50+
st.session_state.update(
51+
dict(
52+
model_name=model_name,
53+
base_url=base_url,
54+
api_key=api_key,
55+
)
56+
)
57+
4558
with st.expander("🐧 参数配置", False):
4659
max_tokens = st.slider("回复最大token数量", 20, 4096, 1024)
4760
temperature = st.slider("温度", 0.0, 1.0, 0.9)

streamlit-demo/streamlit_gallery/components/chat/streamlit_app.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import os
2-
31
import streamlit as st
42
from openai import OpenAI
53

@@ -8,8 +6,8 @@ def main():
86
st.title("💬 Chatbot")
97

108
client = OpenAI(
11-
api_key=os.getenv("API_KEY"),
12-
base_url=os.getenv("CHAT_API_BASE"),
9+
api_key=st.session_state.get("api_key", "xxx"),
10+
base_url=st.session_state.get("base_url", "xxx"),
1311
)
1412

1513
if "messages" not in st.session_state:
@@ -28,7 +26,7 @@ def main():
2826
message_placeholder = st.empty()
2927
full_response = ""
3028
for response in client.chat.completions.create(
31-
model="baichuan",
29+
model=st.session_state.get("model_name", "xxx"),
3230
messages=[
3331
{
3432
"role": m["role"],

streamlit-demo/streamlit_gallery/components/doc_chat/streamlit_app.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,6 @@ def main():
1414

1515
os.makedirs(UPLOAD_FOLDER, exist_ok=True)
1616

17-
client = OpenAI(
18-
api_key=os.getenv("API_KEY"),
19-
base_url=os.getenv("CHAT_API_BASE"),
20-
)
21-
2217
@st.cache_resource
2318
def load_doc_server():
2419
embeddings = OpenAIEmbeddings(
@@ -64,6 +59,11 @@ def delete_index(table_name):
6459

6560
st.title("💬 Document Chatbot")
6661

62+
client = OpenAI(
63+
api_key=st.session_state.get("api_key", "xxx"),
64+
base_url=st.session_state.get("base_url", "xxx"),
65+
)
66+
6767
col1, col2, col3 = st.columns([3, 3, 4])
6868

6969
with col1:
@@ -149,7 +149,7 @@ def delete_index(table_name):
149149
message_placeholder = st.empty()
150150
full_response = ""
151151
pyload = dict(
152-
model="qwen2",
152+
model=st.session_state.get("model_name", "xxx"),
153153
messages=[
154154
{
155155
"role": m["role"],

0 commit comments

Comments
 (0)