WeClone Documentation

One-stop solution for creating your AI twin from chat history 💡 Fine-tune LLMs with your chat logs to capture your unique style, then bind to a chatbot to...

18,047 stars Python Python 1 file · ~5,864 tokens #chat-history#digital-avatar#llm#qwen#telegram
RAW Doc

File: README.md

🚀 One-stop solution for creating your digital avatar from chat history 💡

[!IMPORTANT]

Telegram is now supported as a data source !

✨Core Features

  • 💫 Complete end-to-end solution for creating digital avatars, including chat data export, preprocessing, model training, and deployment
  • 💬 Fine-tune LLM using chat history with support for image modal data, infusing it with that authentic "flavor"
  • 🔗 Integrate with Telegram, WhatsApp (coming soon) to create your own digital avatar
  • 🛡️ Privacy information filtering with localized fine-tuning and deployment for secure and controllable data

📋Features & Notes

Data Source Platform Support

Platform Text Images Voice Video Animated Emojis/Stickers Links (Sharing) Quote Forward Location Files
Telegram ✅ ✅ ❌ ❌ ⚠️Convert to Emoji ❌ ❌ ✅ ✅ ❌
WhatsApp 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧
Discord 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧
Slack 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧

Deployment Platform Support

Platform Deployment Support
Telegram ✅
WhatsApp 🚧
WeChat (Personal Account) ✅ (Based on openclaw-weixin)
Discord ✅
Slack ✅

[!IMPORTANT]

  • WeClone is still in rapid iteration phase, current performance does not represent final results.
  • LLM fine-tuning effectiveness largely depends on model size, quantity and quality of chat data. Theoretically, larger models with more data yield better results.
  • The performance of the 7B model is average, while models with 14B or more parameters tend to deliver better results.
  • Windows environment has not been rigorously tested. You can use WSL as the runtime environment.

Recent Updates

[25/07/10] Data source added Telegram
[25/06/05] Support for image modal data fine-tuning

Hardware Requirements

The project uses Qwen2.5-VL-7B-Instruct model by default with LoRA method for SFT stage fine-tuning. You can also use other models and methods supported by LLaMA Factory.

Estimated VRAM requirements:

Method Precision 7B 14B 30B 70B xB
Full (bf16 or fp16) 32 120GB 240GB 600GB 1200GB 18xGB
Full (pure_bf16) 16 60GB 120GB 300GB 600GB 8xGB
Freeze/LoRA/GaLore/APOLLO/BAdam 16 16GB 32GB 64GB 160GB 2xGB
QLoRA 8 10GB 20GB 40GB 80GB xGB
QLoRA 4 6GB 12GB 24GB 48GB x/2GB
QLoRA 2 4GB 8GB 16GB 24GB x/4GB

Environment Setup

  1. CUDA installation (skip if already installed, requires version 12.6 or above)

  2. It is recommended to use uv to install dependencies, which is a very fast Python environment manager. After installing uv, you can use the following commands to create a new Python environment and install dependencies.

bash
git clone https://github.com/xming521/WeClone.git && cd WeClone
uv venv .venv --python=3.12
source .venv/bin/activate # windows .venv\Scripts\activate
uv pip install --group main -e .
  1. Copy the configuration file template and rename it to settings.jsonc, and make subsequent configuration changes in this file:
bash
cp examples/tg.template.jsonc settings.jsonc

[!NOTE]
Training and inference related configurations are unified in the file settings.jsonc

  1. Use the following command to test whether the CUDA environment is correctly configured and can be recognized by PyTorch (not needed for Mac):
bash
python -c "import torch; print('CUDA Available:', torch.cuda.is_available());"
  1. (Optional) Install FlashAttention to accelerate training and inference: uv pip install flash-attn --no-build-isolation.

Model Download

It is recommended to use Hugging Face to download models, or use the following command:

bash
git lfs install
git clone https://huggingface.co/Qwen/Qwen2.5-VL-7B-Instruct models/Qwen2.5-VL-7B-Instruct

Data Preparation

