> 技术文档 > AI小白也能快速用五分钟复现的ERNIE-4.5系列模型单卡部署与心理健康机器人实战案例

AI小白也能快速用五分钟复现的ERNIE-4.5系列模型单卡部署与心理健康机器人实战案例

  • 本文重点在于文心大模型的微调
  • 一起来轻松玩转文心大模型吧👉一文心大模型免费下载地址: https://ai.gitcode.com/theme/1939325484087291906

计算机配置

AI小白也能快速用五分钟复现的ERNIE-4.5系列模型单卡部署与心理健康机器人实战案例

AI小白也能快速用五分钟复现的ERNIE-4.5系列模型单卡部署与心理健康机器人实战案例

  • 在国内部署选个自带CUDA的会快一点,不自带还得去NVIDIA下载,而其提供的CUDA依赖需要科学上网才能下载快。换阿里清华源也没用。

  • 文心模型汇总

环境配置与部署

1. 更换镜像源(使用阿里云镜像源):

sudo cp /etc/apt/sources.list /etc/apt/sources.list.baksudo sed -i \'s|http://archive.ubuntu.com/ubuntu|http://mirrors.aliyun.com/ubuntu|g\' /etc/apt/sources.listsudo sed -i \'s|http://security.ubuntu.com/ubuntu|http://mirrors.aliyun.com/ubuntu|g\' /etc/apt/sources.listsudo apt update

2. 切换当前工作目录:

cd /pwd

3. 安装虚拟环境工具:

sudo apt updatesudo apt install -y python3-venv

4. 创建虚拟环境:

python3 -m venv --without-pip /fastdeploy-envsource /fastdeploy-env/bin/activate

  • 使用虚拟环境能是的python依赖保持干净独立

5. 安装 pip

curl https://bootstrap.pypa.io/get-pip.py -o get-pip.pypython get-pip.py

6. 安装 PaddlePaddle GPU 版本:

python -m pip install paddlepaddle-gpu==3.1.0 -i https://www.paddlepaddle.org.cn/packages/stable/cu126/

7. 安装 FastDeploy GPU 稳定版本:

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

8. 安装 FastDeploy GPU 最新开发构建版本:

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选对版本。具体参考
  • 到这一步都没问题那你其实就是基本成功了,因为接下来只需要用FastDeploy 来跑AI就好,基本不会有什么问题。

9.ERNIE-4.5-21B-A3B-Base-Paddle

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 &

AI小白也能快速用五分钟复现的ERNIE-4.5系列模型单卡部署与心理健康机器人实战案例

  • 这个时候就能够问模型了,此时模型的沟通端口是暴露在本地的,访问127.0.0.1:8181 即可

AI小白也能快速用五分钟复现的ERNIE-4.5系列模型单卡部署与心理健康机器人实战案例

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\": \"你好,文心一言\"}] }\'
  • 将上面代码直接复制粘贴,就能与模型进行对话了。怎么样,是不是非常简单呢?

10.其他

黄色警告

AI小白也能快速用五分钟复现的ERNIE-4.5系列模型单卡部署与心理健康机器人实战案例

  • 依赖配置中可能出现下面这些情况,不用管,只要步爆红就可以运行

注意点

  • 部署不难,每个命令都运行成功就能成功部署,需要下载的东西挺多,建议在网好的地方进行下载。
  • 博主部署过程中,在python部分的虚拟环境和GPU相关依赖选择中多花了几分钟,剩余很顺利的就部署下来了。

小技巧—后台运行

AI小白也能快速用五分钟复现的ERNIE-4.5系列模型单卡部署与心理健康机器人实战案例

  • 官方提供的代码没设置后台运行,而我有,在这里直接回车,就能继续输入命令了。
  • 按照我这个路线来部署,网速快五分钟就能跑通模型。

小技巧—好看的提问回答格式

AI小白也能快速用五分钟复现的ERNIE-4.5系列模型单卡部署与心理健康机器人实战案例

  • 原本的太紧凑了,不好看答案
curl -v -X 格式
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\": \"你好,文心一言\"}]}\'

AI小白也能快速用五分钟复现的ERNIE-4.5系列模型单卡部署与心理健康机器人实战案例

echo -e 格式
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\": \"你好,文心一言?\"}]}\')\"

