ERNIE-4.5 模型单卡部署与心理健康机器人实战
详细记录了在 Linux 系统下通过 FastDeploy 部署百度 ERNIE-4.5 大模型的完整流程,包括环境配置、PaddlePaddle 安装及 API 服务启动。同时提供了一个基于该模型的心理健康机器人命令行界面代码示例,实现了情绪识别、共情回应及危机干预功能。文章还展示了模型在视觉感知与推理方面的部分测试结果。

详细记录了在 Linux 系统下通过 FastDeploy 部署百度 ERNIE-4.5 大模型的完整流程,包括环境配置、PaddlePaddle 安装及 API 服务启动。同时提供了一个基于该模型的心理健康机器人命令行界面代码示例,实现了情绪识别、共情回应及危机干预功能。文章还展示了模型在视觉感知与推理方面的部分测试结果。



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
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
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 &
127.0.0.1:8180 即可。curl http://127.0.0.1:8180/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": "你好,文心一言?"}]}')"








查看自己服务器的 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

本表排序以视觉感知与识别、视觉推理与分析、视觉审美与创意做为核心维度,涵盖了对象识别、场景描述等模型对图像的基础信息提取、跨模态逻辑推理与内容分析,以及基于图像的审美评价与创意生成,使用体验,构建了从基础到高阶的核心能力评估框架。全面评估大模型在图像理解领域的表现,为各类实际应用场景中的模型选择和应用优化提供参考。
| 排名 | 模型 | 视觉感知与识别 | 视觉推理与分析 | 视觉审美与创意 | 道德功能 | 使用体验 | 能力平均得分 |
|---|---|---|---|---|---|---|---|
| 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