Please use Telegram Desktop to export chat records. Click the top right corner in the chat interface, then click "Export chat history". Select Photos for message types and JSON for format. You can export multiple contacts (group chat records are not recommended), then place the exported ChatExport_* in the ./dataset/telegram directory, meaning put different people's chat record folders together in ./dataset/telegram.

Data Preprocessing

  • First, modify the language, platform, and include_type in the configuration file according to your needs.
  • If you use telegram, you need to modify the telegram_args.my_id in the configuration file to your own telegram user ID.
  • By default, the project uses Microsoft Presidio to remove phone numbers, email addresses, credit card numbers, IP addresses, geographic location names, international bank account numbers, cryptocurrency wallet addresses, age information, and generic ID numbers from the data, but it cannot guarantee 100% identification.
  • Therefore, a blocklist blocked_words is provided in settings.jsonc, allowing users to manually add words or phrases they want to filter (the entire sentence containing blocked words will be removed by default).

[!IMPORTANT]
🚨 Please be sure to protect personal privacy and do not leak personal information!

  • Execute the following command to process the data. You can modify the make_dataset_args in settings.jsonc according to your own chat style.
bash
weclone-cli make-dataset

More Parameter Details: Data Preprocessing

Configure Parameters and Fine-tune Model

  • (Optional) Modify model_name_or_path, template, lora_target in settings.jsonc to select other locally downloaded models.
  • Modify per_device_train_batch_size and gradient_accumulation_steps to adjust VRAM usage.
  • You can modify parameters like num_train_epochs, lora_rank, lora_dropout in train_sft_args based on your dataset's quantity and quality.

Single GPU Training

bash
weclone-cli train-sft

Multi-GPU Training

Uncomment the deepspeed line in settings.jsonc and use the following command for multi-GPU training:

bash
uv pip install "deepspeed<=0.16.9"
deepspeed --num_gpus=number_of_gpus weclone/train/train_sft.py

Simple Inference with Browser Demo

Test suitable temperature and top_p values, then modify infer_args in settings.jsonc for subsequent inference use.

bash
weclone-cli webchat-demo

Inference Using API

bash
weclone-cli server

Test with Common Chat Questions

Does not include questions asking for personal information, only daily conversation. Test results are in test_result-my.txt.

bash
weclone-cli server
weclone-cli test-model

🖼️ Results Showcase

[!TIP]
We're looking for interesting examples of native English speakers chatting with WeClone! Feel free to share them with us on Twitter.

🤖 Deploy to Chat Bots

AstrBot

AstrBot is an easy-to-use multi-platform LLM chatbot and development framework ✨ Supports Discord, Telegram, Slack, Feishu and other platforms.

Usage steps:

  1. Deploy AstrBot
  2. Deploy messaging platforms like Discord, Telegram, Slack in AstrBot
  3. Execute weclone-cli server to start the API service
  4. Add a new service provider in AstrBot, select OpenAI type, fill in the API Base URL according to AstrBot's deployment method (e.g., for docker deployment it might be http://172.17.0.1:8005/v1), fill in the model as gpt-3.5-turbo, and enter any API Key
  5. Tool calling is not supported after fine-tuning, please turn off the default tools first by sending the command: /tool off_all on the messaging platform, otherwise the fine-tuned effect won't be visible.
  6. Set the system prompt in AstrBot according to the default_system used during fine-tuning.

[!IMPORTANT]
Check the api_service logs to ensure that the large model service request parameters are consistent with those used during fine-tuning as much as possible, and turn off all tool plugin capabilities.

LangBot

LangBot is an easy-to-use open-source LLM chatbot platform suitable for various scenarios. It connects to various global instant messaging platforms. You can set up your IM bot in just 5 minutes.

  1. Deploy LangBot

  2. Add a bot (Discord, Telegram, Slack, Lark e.g.) in LangBot

  3. Execute weclone-cli server to start the WeClone API service

  4. Add a new model in the model page, name it gpt-3.5-turbo, select OpenAI as the provider, fill in the request URL as WeClone's address. For detailed connection methods, refer to the documentation, and enter any API Key.

  5. Select the model you just added in the pipeline configuration, or modify the prompt configuration

