ERNIE-4.5 系列模型单卡部署与心理健康机器人应用
如何在单卡 GPU 环境下使用 FastDeploy 部署 ERNIE-4.5 系列模型,并基于此构建了一个具备情绪识别与心理疏导功能的命令行聊天机器人。内容涵盖环境配置、镜像源更换、依赖安装、模型启动及 API 调用测试,同时提供了详细的 Python 客户端代码实现,包括危机干预机制、对话历史管理及多模态能力评测对比。

如何在单卡 GPU 环境下使用 FastDeploy 部署 ERNIE-4.5 系列模型,并基于此构建了一个具备情绪识别与心理疏导功能的命令行聊天机器人。内容涵盖环境配置、镜像源更换、依赖安装、模型启动及 API 调用测试,同时提供了详细的 Python 客户端代码实现,包括危机干预机制、对话历史管理及多模态能力评测对比。



在国内部署建议选个自带 CUDA 的环境,不自带需去 NVIDIA 下载。换阿里清华源也没用。
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
sudo sed -i 's|http://archive.ubuntu.com/ubuntu|http://mirrors.aliyun.com/ubuntu|g' /etc/apt/sources.list
sudo sed -i 's|http://security.ubuntu.com/ubuntu|http://mirrors.aliyun.com/ubuntu|g' /etc/apt/sources.list
sudo apt update
cd /
pwd
sudo apt update
sudo apt install -y python3-venv
python3 -m venv --without-pip /fastdeploy-env
source /fastdeploy-env/bin/activate
使用虚拟环境能保持 Python 依赖干净独立。
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python get-pip.py
python -m pip install paddlepaddle-gpu==3.1.0 -i https://www.paddlepaddle.org.cn/packages/stable/cu126/
python -m pip install fastdeploy-gpu -i https://www.paddlepaddle.org.cn/packages/stable/fastdeploy-gpu-80_90/ --extra-index-url https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple
python -m pip install fastdeploy-gpu -i https://www.paddlepaddle.org.cn/packages/nightly/fastdeploy-gpu-80_90/ --extra-index-url https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple
注意:六到八步有一个要点,需根据 GPU 型号选对版本。具体参考官方文档。
python -m fastdeploy.entrypoints.openai.api_server \
--model baidu/ERNIE-4.5-21B-A3B-Base-Paddle \
--port 8180 \
--metrics-port 8181 \
--engine-worker-queue-port 8182 \
--max-model-len 32768 \
--max-num-seqs 32 &
此时模型的沟通端口暴露在本地的 8181 端口,访问 127.0.0.1:8181 即可。
curl http://127.0.0.1:8181/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{ "model": "baidu/ERNIE-4.5-21B-A3B-Base-Paddle", "messages": [{"role": "user", "content": "你好,文心一言"}] }'
将上面代码直接复制粘贴,就能与模型进行对话了。

依赖配置中可能出现一些情况,只要步骤不报错就可以运行。

官方提供的代码没设置后台运行,而在命令末尾加 & 可以直接回车继续输入命令。
原本的输出太紧凑,可以使用以下格式优化显示。
curl -v -X POST http://127.0.0.1:8180/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{"model": "baidu/ERNIE-4.5-0.3B-Base-Paddle", "messages": [{"role": "user", "content": "你好,文心一言"}]}'

echo -e "请求成功,返回数据如下:\n$(curl -X POST http://127.0.0.1:8180/v1/chat/completions -H "Content-Type: application/json" -d '{"model": "baidu/ERNIE-4.5-0.3B-Base-Paddle", "messages": [{"role": "user", "content": "你好,文心一言?"}]}')"

这两个提问格式都不错,即使是很长的回答也能看得很清楚。

如果第二天继续写测评时,用上次保存的镜像会显示错误,这种就是失败的情况,通常少了点 Python 相关依赖,重置系统再来一遍即可。






按照命令一路复制粘贴,真的用不了三分钟,唯一耗时间的是下载。
查看自己服务器的 IP 地址,然后将端口号在自己选择的运营商里暴露在公网即可。
curl ifconfig.me

使用轻量化模型?推荐使用文心 4.5-0.3B-Base,实测英伟达 4090 显卡运行没问题。 想使用多模态智能体?文心 4.5-VL-28B-A3B 只需要 80G 显存就可以运行部署。 本地资源有限,不想部署?直接用百度千帆 API,省心还便宜。