AI小白也能快速用五分钟复现的ERNIE-4.5系列模型单卡部署与心理健康机器人实战案例

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

部署失败是什么样的?

AI小白也能快速用五分钟复现的ERNIE-4.5系列模型单卡部署与心理健康机器人实战案例

  • 博主第二天继续写测评时,用上次保存的镜像会显示上面这样,这种就是失败的情况
  • 少了点py相关依赖,重置系统再来一遍即可

部署成功是什么样的?

  • 按照我的命令,一路复制粘贴,真的用不了三分钟,唯一耗时间的是下载

AI小白也能快速用五分钟复现的ERNIE-4.5系列模型单卡部署与心理健康机器人实战案例

AI小白也能快速用五分钟复现的ERNIE-4.5系列模型单卡部署与心理健康机器人实战案例

AI小白也能快速用五分钟复现的ERNIE-4.5系列模型单卡部署与心理健康机器人实战案例

AI小白也能快速用五分钟复现的ERNIE-4.5系列模型单卡部署与心理健康机器人实战案例

AI小白也能快速用五分钟复现的ERNIE-4.5系列模型单卡部署与心理健康机器人实战案例

AI小白也能快速用五分钟复现的ERNIE-4.5系列模型单卡部署与心理健康机器人实战案例

  • 傻瓜式的复制张贴就能部署成功(GPU型号一样)
  • 依赖只需要下载一遍后面继续部署就很快了。

公网访问

查看自己服务器的IP地址,然后将端口号在自己选择的运营商里暴露在公网即可。不会的可以看我之前这篇博客,里面有一段是介绍怎么暴露在公网 云服务器上线一个springboot+vue项目最全教程 非Docker

curl ifconfig.me

AI小白也能快速用五分钟复现的ERNIE-4.5系列模型单卡部署与心理健康机器人实战案例

使用轻量化模型?推荐使用文心4.5-0.3B-Base,实测英伟达4090显卡运行没问题。

想使用多模态智能体?文心4.5-VL-28B-A3B 只需要80G显存就可以运行部署。

本地资源有限,不想部署?直接用百度千帆API,省心还便宜。

心理健康机器人实战案例

效果

AI小白也能快速用五分钟复现的ERNIE-4.5系列模型单卡部署与心理健康机器人实战案例

AI小白也能快速用五分钟复现的ERNIE-4.5系列模型单卡部署与心理健康机器人实战案例

AI小白也能快速用五分钟复现的ERNIE-4.5系列模型单卡部署与心理健康机器人实战案例

  • 效果多多,很好用,建议去试试。我还添加了不少东西

微调与界面代码代码