📌 Roadmap

  • Support more data sources
  • Richer context: including contextual conversations, chat participant information, time, etc.
  • Memory support
  • Multimodal support: image support already implemented
  • Data augmentation
  • GUI support
  • COT (Chain of Thought) thinking support

Troubleshooting

[Official Documentation FAQ](https://docs.weclone.love/docs/introduce/FAQ.html)

It is also recommended to use DeepWiki for problem solving.

❤️ Contributing

Any Issues/Pull Requests are welcome!

You can contribute by checking Issues or helping review PRs (Pull Requests). For new feature additions, please discuss through Issues first.
Development environment:

bash
uv pip install --group dev -e .
pre-commit install

The project uses pytest for testing, pyright for type checking, and ruff for code formatting.
Before submitting your code, you should run pytest tests to ensure all tests pass.

🙏 Acknowledgments

Thanks to the following code contributors and other community members for their contributions

This project also benefits from excellent open source projects such as PyWxDump, LLaMA-Factory, AstrBot, LangBot, and others.

⚠️ Disclaimer

[!CAUTION]
This project is for learning, research and experimental purposes only. There are significant risks in using it for production environments, please assess carefully. Do not use for illegal purposes, consequences are at your own risk.

[!IMPORTANT]

WeClone is currently not partnered with any platform and has not issued any cryptocurrency. The only official website is: [weclone.love](https://www.weclone.love). Beware of imitations.

Click to view disclaimer terms

1. Use at Your Own Risk

  • Users should fully understand and bear all related risks when using this project
  • The project authors are not responsible for any direct or indirect losses arising from the use of this project
  • Including but not limited to: data loss, financial loss, legal disputes, personal reputation damage, social relationship impact, psychological trauma, career development obstacles, business reputation damage, etc.

2. Production Environment Risk Warning

  • Use for commercial purposes or providing external services requires bearing all risks yourself
  • All consequences that may result from production environment use (including but not limited to service interruption, data security issues, user complaints, legal liability, etc.) are entirely borne by the user
  • It is recommended to conduct thorough testing, verification and risk assessment before using in production environments

3. Model Output Unreliability

  • Fine-tuned models may produce inaccurate, harmful or misleading content
  • Model outputs do not represent the views or intentions of real persons
  • Users should conduct manual review and verification of model outputs

4. Data Security and Privacy

  • Users should ensure that uploaded chat records and other data comply with relevant laws and regulations
  • Users should obtain appropriate authorization from data-related persons
  • This project is not responsible for data leakage or privacy infringement
  • Users should ensure that using this project complies with local laws and regulations
  • Involving artificial intelligence, data protection, intellectual property and other related laws
  • Users bear the consequences of illegal use

6. Technical Support Limitations

  • This project is provided "as is" without any express or implied warranties
  • Authors do not promise to provide continuous technical support or maintenance
  • No guarantee of project stability, reliability or applicability

Usage Recommendations

Mandatory Bot Identity Identification

When using digital avatars generated by this project, it is strongly recommended to:

  • Clearly identify as "AI Bot" or "Digital Avatar" at the beginning of each conversation
  • Prominently mark "AI-generated content" in the user interface
  • Avoid letting users mistake it for real human conversation, which could cause risks

Risk Assessment Recommendations

If you must use in production environments, it is recommended to:

  1. Conduct comprehensive security testing
  2. Establish complete content review mechanisms
  3. Develop emergency response plans
  4. Purchase appropriate insurance coverage
  5. Consult legal professionals for advice

This disclaimer may be revised with project updates, users should regularly check the latest version. Continuing to use this project indicates agreement with the latest disclaimer terms.

Once you download, clone, modify, distribute or use the code or models of this project in any way, it indicates that you have fully read, understood and agreed to unconditionally accept all terms of this disclaimer.

Please carefully read and understand all contents of this disclaimer, ensuring strict compliance with relevant regulations when using this project.

⭐ Star History

[!TIP]
If this project is helpful to you, or if you are interested in the future development of this project, please give the project a Star, thank you


File: README_zh.md

🚀 One-stop solution for creating your digital avatar from chat history 💡

🚀从聊天记录创造数字分身的一站式解决方案💡

✨核心功能

  • 💫 涵盖打造数字分身的全链路方案,包括聊天数据导出、预处理、模型训练、部署
  • 💬 使用聊天记录微调LLM,支持图片模态数据,让大模型有"那味儿"
  • 🔗 绑定到Discord, Telegram, Slack, Feishu等,实现自己的数字分身
  • 🛡️ 隐私信息过滤,本地化微调部署,数据安全可控

📋特性与说明

数据源平台适配

平台 文字 图片 语音 视频 动画表情 链接(分享) 引用 转发 位置 文件
Telegram ✅ ✅ ❌ ❌ ⚠️转为Emjoy ❌ ❌ ✅ ✅ ❌
WhatsApp 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧
Discord 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧
Slack 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧

部署平台支持

平台 部署支持
个人微信 ✅ (基于 openclaw-weixin)
Telegram ✅
WhatsApp 🚧
Discord ✅
Slack ✅

[!IMPORTANT]

  • WeClone仍在快速迭代期,当前效果不代表最终效果。
  • 微调LLM效果很大程度取决于模型大小、聊天数据的数量和质量,理论上模型越大,数据越多,效果越好。
  • 7B模型效果一般,14B及以上的模型效果会更好。
  • Windows环境未进行严格测试,可以使用WSL作为运行环境。

近期更新

[25/06/05]支持图片模态数据微调
[25/07/10]数据源增加Telegram

硬件要求

项目默认使用Qwen2.5-7B-Instruct模型,LoRA方法对sft阶段微调,大约需要16GB显存。也可以使用LLaMA Factory支持的其他模型和方法。

需要显存的估算值:

方法 精度 7B 14B 30B 70B xB
Full (bf16 or fp16) 32 120GB 240GB 600GB 1200GB 18xGB
Full (pure_bf16) 16 60GB 120GB 300GB 600GB 8xGB
Freeze/LoRA/GaLore/APOLLO/BAdam 16 16GB 32GB 64GB 160GB 2xGB
QLoRA 8 10GB 20GB 40GB 80GB xGB
QLoRA 4 6GB 12GB 24GB 48GB x/2GB
QLoRA 2 4GB 8GB 16GB 24GB x/4GB

环境搭建

1.cuda安装(已安装可跳过,要求版本12.6及以上):LLaMA Factory

2.建议使用 uv安装依赖,这是一个非常快速的 Python 环境管理器。安装uv后,您可以使用以下命令创建一个新的Python环境并安装依赖项,速度较慢可以开启代理:

bash
git clone https://github.com/xming521/WeClone.git && cd WeClone
uv venv .venv --python=3.12
source .venv/bin/activate # windows下执行 .venv\Scripts\activate
uv pip install --group main -e . # 国内用户使用镜像:-i https://pypi.tuna.tsinghua.edu.cn/simple/ 
uv pip install https://github.com/explosion/spacy-models/releases/download/zh_core_web_sm-3.8.0/zh_core_web_sm-3.8.0-py3-none-any.whl

3.将配置文件模板复制一份并重命名为settings.jsonc,后续配置修改在此文件进行:

bash
cp settings.template.jsonc settings.jsonc

[!NOTE]
训练以及推理相关配置统一在文件settings.jsonc

4.使用以下命令测试CUDA环境是否正确配置并可被PyTorch识别,Mac不需要:

bash
python -c "import torch; print('CUDA是否可用:', torch.cuda.is_available());"

5.(可选)安装FlashAttention,加速训练和推理:uv pip install flash-attn --no-build-isolation 版本问题可以使用prebuild-wheels的预编译包安装。

模型下载

中国境内推荐使用ModelScope下载模型。例如下载WeClone默认模型:

bash
modelscope download --model Qwen/Qwen2.5-7B-Instruct --local_dir ./models/Qwen2.5-7B-Instruct

数据准备

Telegram

请使用Telegram Desktop导出聊天记录,点击右上角点击导出聊天记录,选择照片类型,格式选择JSON。可以导出多个联系人(不建议使用群聊记录),然后将导出的ChatExport_*文件夹放在./dataset/telegram目录即可,也就是不同人聊天记录的文件夹一起放在 ./dataset/telegram。

数据预处理

  • 首先根据需要修改配置文件中的language、platform、include_type。
  • 项目默认通过Microsoft Presidio去除了数据中的电话号码、电子邮件地址、信用卡号码(12-19位数字)、IP地址、地理位置名称、国际银行账户号码、加密货币钱包地址、年龄信息、通用身份证号码,但是不能保证100%过滤识别。
  • 所以在settings.jsonc中提供了一个禁用词词库blocked_words,可以自行添加需要过滤的词句(会默认去掉包括禁用词的整句)。

[!IMPORTANT]
🚨 请一定注意保护个人隐私,不要泄露个人信息!

  • 执行以下命令对数据进行处理,可以先根据自己的聊天风格修改settings.jsonc的make_dataset_args。
bash
weclone-cli make-dataset

数据处理更多参数说明:数据预处理

配置参数并微调模型

  • (可选)修改 settings.jsonc 的 model_name_or_path 、template、 lora_target选择本地下载好的其他模型。
  • 修改per_device_train_batch_size以及gradient_accumulation_steps来调整显存占用。
  • 可以根据自己数据集的数量和质量修改train_sft_args的num_train_epochs、lora_rank、lora_dropout等参数。

单卡训练

bash
weclone-cli train-sft

多卡训练

取消settings.jsonc中deepspeed行代码注释,使用以下命令多卡训练:

bash
uv pip install "deepspeed<=0.16.9"
deepspeed --num_gpus=使用显卡数量 weclone/train/train_sft.py

使用浏览器demo简单推理

测试出合适的temperature、top_p值,修改settings.jsonc的infer_args后,供后续推理时使用。

bash
weclone-cli webchat-demo

使用接口进行推理

bash
weclone-cli server

使用常见聊天问题测试

不包含询问个人信息的问题,仅有日常聊天。测试结果在test_result-my.txt。

bash
weclone-cli server
weclone-cli test-model

🖼️ 微调效果

[!TIP]
社群内有部署好的Qwen2.5VL 32B Bot,可以体验效果。

🤖 部署到聊天机器人

AstrBot

AstrBot 是易上手的多平台 LLM 聊天机器人及开发框架 ✨ 平台支持Telegram、飞书等。

使用步骤:

  1. 部署 AstrBot
  2. 在 AstrBot 中部署消息平台
  3. 执行 weclone-cli server 启动api服务
  4. 在 AstrBot 中新增服务提供商,类型选择OpenAI,API Base URL 根据AstrBot部署方式填写(例如docker部署可能为http://172.17.0.1:8005/v1) ,模型填写gpt-3.5-turbo,API Key随意填写一个
  5. 微调后不支持工具调用,请先关掉默认的工具,消息平台发送指令: /tool off_all,否则会没有微调后的效果。
  6. 根据微调时使用的default_system,在 AstrBot 中设置系统提示词。

[!IMPORTANT]
检查api_service的日志,尽量保证大模型服务请求的参数和微调时一致,tool插件能力都关掉。

LangBot

LangBot 是一个开源的接入全球多种即时通信平台的 LLM 机器人平台,适合各种场景使用。

  1. 部署 LangBot

  2. 执行 weclone-cli server 启动 WeClone API 服务

  3. 在 LangBot 中添加一个机器人

  4. 在模型页添加新模型,名称gpt-3.5-turbo,供应商选择 OpenAI,填写 请求 URL 为 WeClone 的地址,详细连接方式可以参考文档,API Key 任意填写。

  5. 在流水线配置中选择刚才添加的模型,或修改提示词配置

📌 路线图

  • 支持更多数据源
  • 更丰富的上下文:包括上下文对话、聊天对象信息、时间等
  • Memory 支持
  • 支持多模态:已支持图片
  • 数据增强
  • 支持GUI
  • 支持COT思考

问题解决

[官方文档FAQ](https://docs.weclone.love/docs/introduce/FAQ.html)

同时建议使用DeepWiki解决问题。

❤️ 贡献代码

欢迎任何 Issues/Pull Requests!

你可以通过查看Issues或帮助审核 PR(拉取请求)来贡献。对于新功能的添加,请先通过 Issue 讨论。
开发环境:

bash
uv pip install --group dev -e .
pre-commit install

项目使用pytest测试,pyright检查类型,ruff检查代码格式。
提交代码前你应该先运行pytest tests确保所有测试通过。

🙏 致谢

BUPT VCIS Lab的支持
感谢以下代码贡献者和社区里其他成员的贡献

同时本项目受益于LLaMA-Factory、AstrBot、LangBot等优秀开源项目。

⚠️ 免责声明

[!CAUTION]
本项目仅供学习、研究和实验用途,用于生产环境存在较大风险,请谨慎评估。请勿用于非法用途,后果自负。
针对违规获取及利用微信终端用户数据行为的打击公告

[!IMPORTANT]

WeClone 目前未与任何平台合作,未发行任何数字货币。唯一官方网站:[weclone.love](https://www.weclone.love),谨防仿冒。

点击查看免责条款

1. 使用风险自担

  • 用户在使用本项目时,应充分理解并承担所有相关风险
  • 本项目作者不对因使用本项目而产生的任何直接或间接损失承担责任
  • 包括但不限于:数据丢失、经济损失、法律纠纷、个人名誉损害、社会关系影响、心理创伤、职业发展受阻、商业信誉受损等

2. 生产环境风险警告

  • 用于商业用途或对外提供服务需自行承担全部风险
  • 生产环境使用可能导致的所有后果(包括但不限于服务中断、数据安全问题、用户投诉、法律责任等)完全由用户承担
  • 建议在生产环境使用前进行充分的测试、验证和风险评估

3. 模型输出不可靠性

  • 微调后的模型可能产生不准确、有害或误导性的内容
  • 模型输出不代表真实人物的观点或意图
  • 用户应对模型输出进行人工审核和验证

4. 数据安全与隐私

  • 用户应确保上传的聊天记录等数据符合相关法律法规
  • 用户应获得数据相关人员的适当授权
  • 本项目不对数据泄露或隐私侵犯承担责任

5. 法律合规

  • 用户应确保使用本项目符合当地法律法规
  • 涉及人工智能、数据保护、知识产权等相关法律
  • 违法使用造成的后果由用户承担

6. 技术支持限制

  • 本项目按"现状"提供,不提供任何明示或暗示的保证
  • 作者不承诺提供持续的技术支持或维护
  • 不保证项目的稳定性、可靠性或适用性

使用建议

强制性Bot身份标识

使用本项目生成的数字分身时,强烈建议:

  • 在每次对话开始时明确标识为"AI Bot"或"数字分身"
  • 在用户界面显著位置标注"此为AI生成内容"
  • 避免让用户误认为是真实人类在对话,从而造成风险

风险评估建议

如确需在生产环境使用,建议:

  1. 进行全面的安全性测试
  2. 建立完善的内容审核机制
  3. 制定应急响应预案
  4. 购买相应的保险保障
  5. 咨询法律专业人士意见

本免责声明可能随项目更新而修订,用户应定期查看最新版本。继续使用本项目即表示同意最新的免责声明条款。

一旦您下载、克隆、修改、分发或以任何方式使用本项目的代码或模型,即表示您已完整阅读、理解并同意无条件接受本免责声明的全部条款。

请用户慎重阅读并理解本免责声明的所有内容,确保在使用本项目时严格遵守相关规定。

⭐ Star History

[!TIP]
如果本项目对您有帮助,或者您关注本项目的未来发展,请给项目 Star,谢谢