本文将手把手带你构建一个具有登录鉴权、上下文记忆、多模型支持、文件读取等功能的 DeepSeek AI Web 助手。只需使用 Python 和 Streamlit 即可完成,无需前端开发经验。
DeepSeek是一个开源通用大模型服务,具备强大的语言理解与推理能力,支持多种推理模型,如deepseek-chat
和deepseek-reasoner
。
我们将使用 Python 的 Streamlit 框架,构建一个网页端 AI 助手工具,具备以下亮点功能:
请确保安装以下依赖:
pip install streamlit requests pdfplumber chardet
项目中主要包含如下模块:
?? deepseek_dashboard/
│
├── main.py # 主程序入口
├── deepseek_dashboard.log # 日志输出文件(自动生成)
def configure_logging():
...
logging.basicConfig(level=logging.INFO, handlers=[file_handler, console_handler])
我们使用 Python 标准库logging
对用户行为、API 状态进行记录,方便排查问题。
class ChatMemory:
def __init__(self, max_messages=8):
...
该类用于维护会话历史,可限制最多记录N
条对话上下文,保证对话连贯性。
def process_uploaded_files(files) -> str:
...
支持上传 PDF 和 TXT 文件,PDF 使用pdfplumber
提取文本,其他文件自动识别编码(通过chardet
),截断长度防止超长上下文。
def query_deepseek(prompt, system_prompt, memory, model="deepseek-chat", temperature=0.7) -> Dict:
...
关键参数说明:
prompt
system_prompt
memory
model
temperature
def login_page():
...
提供 API Key 的输入框,用户需输入有效 DeepSeek API Key 才可使用主界面。
def main_interface():
...
功能包括:
streamlit run main.py
运行效果:
? 支持中英文 ? 支持 PDF 抽取 ? 可自定义系统提示词与模型
本文通过 Streamlit + DeepSeek API 快速构建了一个多功能 AI 助手应用,非常适合:
如果你想获取完整代码并持续跟进更新,可以访问:
?? GitHub 地址:https://github.com/ghostgorge/DeepSeek-AI-Assistant2.0/tree/master
?? 如有疑问欢迎评论交流!
将你的项目托管到 GitHub 是部署前的第一步。假设你已经有了一个本地项目文件夹,比如deepseek_dashboard/
,你可以按照以下步骤上传:
cd deepseek_dashboard
git init
git add .
git commit -m "initial commit"
deepseek-assistant
)
git remote add origin ***替换为你的github项目网站连接***
git branch -M main
git push -u origin main
完成后你的项目就已经上传到 GitHub,可以用于云端部署了。
Streamlit Cloud是 Streamlit 官方提供的免费托管平台,适合快速部署你的 AI 应用。
确保你的 GitHub 仓库中包含以下文件:
main.py
requirements.txt
requirements.txt
(示例)streamlit
requests
pdfplumber
chardet
?? 注意:Streamlit 会自动识别
main.py
,你无需设置额外入口。
Sign in with GitHub
,授权登录
main.py
Deploy
几秒后你的应用就上线了 ??
st.secrets
功能
如果你部署成功了,可以把你的地址放在这里展示,例如:
?? 在线体验:https://deepseek-ai-assistant2.streamlit.app/
如果你觉得这篇文章对你有帮助,欢迎 ??点赞、?收藏、??评论!