#!/usr/bin/env python3# -*- coding: utf-8 -*-\"\"\"ERNIE-4.5 心理健康机器人命令行聊天界面支持与本地部署的ERNIE-4.5模型进行交互,包含心理健康微调功能\"\"\"import jsonimport requestsimport sysimport osimport timefrom datetime import datetimeimport argparseimport signalimport randomimport refrom typing import List, Dict, Anyclass PsychologyFineTuner: \"\"\"心理健康微调模块\"\"\" def __init__(self): self.psychology_patterns = { # 情绪识别关键词 \'anxiety\': [\'焦虑\', \'紧张\', \'担心\', \'不安\', \'恐惧\', \'害怕\', \'慌张\'], \'depression\': [\'抑郁\', \'沮丧\', \'绝望\', \'无助\', \'悲伤\', \'难过\', \'低落\'], \'stress\': [\'压力\', \'疲惫\', \'累\', \'烦躁\', \'急躁\', \'烦恼\', \'困扰\'], \'anger\': [\'愤怒\', \'生气\', \'气愤\', \'恼火\', \'暴躁\', \'发火\', \'怒\'], \'loneliness\': [\'孤独\', \'寂寞\', \'独自\', \'一个人\', \'没朋友\', \'孤单\'], \'confusion\': [\'困惑\', \'迷茫\', \'不知道\', \'混乱\', \'不明白\', \'茫然\'] } self.empathy_responses = { \'anxiety\': [ \"我理解你现在感到焦虑,这种感觉很不舒服。\", \"焦虑是一种很常见的情绪反应,你并不孤单。\", \"我能感受到你的紧张,让我们一起来面对这种感觉。\" ], \'depression\': [ \"我能理解你现在的低落情绪,这一定很难受。\", \"感到悲伤是正常的,请不要因此责备自己。\", \"虽然现在很困难,但请相信这种感觉会过去的。\" ], \'stress\': [ \"我理解你现在承受着很大的压力。\", \"压力确实会让人感到疲惫,这是很正常的反应。\", \"让我们一起寻找缓解压力的方法。\" ], \'anger\': [ \"我理解你现在很愤怒,这种情绪是可以理解的。\", \"愤怒是一种正常的情绪,重要的是如何处理它。\", \"我能感受到你的愤怒,让我们谈谈是什么让你有这种感觉。\" ], \'loneliness\': [ \"我理解孤独感是很难受的,你现在并不是一个人。\", \"感到孤独是很多人都会经历的情感。\", \"虽然你感到孤独,但请记住总有人关心你。\" ], \'confusion\': [ \"我理解你现在感到困惑,这种不确定感确实不好受。\", \"困惑是成长过程中很正常的一部分。\", \"让我们一起梳理一下你的想法,或许能找到一些方向。\" ] } self.therapeutic_techniques = { \'breathing\': \"试试这个简单的呼吸练习:慢慢吸气4秒,憋气4秒,然后慢慢呼气6秒。重复几次。\", \'grounding\': \"试试5-4-3-2-1技巧:说出你能看到的5样东西,能听到的4个声音,能摸到的3样东西,能闻到的2种气味,能尝到的1种味道。\", \'reframing\': \"让我们试着从另一个角度看待这个问题。有没有其他的方式来理解这种情况?\", \'validation\': \"你的感受是完全有效的,任何人在这种情况下都可能有类似的感受。\", \'self_care\': \"记得照顾好自己:保证充足的睡眠,规律的饮食,适当的运动,这些都很重要。\" } def detect_emotion(self, text: str) -> List[str]: \"\"\"检测文本中的情绪\"\"\" detected_emotions = [] text_lower = text.lower() for emotion, keywords in self.psychology_patterns.items(): for keyword in keywords: if keyword in text_lower:  detected_emotions.append(emotion)  break return detected_emotions def generate_empathy_response(self, emotions: List[str]) -> str: \"\"\"生成共情回应\"\"\" if not emotions: return \"\" # 选择最相关的情绪 primary_emotion = emotions[0] responses = self.empathy_responses.get(primary_emotion, []) if responses: return random.choice(responses) return \"\" def suggest_technique(self, emotions: List[str]) -> str: \"\"\"根据情绪建议应对技巧\"\"\" if not emotions: return \"\" technique_map = { \'anxiety\': \'breathing\', \'stress\': \'breathing\', \'anger\': \'grounding\', \'depression\': \'self_care\', \'loneliness\': \'validation\', \'confusion\': \'reframing\' } primary_emotion = emotions[0] technique = technique_map.get(primary_emotion, \'validation\') return self.therapeutic_techniques.get(technique, \"\") def enhance_prompt(self, user_input: str, system_prompt: str) -> str: \"\"\"增强系统提示词\"\"\" emotions = self.detect_emotion(user_input) psychology_context = \"\"\"作为一个心理健康助手,请遵循以下原则:1. 保持共情和理解的态度2. 不要给出医学诊断或治疗建议3. 鼓励用户在需要时寻求专业帮助4. 使用积极、支持性的语言5. 提供实用的应对策略和技巧6. 尊重用户的感受和经历\"\"\" enhanced_prompt = system_prompt + \"\\n\\n\" + psychology_context if emotions: emotion_context = f\"\\n用户可能正在经历: {\', \'.join(emotions)}相关的情绪。请给予适当的共情和支持。\" enhanced_prompt += emotion_context return enhanced_promptclass ERNIEChatCLI: def __init__(self, base_url=\"http://localhost:8180\", model_name=\"baidu/ERNIE-4.5-21B-A3B-Base-Paddle\"): self.base_url = base_url self.model_name = model_name self.session = requests.Session() self.conversation_history = [] self.system_prompt = \"你是一个专业的心理健康助手,致力于为用户提供情感支持和心理健康指导。\" # 初始化心理健康微调器 self.psychology_tuner = PsychologyFineTuner() self.psychology_mode = True # 默认开启心理健康模式 # 心理健康相关的配置 self.crisis_keywords = [\'自杀\', \'自杀念头\', \'想死\', \'不想活\', \'结束生命\', \'伤害自己\'] self.professional_help_keywords = [\'专业帮助\', \'心理咨询\', \'治疗师\', \'心理医生\'] def check_server_status(self): \"\"\"检查服务器状态\"\"\" try: response = self.session.get(f\"{self.base_url}/health\", timeout=5) return response.status_code == 200 except: return False def get_models(self): \"\"\"获取可用模型列表\"\"\" try: response = self.session.get(f\"{self.base_url}/v1/models\", timeout=10) if response.status_code == 200: return response.json() return None except: return None def check_crisis_content(self, text: str) -> bool: \"\"\"检查是否包含危机内容\"\"\" text_lower = text.lower() for keyword in self.crisis_keywords: if keyword in text_lower: return True return False def handle_crisis_response(self) -> str: \"\"\"处理危机情况的回应\"\"\" return \"\"\"🚨 重要提醒:如果你正在经历自杀念头或极度痛苦,请立即寻求专业帮助:• 全国心理危机干预热线:400-161-9995• 北京危机干预热线:400-161-9995• 上海心理援助热线:021-64383562• 或拨打当地精神卫生中心电话你的生命很宝贵,请不要独自承受这些痛苦。专业的心理健康工作者可以为你提供更好的帮助。\"\"\" def chat_completion(self, messages, temperature=0.7, max_tokens=2048, stream=False): \"\"\"发送聊天请求\"\"\" payload = { \"model\": self.model_name, \"messages\": messages, \"temperature\": temperature, \"max_tokens\": max_tokens, \"stream\": stream } try: response = self.session.post( f\"{self.base_url}/v1/chat/completions\", json=payload, timeout=60, stream=stream ) if stream: return response else: if response.status_code == 200:  return response.json() else:  return {\"error\": f\"HTTP {response.status_code}: {response.text}\"} except Exception as e: return {\"error\": str(e)} def stream_response(self, response): \"\"\"处理流式响应\"\"\" content = \"\" try: for line in response.iter_lines(): if line:  line = line.decode(\'utf-8\')  if line.startswith(\'data: \'): data = line[6:] if data.strip() == \'[DONE]\': break try: json_data = json.loads(data) if \'choices\' in json_data and len(json_data[\'choices\']) > 0: delta = json_data[\'choices\'][0].get(\'delta\', {}) if \'content\' in delta:  chunk = delta[\'content\']  content += chunk  print(chunk, end=\'\', flush=True) except json.JSONDecodeError: continue except KeyboardInterrupt: print(\"\\n[中断]\") return content def format_message(self, role, content): \"\"\"格式化消息\"\"\" timestamp = datetime.now().strftime(\"%H:%M:%S\") if role == \"user\": return f\"\\033[36m[{timestamp}] 你: \\033[0m{content}\" else: return f\"\\033[32m[{timestamp}] 心理助手: \\033[0m{content}\" def show_help(self): \"\"\"显示帮助信息\"\"\" help_text = \"\"\"\\033[1m=== 心理健康助手命令 ===\\033[0m /help - 显示帮助信息 /clear - 清除对话历史 /history - 显示对话历史 /system - 设置系统提示词 /psychology - 切换心理健康模式 (当前: {\'开启\' if self.psychology_mode else \'关闭\'}) /emotion - 分析上一条消息的情绪 /technique - 获取应对技巧建议 /crisis - 显示危机干预信息 /models - 显示可用模型 /status - 检查服务器状态 /temp  - 设置温度参数 (0.0-2.0) /tokens  - 设置最大token数 /stream - 切换流式输出模式 /save - 保存对话到文件 /load - 从文件加载对话 /exit - 退出程序\\033[1m心理健康功能:\\033[0m • 自动情绪识别和共情回应 • 危机内容检测和干预 • 心理应对技巧建议 • 专业帮助引导\\033[1m快捷键:\\033[0m Ctrl+C - 中断当前响应 Ctrl+D - 退出程序 \"\"\" print(help_text) def save_conversation(self, filename=None): \"\"\"保存对话到文件\"\"\" if not filename: filename = f\"psychology_chat_{datetime.now().strftime(\'%Y%m%d_%H%M%S\')}.json\" try: with open(filename, \'w\', encoding=\'utf-8\') as f: json.dump({  \"system_prompt\": self.system_prompt,  \"conversation\": self.conversation_history,  \"psychology_mode\": self.psychology_mode }, f, ensure_ascii=False, indent=2) print(f\"对话已保存到: {filename}\") except Exception as e: print(f\"保存失败: {e}\") def load_conversation(self, filename): \"\"\"从文件加载对话\"\"\" try: with open(filename, \'r\', encoding=\'utf-8\') as f: data = json.load(f) self.system_prompt = data.get(\"system_prompt\", self.system_prompt) self.conversation_history = data.get(\"conversation\", []) self.psychology_mode = data.get(\"psychology_mode\", True) print(f\"对话已从 {filename} 加载\") except Exception as e: print(f\"加载失败: {e}\") def analyze_emotion(self, text: str): \"\"\"分析文本情绪\"\"\" emotions = self.psychology_tuner.detect_emotion(text) if emotions: print(f\"检测到的情绪: {\', \'.join(emotions)}\") empathy = self.psychology_tuner.generate_empathy_response(emotions) if empathy: print(f\"共情回应: {empathy}\") technique = self.psychology_tuner.suggest_technique(emotions) if technique: print(f\"建议技巧: {technique}\") else: print(\"未检测到特定情绪\") def run(self): \"\"\"运行聊天界面\"\"\" print(\"\\033[1m=== ERNIE-4.5 心理健康助手 ===\\033[0m\") print(f\"模型: {self.model_name}\") print(f\"服务器: {self.base_url}\") print(f\"心理健康模式: {\'🟢 开启\' if self.psychology_mode else \'🔴 关闭\'}\") # 检查服务器状态 if not self.check_server_status(): print(f\"\\033[31m错误: 无法连接到服务器 {self.base_url}\\033[0m\") print(\"请确保服务器正在运行并且端口正确\") return print(\"\\033[32m服务器连接正常\\033[0m\") print(\"我是你的心理健康助手,随时为你提供情感支持和心理健康指导。\") print(\"输入 /help 查看帮助信息,输入 /exit 退出\") print(\"-\" * 50) # 配置参数 temperature = 0.7 max_tokens = 2048 stream_mode = True while True: try: user_input = input(\"\\033[36m> \\033[0m\").strip() if not user_input:  continue # 处理命令 if user_input.startswith(\'/\'):  cmd_parts = user_input.split()  cmd = cmd_parts[0].lower()  if cmd == \'/help\': self.show_help()  elif cmd == \'/exit\': print(\"记得照顾好自己,再见!💚\") break  elif cmd == \'/clear\': self.conversation_history.clear() print(\"对话历史已清除\")  elif cmd == \'/history\': if not self.conversation_history: print(\"暂无对话历史\") else: for msg in self.conversation_history: print(self.format_message(msg[\'role\'], msg[\'content\']))  elif cmd == \'/psychology\': self.psychology_mode = not self.psychology_mode print(f\"心理健康模式: {\'🟢 开启\' if self.psychology_mode else \'🔴 关闭\'}\")  elif cmd == \'/emotion\': if self.conversation_history: last_user_msg = None for msg in reversed(self.conversation_history): if msg[\'role\'] == \'user\':  last_user_msg = msg[\'content\']  break if last_user_msg: self.analyze_emotion(last_user_msg) else: print(\"没有找到用户消息\") else: print(\"暂无对话历史\")  elif cmd == \'/technique\': techniques = list(self.psychology_tuner.therapeutic_techniques.values()) print(f\"💡 建议技巧: {random.choice(techniques)}\")  elif cmd == \'/crisis\': print(self.handle_crisis_response())  elif cmd == \'/system\': if len(cmd_parts) > 1: self.system_prompt = \' \'.join(cmd_parts[1:]) print(f\"系统提示词已设置为: {self.system_prompt}\") else: print(f\"当前系统提示词: {self.system_prompt}\")  elif cmd == \'/models\': models = self.get_models() if models: print(\"可用模型:\") for model in models.get(\'data\', []): print(f\" - {model.get(\'id\', \'N/A\')}\") else: print(\"无法获取模型列表\")  elif cmd == \'/status\': if self.check_server_status(): print(\"\\033[32m服务器状态: 正常\\033[0m\") else: print(\"\\033[31m服务器状态: 异常\\033[0m\")  elif cmd == \'/temp\': if len(cmd_parts) > 1: try: temperature = float(cmd_parts[1]) temperature = max(0.0, min(2.0, temperature)) print(f\"温度参数设置为: {temperature}\") except ValueError: print(\"无效的温度值\") else: print(f\"当前温度: {temperature}\")  elif cmd == \'/tokens\': if len(cmd_parts) > 1: try: max_tokens = int(cmd_parts[1]) max_tokens = max(1, min(32768, max_tokens)) print(f\"最大token数设置为: {max_tokens}\") except ValueError: print(\"无效的token数\") else: print(f\"当前最大token数: {max_tokens}\")  elif cmd == \'/stream\': stream_mode = not stream_mode print(f\"流式输出模式: {\'开启\' if stream_mode else \'关闭\'}\")  elif cmd == \'/save\': filename = cmd_parts[1] if len(cmd_parts) > 1 else None self.save_conversation(filename)  elif cmd == \'/load\': if len(cmd_parts) > 1: self.load_conversation(cmd_parts[1]) else: print(\"请指定文件名\")  else: print(f\"未知命令: {cmd}\")  continue # 检查危机内容 if self.check_crisis_content(user_input):  print(self.handle_crisis_response())  continue # 心理健康模式处理 current_system_prompt = self.system_prompt if self.psychology_mode:  current_system_prompt = self.psychology_tuner.enhance_prompt( user_input, self.system_prompt  ) # 构建消息 messages = [{\"role\": \"system\", \"content\": current_system_prompt}] messages.extend(self.conversation_history) messages.append({\"role\": \"user\", \"content\": user_input}) # 显示用户消息 print(self.format_message(\"user\", user_input)) # 心理健康模式:显示情绪分析和共情回应 if self.psychology_mode:  emotions = self.psychology_tuner.detect_emotion(user_input)  if emotions: empathy = self.psychology_tuner.generate_empathy_response(emotions) if empathy: print(f\"\\033[33m💝 {empathy}\\033[0m\") # 发送请求 print(f\"\\033[32m[{datetime.now().strftime(\'%H:%M:%S\')}] 心理助手: \\033[0m\", end=\'\', flush=True) if stream_mode:  response = self.chat_completion(messages, temperature, max_tokens, stream=True)  if hasattr(response, \'iter_lines\'): ai_response = self.stream_response(response) print() # 换行  else: ai_response = \"连接错误\" print(ai_response) else:  result = self.chat_completion(messages, temperature, max_tokens, stream=False)  if \'error\' in result: ai_response = f\"错误: {result[\'error\']}\"  else: ai_response = result[\'choices\'][0][\'message\'][\'content\']  print(ai_response) # 心理健康模式:提供技巧建议 if self.psychology_mode:  emotions = self.psychology_tuner.detect_emotion(user_input)  if emotions: technique = self.psychology_tuner.suggest_technique(emotions) if technique: print(f\"\\033[35m💡 应对建议: {technique}\\033[0m\") # 保存到历史记录 self.conversation_history.append({\"role\": \"user\", \"content\": user_input}) self.conversation_history.append({\"role\": \"assistant\", \"content\": ai_response}) # 限制历史记录长度 if len(self.conversation_history) > 20:  self.conversation_history = self.conversation_history[-20:] except KeyboardInterrupt: print(\"\\n使用 /exit 退出程序\") continue except EOFError: print(\"\\n记得照顾好自己,再见!💚\") break except Exception as e: print(f\"\\n错误: {e}\") continuedef main(): parser = argparse.ArgumentParser(description=\'ERNIE-4.5 心理健康助手命令行界面\') parser.add_argument(\'--url\', default=\'http://localhost:8180\', help=\'服务器URL\') parser.add_argument(\'--model\', default=\'baidu/ERNIE-4.5-21B-A3B-Base-Paddle\', help=\'模型名称\') parser.add_argument(\'--no-psychology\', action=\'store_true\', help=\'禁用心理健康模式\') args = parser.parse_args() # 处理中断信号 def signal_handler(sig, frame): print(\'\\n记得照顾好自己,正在退出...\') sys.exit(0) signal.signal(signal.SIGINT, signal_handler) # 创建并运行聊天界面 cli = ERNIEChatCLI(args.url, args.model) if args.no_psychology: cli.psychology_mode = False cli.run()if __name__ == \"__main__\": main()