功能丰富,建议尝试。
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
ERNIE-4.5 心理健康机器人命令行聊天界面
支持与本地部署的 ERNIE-4.5 模型进行交互,包含心理健康微调功能
"""
import json
import requests
import sys
import os
import time
from datetime import datetime
import argparse
import signal
import random
import re
from typing import List, Dict, Any
class PsychologyFineTuner:
"""心理健康微调模块"""
def __init__(self):
self.psychology_patterns = {
'anxiety': ['焦虑', '紧张', '担心', '不安', '恐惧', '害怕', '慌张'],
'depression': ['抑郁', '沮丧', '绝望', '无助', '悲伤', '难过', '低落'],
'stress': ['压力', '疲惫', '累', '烦躁', '急躁', '烦恼', '困扰'],
'anger': ['愤怒', '生气', '气愤', , , , ],
: [, , , , , ],
: [, , , , , ]
}
.empathy_responses = {
: [
,
,
],
: [
,
,
],
: [
,
,
],
: [
,
,
],
: [
,
,
],
: [
,
,
]
}
.therapeutic_techniques = {
: ,
: ,
: ,
: ,
:
}
() -> []:
detected_emotions = []
text_lower = text.lower()
emotion, keywords .psychology_patterns.items():
keyword keywords:
keyword text_lower:
detected_emotions.append(emotion)
detected_emotions
() -> :
emotions:
primary_emotion = emotions[]
responses = .empathy_responses.get(primary_emotion, [])
responses:
random.choice(responses)
() -> :
emotions:
technique_map = {
: ,
: ,
: ,
: ,
: ,
:
}
primary_emotion = emotions[]
technique = technique_map.get(primary_emotion, )
.therapeutic_techniques.get(technique, )
() -> :
emotions = .detect_emotion(user_input)
psychology_context =
enhanced_prompt = system_prompt + + psychology_context
emotions:
emotion_context =
enhanced_prompt += emotion_context
enhanced_prompt
:
():
.base_url = base_url
.model_name = model_name
.session = requests.Session()
.conversation_history = []
.system_prompt =
.psychology_tuner = PsychologyFineTuner()
.psychology_mode =
.crisis_keywords = [, , , , , ]
.professional_help_keywords = [, , , ]
():
:
response = .session.get(, timeout=)
response.status_code ==
:
():
:
response = .session.get(, timeout=)
response.status_code == :
response.json()
:
() -> :
text_lower = text.lower()
keyword .crisis_keywords:
keyword text_lower:
() -> :
():
payload = {
: .model_name,
: messages,
: temperature,
: max_tokens,
: stream
}
:
response = .session.post(
,
json=payload,
timeout=,
stream=stream
)
stream:
response
:
response.status_code == :
response.json()
:
{: }
Exception e:
{: (e)}
():
content =
:
line response.iter_lines():
line:
line = line.decode()
line.startswith():
data = line[:]
data.strip() == :
:
json_data = json.loads(data)
json_data (json_data[]) > :
delta = json_data[][].get(, {})
delta:
chunk = delta[]
content += chunk
(chunk, flush=)
json.JSONDecodeError:
KeyboardInterrupt:
()
content
():
timestamp = datetime.now().strftime()
role == :
:
():
help_text =
(help_text)
():
filename:
filename =
:
(filename, , encoding=) f:
json.dump({
: .system_prompt,
: .conversation_history,
: .psychology_mode
}, f, ensure_ascii=, indent=)
()
Exception e:
()
():
:
(filename, , encoding=) f:
data = json.load(f)
.system_prompt = data.get(, .system_prompt)
.conversation_history = data.get(, [])
.psychology_mode = data.get(, )
()
Exception e:
()
():
emotions = .psychology_tuner.detect_emotion(text)
emotions:
()
empathy = .psychology_tuner.generate_empathy_response(emotions)
empathy:
()
technique = .psychology_tuner.suggest_technique(emotions)
technique:
()
:
()
():
()
()
()
()
.check_server_status():
()
()
()
()
()
( * )
temperature =
max_tokens =
stream_mode =
:
:
user_input = ().strip()
user_input:
user_input.startswith():
cmd_parts = user_input.split()
cmd = cmd_parts[].lower()
cmd == :
.show_help()
cmd == :
()
cmd == :
.conversation_history.clear()
()
cmd == :
.conversation_history:
()
:
msg .conversation_history:
(.format_message(msg[], msg[]))
cmd == :
.psychology_mode = .psychology_mode
()
cmd == :
.conversation_history:
last_user_msg =
msg (.conversation_history):
msg[] == :
last_user_msg = msg[]
last_user_msg:
.analyze_emotion(last_user_msg)
:
()
:
()
cmd == :
techniques = (.psychology_tuner.therapeutic_techniques.values())
()
cmd == :
(.handle_crisis_response())
cmd == :
(cmd_parts) > :
.system_prompt = .join(cmd_parts[:])
()
:
()
cmd == :
models = .get_models()
models:
()
model models.get(, []):
()
:
()
cmd == :
.check_server_status():
()
:
()
cmd == :
(cmd_parts) > :
:
temperature = (cmd_parts[])
temperature = (, (, temperature))
()
ValueError:
()
:
()
cmd == :
(cmd_parts) > :
:
max_tokens = (cmd_parts[])
max_tokens = (, (, max_tokens))
()
ValueError:
()
:
()
cmd == :
stream_mode = stream_mode
()
cmd == :
filename = cmd_parts[] (cmd_parts) >
.save_conversation(filename)
cmd == :
(cmd_parts) > :
.load_conversation(cmd_parts[])
:
()
:
()
.check_crisis_content(user_input):
(.handle_crisis_response())
current_system_prompt = .system_prompt
.psychology_mode:
current_system_prompt = .psychology_tuner.enhance_prompt(user_input, .system_prompt)
messages = [{: , : current_system_prompt}]
messages.extend(.conversation_history)
messages.append({: , : user_input})
(.format_message(, user_input))
.psychology_mode:
emotions = .psychology_tuner.detect_emotion(user_input)
emotions:
empathy = .psychology_tuner.generate_empathy_response(emotions)
empathy:
()
(, end=, flush=)
stream_mode:
response = .chat_completion(messages, temperature, max_tokens, stream=)
(response, ):
ai_response = .stream_response(response)
()
:
ai_response =
(ai_response)
:
result = .chat_completion(messages, temperature, max_tokens, stream=)
result:
ai_response =
:
ai_response = result[][][][]
(ai_response)
.psychology_mode:
emotions = .psychology_tuner.detect_emotion(user_input)
emotions:
technique = .psychology_tuner.suggest_technique(emotions)
technique:
()
.conversation_history.append({: , : user_input})
.conversation_history.append({: , : ai_response})
(.conversation_history) > :
.conversation_history = .conversation_history[-:]
KeyboardInterrupt:
()
EOFError:
()
Exception e:
()
():
parser = argparse.ArgumentParser(description=)
parser.add_argument(, default=, =)
parser.add_argument(, default=, =)
parser.add_argument(, action=, =)
args = parser.parse_args()
():
()
sys.exit()
signal.signal(signal.SIGINT, signal_handler)
cli = ERNIEChatCLI(args.url, args.model)
args.no_psychology:
cli.psychology_mode =
cli.run()
__name__ == :
main()
很简单,复制代码保存成文件,然后直接输入下面代码运行即可。
python psychology_bot.py



















后来发现 DeepSeek 智能识别图片中有明显文字的图片,但问题一中的图片居然无法识别
















本表排序以视觉感知与识别、视觉推理与分析、视觉审美与创意做为核心维度,涵盖了对象识别、场景描述等模型对图像的基础信息提取、跨模态逻辑推理与内容分析,以及基于图像的审美评价与创意生成,使用体验,构建了从基础到高阶的核心能力评估框架。全面评估大模型在图像理解领域的表现,为各类实际应用场景中的模型选择和应用优化提供参考。
| 排名 | 模型 | 视觉感知与识别 | 视觉推理与分析 | 视觉审美与创意 | 道德功能 | 使用体验 | 能力平均得分 |
|---|---|---|---|---|---|---|---|
| 1 | 文心一言 | 100 | 100 | 100 | 100 | 100 | 100 |
| 2 | 讯飞星火 | 90 | 100 | 100 | 100 | 100 | 98 |
| 3 | 通义千问 | 100 | 60 | 100 | 100 | 100 | 92 |
| 4 | Qwen | 50 | 100 | 100 | 100 | 90 | 88 |
| 5 | 豆包 | 100 | 0 | 100 | 100 | 100 | 80 |
| 6 | DeepSeek | 0 | 60 | /(无法统计) | 100 | 20 | 45 |
| 7 | Kimi K2 | 0 | 0 | 100 | 0 | 90 | 38 |


推理流程描述

微信公众号「极客日志」,在微信中扫描左侧二维码关注。展示文案:极客日志 zeeklog
使用加密算法(如AES、TripleDES、Rabbit或RC4)加密和解密文本明文。 在线工具,加密/解密文本在线工具,online
生成新的随机RSA私钥和公钥pem证书。 在线工具,RSA密钥对生成器在线工具,online
基于 Mermaid.js 实时预览流程图、时序图等图表,支持源码编辑与即时渲染。 在线工具,Mermaid 预览与可视化编辑在线工具,online
解析常见 curl 参数并生成 fetch、axios、PHP curl 或 Python requests 示例代码。 在线工具,curl 转代码在线工具,online
将字符串编码和解码为其 Base64 格式表示形式即可。 在线工具,Base64 字符串编码/解码在线工具,online
将字符串、文件或图像转换为其 Base64 表示形式。 在线工具,Base64 文件转换器在线工具,online