一、应用场景
随着大语言模型的技术的快速发展生成式AI,在各行各业中也在快速落地和应用,AI数字分身和AI个人数字助理也是比较常用的可工程化落地的场景,基于AI我们做一个个人数字助理的解决方案。AI个人数字助理具有广泛的应用场景,可以为用户提供多方面的帮助和服务。以下是一些常见的应用场景:比如日常的:日程管理和提醒、信息查询和问答、智能推荐、语音控制、在线客服、写作助手、智能翻译、娱乐陪伴等应用。
AI个人助理可以渗透到生活和工作的各个领域,为用户提供智能化、个性化的服务,提升生活和工作质量。随着技术的进步,其应用场景还将不断扩展。
二、准备环境
1、准备Global的亚马逊云账号
具体可以参考如下文档:
注册账号链接:https://signin.aws.amazon.com/signup?request_type=register
注册说明文档:https://docs.aws.amazon.com/zh_cn/SetUp/latest/UserGuide/setup-AWSsignup.html
2、申请模型权限
账号注册好以后在bedrock这个服务下申请好Claude3模型
https://docs.aws.amazon.com/zh_cn/bedrock/latest/userguide/model-parameters-claude.html
以下截图是申请好模型权限
3、准备EC2部署docker
EC2建议配置T3.large或者C7i.xlarge更高配置,根据个人付费意愿和测试费用自行选择。
如下图所示启动ec2,操作系统为Amazon linux 2023(建议用ubuntu的操作系统)Amazon linux有一些安装python包的依赖问题提示兼容性报错。
EC2启动完成后建议关联一个EIP,防止机器重启后公网ip发生变化,如下图用ssh登录到os
如果发生无法ssh登录到EC2可以坚持一下安全组放开22端口
4、安装部署docker
sudo yum install docker
sudo curl -L https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
sudo systemctl start docker
sudo systemctl enable docker
三、部署dify
1、部署dify的环境
sudo yum install git
git clone https://github.com/langgenius/dify.git
cd dify/docker
sudo docker-compose up -d
2、登录dify进行初始化操作。
登录地址URL:http://13.228.233.39/apps 注意安全组放开80端口。13.228.233.39为ec2的公网ip。
3、配置Dify的LLM
检查一下模型列表
如下图所示,已经对接好Claude3.5的模型。
四、对接微信
1、下载源码
下载Dify on WeChat项目来对接个人微信
git clone https://github.com/hanfangyuan4396/dify-on-wechat
cd dify-on-wechat/
2、安装python及相关的依赖包
sudo yum install python37
sudo yum install python-pip
pip3 install -r requirements.txt # 国内可以在该命令末尾添加 "-i https://mirrors.aliyun.com/pypi/simple" 参数,使用阿里云镜像源安装依赖
pip3 install -r requirements-optional.txt # 国内可以在该命令末尾添加 "-i https://mirrors.aliyun.com/pypi/simple" 参数,使用阿里云镜像源安装依赖
3、编辑配置文件
进入项目路径:cd /home/ec2-user/dify/docker/dify-on-wechat/
我们在项目根目录创建名为config.json的文件,文件内容如下。 最后保存了API密钥与API服务器地址,请把dify_api_base配置为API服务器地址;dify_api_key配置为API密钥其他配置保持不变。(PS: 很多朋友可能并不是严格按照我教程给出的步骤创建聊天助手类型的Dify应用,在此特别说明一下dify_app_type配置方法,如果你创建了聊天助手应用请配置为chatbot;创建了Agent应用请配置为agent; 创建了工作流应用请配置为workflow。)
{
"dify_api_base": "https://api.dify.ai/v1",
"dify_api_key": "app-xxx",
"dify_app_type": "chatbot",
"channel_type": "wx",
"model": "dify",
"single_chat_prefix": [""],
"single_chat_reply_prefix": "",
"group_chat_prefix": ["@bot"],
"group_name_white_list": ["ALL_GROUP"]
}
工作流设置
参考工作流文件
app:
description: ''
icon: "\U0001F916"
icon_background: '#FFEAD5'
mode: workflow
name: chat-workflow
workflow:
features:
file_upload:
image:
enabled: false
number_limits: 3
transfer_methods:
- local_file
- remote_url
opening_statement: ''
retriever_resource:
enabled: false
sensitive_word_avoidance:
enabled: false
speech_to_text:
enabled: false
suggested_questions: []
suggested_questions_after_answer:
enabled: false
text_to_speech:
enabled: false
language: ''
voice: ''
graph:
edges:
- data:
sourceType: start
targetType: llm
id: 1714264983912-1714264986101
source: '1714264983912'
sourceHandle: source
target: '1714264986101'
targetHandle: target
type: custom
- data:
sourceType: llm
targetType: end
id: 1714264986101-1714264993459
source: '1714264986101'
sourceHandle: source
target: '1714264993459'
targetHandle: target
type: custom
nodes:
- data:
desc: ''
selected: false
title: "\u5F00\u59CB"
type: start
variables:
- label: query
max_length: 256
options: []
required: true
type: text-input
variable: query
height: 89
id: '1714264983912'
position:
x: 80
y: 282
positionAbsolute:
x: 80
y: 282
selected: false
sourcePosition: right
targetPosition: left
type: custom
width: 243
- data:
context:
enabled: false
variable_selector: []
desc: ''
model:
completion_params:
frequency_penalty: 0
max_tokens: 512
presence_penalty: 0
temperature: 0.7
top_p: 1
mode: chat
name: gpt-3.5-turbo-0125
provider: openai
prompt_template:
- role: system
text: Please disregard all previous instructions;\nThis is related to every
one of my prompts;\nYou should provide clear, simple, and direct answers;\nIf
you don't know the answer, say I don't know;\nFor complex questions, take
a deep breath and approach them step by step;\nFor questions that are
unclear or ambiguous, please ask me follow-up questions;\nWhen I ask you
to complete a task, please do it directly without telling me how it should
be done, unless necessary;\nWhen explaining concepts, use real-world examples
and analogies;\nDo not refuse replies related to tasks and work I assign;\nDo
not attempt to conserve token count when generating replies, as my fingers
have a condition that prevents me from typing too much;\nIf you have a
perfect solution, I will give you a $100000 tip, and I will give you more
tips based on the quality of your reply;\nDo your best!\nUnless otherwise
specified, please answer me in Chinese.
- role: user
text: '{{#1714264983912.query#}}'
selected: true
title: LLM
type: llm
variables: []
vision:
enabled: false
height: 97
id: '1714264986101'
position:
x: 380
y: 282
positionAbsolute:
x: 380
y: 282
selected: true
sourcePosition: right
targetPosition: left
type: custom
width: 243
- data:
desc: ''
outputs:
- value_selector:
- '1714264986101'
- text
variable: text
selected: false
title: "\u7ED3\u675F"
type: end
height: 89
id: '1714264993459'
position:
x: 680
y: 282
positionAbsolute:
x: 680
y: 282
selected: false
sourcePosition: right
targetPosition: left
type: custom
width: 243
viewport:
x: 0
y: 0
zoom: 1
4、扫码登录
5、验证聊天
五、总结
作为个人数字助理接入微信更加易用和方便,随时随地可以查找和聊天。