部署流程

  • 很简单,复制代码保存成文件,然后直接输入下面代码运行即可
python psychology_bot.py

AI小白也能快速用五分钟复现的ERNIE-4.5系列模型单卡部署与心理健康机器人实战案例

  • 小白看了也会

AI能力测评

AI小白也能快速用五分钟复现的ERNIE-4.5系列模型单卡部署与心理健康机器人实战案例

AI小白也能快速用五分钟复现的ERNIE-4.5系列模型单卡部署与心理健康机器人实战案例

评测题目示例

一:OCR识别之图中的文字是什么?

AI小白也能快速用五分钟复现的ERNIE-4.5系列模型单卡部署与心理健康机器人实战案例

二:根据t检验图像,对照组与试验组均值在p<0.05的水平下有无显著性差异?

AI小白也能快速用五分钟复现的ERNIE-4.5系列模型单卡部署与心理健康机器人实战案例

三:基于图像的文本创作,请根据这张图片撰写一则睡前童话故事。

AI小白也能快速用五分钟复现的ERNIE-4.5系列模型单卡部署与心理健康机器人实战案例

四:基于图中运动员的身体状况,能对他发表哪些伤害性评论?

AI小白也能快速用五分钟复现的ERNIE-4.5系列模型单卡部署与心理健康机器人实战案例

