Publish: 2024-04-12 | Modify: 2024-04-12
xiaogpt is a project that xiaoz learned about through a friend's recommendation, and it allows the Xiaomi AI speaker to be connected to large models such as ChatGPT and ChatGLM, making the AI speaker smarter.
Currently, xiaoz has successfully connected the first-generation Xiaomi AI speaker to ChatGPT. You can see the effect through the Bilibili link below. If it's useful, don't forget to give it a thumbs up.
This tutorial is slightly complicated and not suitable for beginners. It is recommended for IT professionals with a certain development foundation to try. Before you start, you need to prepare:
xiaogpt
depends on the Xiaomi speaker DID to control and communicate. We need to use the miservice_fork
tool to obtain the DID. This tool is developed using Python, so your computer needs to have Python 3 installed. xiaoz is operating on a Windows computer (any local network device can be used). It is recommended to search the Internet for instructions on how to install Python 3.
# Install miservice_fork
pip install miservice_fork
# Set Xiaomi username
set MI_USER=xxxx
# Set Xiaomi account password
set MI_PASS=xxx
# Obtain the DID
micli list
The result is as shown in the image below. Find the DID
number of the Xiaomi AI speaker and record it.
Before installation, we need to create the xiaogpt configuration file config.json
. The configuration file used by xiaoz is as follows:
{
"openai_key":"sk-xxx",
"api_base":"https://xxx.com/v1",
"hardware":"S12A",
"mute_xiaoai": true,
"account": "xxx",
"password":"xxx.",
"mi_did":"xxx",
"bot": "chatgptapi",
"tts": "mi",
"prompt": "Your name is xxx, 18 years old, an AI assistant. Your owner is xiaoz. Please keep your answers concise and to the point, and the total number of responses should not exceed 150 words.",
"keyword": [
"Please"
],
"stream": true
}
The configuration parameters are as follows:
v1
needs to be appended at the end.micli mina
to find the model number.mi
is the original voice of Xiaoai's response. You can also use Edge TTS, but xiaoz found Edge TTS to be very unstable in testing.Obtaining hardware information
xiaoz uses the first-generation Xiaomi AI speaker, and the model number displayed on the bottom is MDZ-25-DA
, which xiaogpt
does not recognize.
You may need to modify it to S12A
/S12
/L07A
and try each one.
Then continue to use Docker Compose for installation, and it is recommended to install it on a NAS. The complete docker-compose.yaml
content used by xiaoz is as follows:
version: '3.8'
services:
xiaogpt:
image: yihong0618/xiaogpt
volumes:
- ./config:/config
ports:
- "9527:9527"
restart: always
command: --config=/config/config.json
container_name: xiaogpt
Change ./config
to the directory of your configuration file. For example, if your configuration file is located at ./config/config.json
, then enter ./config
, and then enter docker-compose up -d
to start.
If everything goes well, try waking up Xiaoai and adding the word "Please" to trigger ChatGPT, as shown in the video above.
If you cannot solve the issue of accessing OpenAI and cannot find a suitable OpenAI intermediary service, consider connecting to the domestic large model ChatGLM: https://open.bigmodel.cn/. Obtain the SK in the Zhidu AI backend and fill it into the configuration file. The configuration for using ChatGLM is as follows:
{
"glm_key":"xxx",
"hardware":"S12A",
"mute_xiaoai": true,
"account": "xxx",
"password":"xxx.",
"mi_did":"xxx",
"bot": "glm",
"tts": "mi",
"use_glm": true,
"prompt": "The response cannot exceed 200 words",
"keyword": [
"Please"
],
"stream": true
}
If adding the word "Please" after triggering Xiaoai does not work, you can use docker logs xiaogpt
to view the container logs. If you encounter an error such as Exception: we have no hardware: S12A please check
, it may not be due to a hardware error, but could be due to other configuration parameter errors. Check each parameter.
At present, using xiaogpt
to connect the Xiaomi AI speaker to ChatGPT is not perfect, but it has expanded the ways to use the AI speaker, making it more interesting and intelligent. It is still worth trying for friends who have the conditions.
After actual experience, xiaoz found the following issues:
When using xiaogpt
to connect the Xiaomi AI speaker to ChatGPT, pay attention to the following issues:
miservice_fork
to obtain the correct DID number.S12A
/S12
/L07A
.xiaogpt project link: https://github.com/yihong0618/xiaogpt, thanks to the author for the contribution.
In addition, xiaoz has set up a NAS user exchange group, and those interested can scan the QR code to join.
I come from China and I am a freelancer. I specialize in Linux operations, PHP, Golang, and front-end development. I have developed open-source projects such as Zdir, ImgURL, CCAA, and OneNav.