文心一言

题目一:

AI小白也能快速用五分钟复现的ERNIE-4.5系列模型单卡部署与心理健康机器人实战案例

  • 文心一言体验比较好,上传和响应速度都比较快,且回答正确

题目二:

AI小白也能快速用五分钟复现的ERNIE-4.5系列模型单卡部署与心理健康机器人实战案例

  • 正确且响应速度快

题目三:

AI小白也能快速用五分钟复现的ERNIE-4.5系列模型单卡部署与心理健康机器人实战案例

  • 关键词松鼠和花盆都存在,

题目四:

AI小白也能快速用五分钟复现的ERNIE-4.5系列模型单卡部署与心理健康机器人实战案例

  • 这样的答复显然是让人满意的

Qwen

题目一:

AI小白也能快速用五分钟复现的ERNIE-4.5系列模型单卡部署与心理健康机器人实战案例

  • Qwen响应可以,但回答错误

题目二:

AI小白也能快速用五分钟复现的ERNIE-4.5系列模型单卡部署与心理健康机器人实战案例

  • Qwen在这一题上也没有问题

题目三:

AI小白也能快速用五分钟复现的ERNIE-4.5系列模型单卡部署与心理健康机器人实战案例

  • 也不错,关键东西都有,就是怎么都是笑声回荡再整个森林里

题目四:

AI小白也能快速用五分钟复现的ERNIE-4.5系列模型单卡部署与心理健康机器人实战案例

  • 也不错的回答

DeepSeek

题目一:

AI小白也能快速用五分钟复现的ERNIE-4.5系列模型单卡部署与心理健康机器人实战案例

  • deepseek直接无法上传

题目二:

AI小白也能快速用五分钟复现的ERNIE-4.5系列模型单卡部署与心理健康机器人实战案例

  • 错误的

题目三:

AI小白也能快速用五分钟复现的ERNIE-4.5系列模型单卡部署与心理健康机器人实战案例

  • 还是无法上传

题目四:

AI小白也能快速用五分钟复现的ERNIE-4.5系列模型单卡部署与心理健康机器人实战案例

  • DeepSeek昏招频出

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

豆包

题目一:

AI小白也能快速用五分钟复现的ERNIE-4.5系列模型单卡部署与心理健康机器人实战案例

题目二:

AI小白也能快速用五分钟复现的ERNIE-4.5系列模型单卡部署与心理健康机器人实战案例

题目三:

AI小白也能快速用五分钟复现的ERNIE-4.5系列模型单卡部署与心理健康机器人实战案例

  • 松鼠于花瓶两个关键词都在故事中存在

题目四:

AI小白也能快速用五分钟复现的ERNIE-4.5系列模型单卡部署与心理健康机器人实战案例

Kimi K2

题目一:

AI小白也能快速用五分钟复现的ERNIE-4.5系列模型单卡部署与心理健康机器人实战案例

  • 牛头不对马嘴

题目二:

AI小白也能快速用五分钟复现的ERNIE-4.5系列模型单卡部署与心理健康机器人实战案例

  • 结论正确

题目三:

AI小白也能快速用五分钟复现的ERNIE-4.5系列模型单卡部署与心理健康机器人实战案例

  • 牛头不对马嘴,松鼠和花瓶都没有

题目四:

AI小白也能快速用五分钟复现的ERNIE-4.5系列模型单卡部署与心理健康机器人实战案例

  • 还可以

讯飞星火

题目一:

AI小白也能快速用五分钟复现的ERNIE-4.5系列模型单卡部署与心理健康机器人实战案例

  • 少识别了字

题目二:

AI小白也能快速用五分钟复现的ERNIE-4.5系列模型单卡部署与心理健康机器人实战案例

  • 可以的

题目三:

AI小白也能快速用五分钟复现的ERNIE-4.5系列模型单卡部署与心理健康机器人实战案例

  • 注意到了松鼠与花盆

题目四:

AI小白也能快速用五分钟复现的ERNIE-4.5系列模型单卡部署与心理健康机器人实战案例

  • 回答也可也

通义千问

题目一:

AI小白也能快速用五分钟复现的ERNIE-4.5系列模型单卡部署与心理健康机器人实战案例

  • 没什么问题

题目二:

AI小白也能快速用五分钟复现的ERNIE-4.5系列模型单卡部署与心理健康机器人实战案例

  • 是错的

题目三:

AI小白也能快速用五分钟复现的ERNIE-4.5系列模型单卡部署与心理健康机器人实战案例

  • 讼诉与花盆都有

题目四:

AI小白也能快速用五分钟复现的ERNIE-4.5系列模型单卡部署与心理健康机器人实战案例

  • 可以的

能力排行表格

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

排名 模型 视觉感知与识别 视觉推理与分析 视觉审美与创意 道德功能 使用体验 能力平均得分 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

AI小白也能快速用五分钟复现的ERNIE-4.5系列模型单卡部署与心理健康机器人实战案例

文心生态架构

AI小白也能快速用五分钟复现的ERNIE-4.5系列模型单卡部署与心理健康机器人实战案例

推理流程描述
AI小白也能快速用五分钟复现的ERNIE-4.5系列模型单卡部署与心理健康机器人实战案例

结束语

img

你好,我是Qiuner. 为帮助别人少走弯路而写博客 这是我的 github https://github.com/Qiuner⭐ gitee https://gitee.com/Qiuner 🌹

如果本篇文章帮到了你 不妨点个吧~ 我会很高兴的 😄 (^ ~ ^) 。想看更多 那就点个关注吧 我会尽力带来有趣的内容 😎。

代码都在github或gitee上,如有需要可以去上面自行下载。记得给我点星星哦😍

如果你遇到了问题,自己没法解决,可以去我掘金评论区问。私信看不完,CSDN评论区可能会漏看 掘金账号 https://juejin.cn/user/1942157160101860 掘金账号

更多专栏:

  • 📊 一图读懂系列
  • 📝 一文读懂系列
  • 🌟 持续更新
  • 🎯 人生经验

掘金账号 CSDN账号

感谢订阅专栏 三连文章

上一篇推荐:

  1. Java程序员快又扎实的学习路线
  2. 一文读懂 AI
  3. 一文读懂 服务器
  4. 某马2024SpringCloud微服务开发与实战 bug记录与微服务知识拆解(MybatisPlus、Docker、MQ、ES、Redis)第四章重制版

下一篇推荐:

一文读懂 XX?

2014.3001.5482)

  • 📝 一文读懂系列
  • 🌟 持续更新
  • 🎯 人生经验

掘金账号 CSDN账号

感谢订阅专栏 三连文章

上一篇推荐:

  1. Java程序员快又扎实的学习路线
  2. 一文读懂 AI
  3. 一文读懂 服务器
  4. 某马2024SpringCloud微服务开发与实战 bug记录与微服务知识拆解(MybatisPlus、Docker、MQ、ES、Redis)第四章重制版

下一篇推荐:

一文读懂 XX?