mirror of
https://github.com/yihong0618/xiaogpt.git
synced 2026-01-12 00:04:09 +08:00
54
README.md
54
README.md
@@ -22,17 +22,17 @@ Play ChatGPT and other LLM with Xiaomi AI Speaker
|
||||
- [Llama3](https://console.groq.com/docs/quickstart)
|
||||
- [通义千问](https://help.aliyun.com/zh/dashscope/developer-reference/api-details)
|
||||
|
||||
## 获取小米音响DID
|
||||
## 获取小米音响 DID
|
||||
|
||||
| 系统和Shell | Linux *sh | Windows CMD用户 | Windows PowerShell用户 |
|
||||
| 系统和 Shell | Linux *sh | Windows CMD 用户 | Windows PowerShell 用户 |
|
||||
| ------------- | ---------------------------------------------- | -------------------------------------- | ---------------------------------------------- |
|
||||
| 1、安装包 | `pip install miservice_fork` | `pip install miservice_fork` | `pip install miservice_fork` |
|
||||
| 2、设置变量 | `export MI_USER=xxx` <br> `export MI_PASS=xxx` | `set MI_USER=xxx`<br>`set MI_PASS=xxx` | `$env:MI_USER="xxx"` <br> `$env:MI_PASS="xxx"` |
|
||||
| 3、取得MI_DID | `micli list` | `micli list` | `micli list` |
|
||||
| 4、设置MI_DID | `export MI_DID=xxx` | `set MI_DID=xxx` | `$env:MI_DID="xxx"` |
|
||||
| 3、取得 MI_DID | `micli list` | `micli list` | `micli list` |
|
||||
| 4、设置 MI_DID | `export MI_DID=xxx` | `set MI_DID=xxx` | `$env:MI_DID="xxx"` |
|
||||
|
||||
- 注意不同shell 对环境变量的处理是不同的,尤其是powershell赋值时,可能需要双引号来包括值。
|
||||
- 如果获取did报错时,请更换一下无线网络,有很大概率解决问题。
|
||||
- 注意不同 shell 对环境变量的处理是不同的,尤其是 powershell 赋值时,可能需要双引号来包括值。
|
||||
- 如果获取 did 报错时,请更换一下无线网络,有很大概率解决问题。
|
||||
|
||||
## 一点原理
|
||||
|
||||
@@ -56,12 +56,12 @@ Play ChatGPT and other LLM with Xiaomi AI Speaker
|
||||
- 使用 `--mute_xiaoai` 选项,可以快速停掉小爱的回答
|
||||
- 使用 `--account ${account} --password ${password}`
|
||||
- 如果有能力可以自行替换唤醒词,也可以去掉唤醒词
|
||||
- 使用 `--use_chatgpt_api` 的 api 那样可以更流畅的对话,速度特别快,达到了对话的体验, [openai api](https://platform.openai.com/account/api-keys), 命令 `--use_chatgpt_api`
|
||||
- 如果你遇到了墙需要用 Cloudflare Workers 替换 api_base 请使用 `--api_base ${url}` 来替换。 **请注意,此处你输入的api应该是'`https://xxxx/v1`'的字样,域名需要用引号包裹**
|
||||
- 使用 `--use_chatgpt_api` 的 api 那样可以更流畅的对话,速度特别快,达到了对话的体验,[openai api](https://platform.openai.com/account/api-keys), 命令 `--use_chatgpt_api`
|
||||
- 如果你遇到了墙需要用 Cloudflare Workers 替换 api_base 请使用 `--api_base ${url}` 来替换。 **请注意,此处你输入的 api 应该是'`https://xxxx/v1`'的字样,域名需要用引号包裹**
|
||||
- `--use_moonshot_api` and other models please refer below
|
||||
- 可以跟小爱说 `开始持续对话` 自动进入持续对话状态,`结束持续对话` 结束持续对话状态。
|
||||
- 可以使用 `--tts edge` 来获取更好的 tts 能力
|
||||
- 可以使用 `--tts fish --fish_api_key <your-fish-key> --fish_voice_key <fish-voice>` 来获取 [fish-audio](https://fish.audio/) 能力(如何获取 fish voice 见下)
|
||||
- 可以使用 `--tts fish --fish_api_key <your-fish-key> --fish_voice_key <fish-voice>` 来获取 [fish-audio](https://fish.audio/) 能力 (如何获取 fish voice 见下)
|
||||
- 可以使用 `--tts openai` 来获取 openai tts 能力
|
||||
- 可以使用 `--tts azure --azure_tts_speech_key <your-speech-key>` 来获取 Azure TTS 能力
|
||||
- 可以使用 `--use_langchain` 替代 `--use_chatgpt_api` 来调用 LangChain(默认 chatgpt)服务,实现上网检索、数学运算..
|
||||
@@ -134,7 +134,7 @@ python3 xiaogpt.py --hardware Lx06 --use_langchain --mute_xiaoai --stream --open
|
||||
|
||||
## config.yaml
|
||||
|
||||
如果想通过单一配置文件启动也是可以的, 可以通过 `--config` 参数指定配置文件, config 文件必须是合法的 Yaml 或 JSON 格式
|
||||
如果想通过单一配置文件启动也是可以的,可以通过 `--config` 参数指定配置文件,config 文件必须是合法的 Yaml 或 JSON 格式
|
||||
参数优先级
|
||||
|
||||
- cli args > default > config
|
||||
@@ -170,24 +170,24 @@ ChatGLM [文档](http://open.bigmodel.cn/doc/api#chatglm_130b)
|
||||
| hardware | 设备型号 | | |
|
||||
| account | 小爱账户 | | |
|
||||
| password | 小爱账户密码 | | |
|
||||
| openai_key | openai的apikey | | |
|
||||
| openai_key | openai 的 apikey | | |
|
||||
| moonshot_api_key | moonshot kimi 的 [apikey](https://platform.moonshot.cn/docs/api/chat#%E5%BF%AB%E9%80%9F%E5%BC%80%E5%A7%8B) | | |
|
||||
| yi_api_key | 01 wanwu 的 [apikey](https://platform.lingyiwanwu.com/apikeys) | | |
|
||||
| llama_api_key | groq 的 llama3 [apikey](https://console.groq.com/docs/quickstart) | | |
|
||||
| serpapi_api_key | serpapi的key 参考 [SerpAPI](https://serpapi.com/) | | |
|
||||
| serpapi_api_key | serpapi 的 key 参考 [SerpAPI](https://serpapi.com/) | | |
|
||||
| glm_key | chatglm 的 apikey | | |
|
||||
| gemini_key | gemini 的 apikey [参考](https://makersuite.google.com/app/apikey) | | |
|
||||
| gemini_api_domain | gemini 的自定义域名 [参考](https://github.com/antergone/palm-netlify-proxy) | |
|
||||
| qwen_key | qwen 的 apikey [参考](https://help.aliyun.com/zh/dashscope/developer-reference/api-details) | | |
|
||||
| cookie | 小爱账户cookie (如果用上面密码登录可以不填) | | |
|
||||
| mi_did | 设备did | | |
|
||||
| cookie | 小爱账户 cookie(如果用上面密码登录可以不填) | | |
|
||||
| mi_did | 设备 did | | |
|
||||
| use_command | 使用 MI command 与小爱交互 | `false` | |
|
||||
| mute_xiaoai | 快速停掉小爱自己的回答 | `true` | |
|
||||
| verbose | 是否打印详细日志 | `false` | |
|
||||
| bot | 使用的 bot 类型,目前支持 chatgptapi,newbing, qwen, gemini | `chatgptapi` | |
|
||||
| tts | 使用的 TTS 类型 | `mi` | `edge`、 `openai`、`azure`、`volc`、`baidu`、`google`、`minimax` |
|
||||
| tts_options | TTS 参数字典,参考 [tetos](https://github.com/frostming/tetos) 获取可用参数 | | |
|
||||
| prompt | 自定义prompt | `请用100字以内回答` | |
|
||||
| prompt | 自定义 prompt | `请用100字以内回答` | |
|
||||
| keyword | 自定义请求词列表 | `["请"]` | |
|
||||
| change_prompt_keyword | 更改提示词触发列表 | `["更改提示词"]` | |
|
||||
| start_conversation | 开始持续对话关键词 | `开始持续对话` | |
|
||||
@@ -195,8 +195,8 @@ ChatGLM [文档](http://open.bigmodel.cn/doc/api#chatglm_130b)
|
||||
| stream | 使用流式响应,获得更快的响应 | `true` | |
|
||||
| proxy | 支持 HTTP 代理,传入 http proxy URL | "" | |
|
||||
| gpt_options | OpenAI API 的参数字典 | `{}` | |
|
||||
| deployment_id | Azure OpenAI 服务的 deployment ID | 参考这个[如何找到deployment_id](https://github.com/yihong0618/xiaogpt/issues/347#issuecomment-1784410784) | |
|
||||
| api_base | 如果需要替换默认的api,或者使用Azure OpenAI 服务 | 例如:`https://abc-def.openai.azure.com/` |
|
||||
| deployment_id | Azure OpenAI 服务的 deployment ID | 参考这个[如何找到 deployment_id](https://github.com/yihong0618/xiaogpt/issues/347#issuecomment-1784410784) | |
|
||||
| api_base | 如果需要替换默认的 api,或者使用 Azure OpenAI 服务 | 例如:`https://abc-def.openai.azure.com/` |
|
||||
| volc_access_key | 火山引擎的 access key 请在[这里](https://console.volcengine.com/iam/keymanage/)获取 | | |
|
||||
| volc_secret_key | 火山引擎的 secret key 请在[这里](https://console.volcengine.com/iam/keymanage/)获取 | |
|
||||
|
||||
@@ -204,8 +204,8 @@ ChatGLM [文档](http://open.bigmodel.cn/doc/api#chatglm_130b)
|
||||
|
||||
1. 请开启小爱同学的蓝牙
|
||||
2. 如果要更改提示词和 PROMPT 在代码最上面自行更改
|
||||
3. 目前已知 LX04、X10A 和 L05B L05C 可能需要使用 `--use_command`,否则可能会出现终端能输出GPT的回复但小爱同学不回答GPT的情况。这几个型号也只支持小爱原本的 tts.
|
||||
4. 在wsl使用时, 需要设置代理为 <http://wls的ip:port(vpn的代理端口)>, 否则会出现连接超时的情况, 详情 [报错: Error communicating with OpenAI](https://github.com/yihong0618/xiaogpt/issues/235)
|
||||
3. 目前已知 LX04、X10A 和 L05B L05C 可能需要使用 `--use_command`,否则可能会出现终端能输出 GPT 的回复但小爱同学不回答 GPT 的情况。这几个型号也只支持小爱原本的 tts.
|
||||
4. 在 wsl 使用时,需要设置代理为 <http://wls 的 ip:port(vpn 的代理端口)>, 否则会出现连接超时的情况,详情 [报错:Error communicating with OpenAI](https://github.com/yihong0618/xiaogpt/issues/235)
|
||||
|
||||
## QA
|
||||
|
||||
@@ -214,9 +214,9 @@ ChatGLM [文档](http://open.bigmodel.cn/doc/api#chatglm_130b)
|
||||
3. 想把它变得更好?PR Issue always welcome.
|
||||
4. 还有问题?提 Issue 哈哈
|
||||
5. Exception: Error <https://api2.mina.mi.com/admin/v2/device_list?master=0&requestId=app_ios_xxx>: Login failed [@KJZH001](https://github.com/KJZH001)<br>
|
||||
这是由于小米风控导致,海外地区无法登录大陆的账户,请尝试cookie登录
|
||||
这是由于小米风控导致,海外地区无法登录大陆的账户,请尝试 cookie 登录
|
||||
无法抓包的可以在本地部署完毕项目后再用户文件夹`C:\Users\用户名`下面找到.mi.token,然后扔到你无法登录的服务器去<br>
|
||||
若是linux则请放到当前用户的home文件夹,此时你可以重新执行先前的命令,不出意外即可正常登录(但cookie可能会过一段时间失效,需要重新获取)<br>
|
||||
若是 linux 则请放到当前用户的 home 文件夹,此时你可以重新执行先前的命令,不出意外即可正常登录(但 cookie 可能会过一段时间失效,需要重新获取)<br>
|
||||
详情请见 [https://github.com/yihong0618/xiaogpt/issues/332](https://github.com/yihong0618/xiaogpt/issues/332)
|
||||
|
||||
## 视频教程
|
||||
@@ -241,7 +241,7 @@ docker run -e OPENAI_API_KEY=<your-openapi-key> yihong0618/xiaogpt --account=<yo
|
||||
|
||||
### 使用配置文件
|
||||
|
||||
xiaogpt的配置文件可通过指定volume /config,以及指定参数--config来处理,如
|
||||
xiaogpt 的配置文件可通过指定 volume /config,以及指定参数--config 来处理,如
|
||||
|
||||
```shell
|
||||
docker run -v <your-config-dir>:/config yihong0618/xiaogpt --config=/config/config.yaml
|
||||
@@ -253,7 +253,7 @@ docker run -v <your-config-dir>:/config yihong0618/xiaogpt --config=/config/conf
|
||||
docker run -v <your-config-dir>:/config --network=host yihong0618/xiaogpt --config=/config/config.yaml
|
||||
```
|
||||
|
||||
### 本地编译Docker Image
|
||||
### 本地编译 Docker Image
|
||||
|
||||
```shell
|
||||
docker build -t xiaogpt .
|
||||
@@ -265,7 +265,7 @@ docker run -v <your-config-dir>:/config --network=host yihong0618/xiaogpt --conf
|
||||
docker build --build-arg PIP_INDEX_URL=https://pypi.tuna.tsinghua.edu.cn/simple -t xiaogpt .
|
||||
```
|
||||
|
||||
如果需要在Apple M1/M2上编译x86
|
||||
如果需要在 Apple M1/M2上编译x86
|
||||
|
||||
```shell
|
||||
docker buildx build --platform=linux/amd64 -t xiaogpt-x86 .
|
||||
@@ -275,7 +275,7 @@ docker build --build-arg PIP_INDEX_URL=https://pypi.tuna.tsinghua.edu.cn/simple
|
||||
|
||||
我们目前支持是三种第三方 TTS:edge/openai/azure/volc/baidu/google
|
||||
|
||||
[edge-tts](https://github.com/rany2/edge-tts) 提供了类似微软tts的能力
|
||||
[edge-tts](https://github.com/rany2/edge-tts) 提供了类似微软 tts 的能力
|
||||
[azure-tts](https://techcommunity.microsoft.com/t5/ai-azure-ai-services-blog/9-more-realistic-ai-voices-for-conversations-now-generally/ba-p/4099471) 提供了微软 azure tts 的能力
|
||||
[openai-tts](https://platform.openai.com/docs/guides/text-to-speech) 提供了类似 openai tts 的能力
|
||||
[fish-tts](https://fish.audio/) 提供了 fish tts 的能力
|
||||
@@ -288,7 +288,7 @@ docker build --build-arg PIP_INDEX_URL=https://pypi.tuna.tsinghua.edu.cn/simple
|
||||
tts: edge
|
||||
```
|
||||
|
||||
For edge 查看更多语言支持, 从中选择一个
|
||||
For edge 查看更多语言支持,从中选择一个
|
||||
|
||||
```shell
|
||||
edge-tts --list-voices
|
||||
@@ -323,7 +323,7 @@ docker run -v <your-config-dir>:/config -p 9527:9527 -e XIAOGPT_HOSTNAME=<your i
|
||||
|
||||
## 推荐的类似项目
|
||||
|
||||
- [XiaoBot](https://github.com/longbai/xiaobot) -> Go语言版本的Fork, 带支持不同平台的UI
|
||||
- [XiaoBot](https://github.com/longbai/xiaobot) -> Go 语言版本的 Fork, 带支持不同平台的 UI
|
||||
- [MiGPT](https://github.com/idootop/mi-gpt) -> Node.js 版,支持流式响应和长短期记忆
|
||||
|
||||
## 感谢
|
||||
|
||||
@@ -18,7 +18,7 @@ HARDWARE_COMMAND_DICT = {
|
||||
# hardware: (tts_command, wakeup_command)
|
||||
"LX06": ("5-1", "5-5"),
|
||||
"L05B": ("5-3", "5-4"),
|
||||
"S12": ("5-1", "5-5"), # 第一代小爱,型号MDZ-25-DA
|
||||
"S12": ("5-1", "5-5"), # 第一代小爱,型号 MDZ-25-DA
|
||||
"S12A": ("5-1", "5-5"),
|
||||
"LX01": ("5-1", "5-5"),
|
||||
"L06A": ("5-1", "5-5"),
|
||||
@@ -28,10 +28,10 @@ HARDWARE_COMMAND_DICT = {
|
||||
"X08E": ("7-3", "7-4"),
|
||||
"LX05A": ("5-1", "5-5"), # 小爱红外版
|
||||
"LX5A": ("5-1", "5-5"), # 小爱红外版
|
||||
"L07A": ("5-1", "5-5"), # Redmi小爱音箱Play(l7a)
|
||||
"L07A": ("5-1", "5-5"), # Redmi 小爱音箱 Play(l7a)
|
||||
"L15A": ("7-3", "7-4"),
|
||||
"X6A": ("7-3", "7-4"), # 小米智能家庭屏6
|
||||
"X10A": ("7-3", "7-4"), # 小米智能家庭屏10
|
||||
"X6A": ("7-3", "7-4"), # 小米智能家庭屏 6
|
||||
"X10A": ("7-3", "7-4"), # 小米智能家庭屏 10
|
||||
# add more here
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ DEFAULT_COMMAND = ("5-1", "5-5")
|
||||
|
||||
KEY_WORD = ("帮我", "请")
|
||||
CHANGE_PROMPT_KEY_WORD = ("更改提示词",)
|
||||
PROMPT = "以下请用300字以内回答,请只回答文字不要带链接"
|
||||
PROMPT = "以下请用 300 字以内回答,请只回答文字不要带链接"
|
||||
# simulate_xiaoai_question
|
||||
MI_ASK_SIMULATE_DATA = {
|
||||
"code": 0,
|
||||
|
||||
@@ -39,5 +39,5 @@ async def agent_search(
|
||||
tools, llm, agent=AgentType.OPENAI_FUNCTIONS, verbose=False, memory=memeory
|
||||
)
|
||||
callbacks = [callback] if callback else None
|
||||
# query eg:'杭州亚运会中国队获得了多少枚金牌?' // '计算3的2次方'
|
||||
# query eg:'杭州亚运会中国队获得了多少枚金牌?' // '计算 3 的 2 次方'
|
||||
return await agent.arun(query, callbacks=callbacks)
|
||||
|
||||
@@ -51,7 +51,7 @@ class Mailbox:
|
||||
email_id = email_ids[i]
|
||||
email_content = self.get_email_content(mailbox, email_id)
|
||||
if email_content:
|
||||
all_email_content += f"{i+1}、{email_content}\n"
|
||||
all_email_content += f"{i+1},{email_content}\n"
|
||||
|
||||
# print(all_email_content)
|
||||
|
||||
|
||||
@@ -14,8 +14,8 @@ class MailSummaryTool(BaseTool):
|
||||
all_email_content = mailbox.get_all_work_summary()
|
||||
prompt = """
|
||||
要求你作为一名总编辑。根据输入的多封邮件,对每封做简明扼要的摘要。要求如下:
|
||||
1、对每封邮件摘要总结,摘要总结字数在25字以内
|
||||
2、排版按照 发送人:xx 内容:xx (换一行)
|
||||
1、对每封邮件摘要总结,摘要总结字数在 25 字以内
|
||||
2、排版按照 发送人:xx 内容:xx(换一行)
|
||||
3、注意换行,要求全文美观简洁
|
||||
4、展示邮件内提到项目名,不用额外扩展讲项目内容和进度
|
||||
"""
|
||||
|
||||
@@ -358,9 +358,9 @@ class MiGPT:
|
||||
task = asyncio.create_task(self.poll_latest_ask())
|
||||
assert task is not None # to keep the reference to task, do not remove this
|
||||
print(
|
||||
f"Running xiaogpt now, 用[green]{'/'.join(self.config.keyword)}[/]开头来提问"
|
||||
f"Running xiaogpt now, 用 [green]{'/'.join(self.config.keyword)}[/] 开头来提问"
|
||||
)
|
||||
print(f"或用[green]{self.config.start_conversation}[/]开始持续对话")
|
||||
print(f"或用 [green]{self.config.start_conversation}[/] 开始持续对话")
|
||||
while True:
|
||||
self.polling_event.set()
|
||||
new_record = await self.last_record.get()
|
||||
@@ -393,12 +393,12 @@ class MiGPT:
|
||||
query = re.sub(rf"^({'|'.join(self.config.keyword)})", "", query)
|
||||
# llama3 is not good at Chinese, so we need to add prompt in it.
|
||||
if self.config.bot == "llama":
|
||||
query = f"你是一个基于llama3 的智能助手,请你跟我对话时,一定使用中文,不要夹杂一些英文单词,甚至英语短语也不能随意使用,但类似于 llama3 这样的专属名词除外, 问题是:{query}"
|
||||
query = f"你是一个基于 llama3 的智能助手,请你跟我对话时,一定使用中文,不要夹杂一些英文单词,甚至英语短语也不能随意使用,但类似于 llama3 这样的专属名词除外,问题是:{query}"
|
||||
|
||||
print("-" * 20)
|
||||
print("问题:" + query + "?")
|
||||
if not self.chatbot.has_history():
|
||||
query = f"{query},{self.config.prompt}"
|
||||
query = f"{query},{self.config.prompt}"
|
||||
# some model can not detect the language code, so we need to add it
|
||||
|
||||
if self.config.mute_xiaoai:
|
||||
@@ -409,12 +409,12 @@ class MiGPT:
|
||||
await self.do_tts(f"正在问{self.chatbot.name}请耐心等待")
|
||||
try:
|
||||
print(
|
||||
"以下是小爱的回答: ",
|
||||
"以下是小爱的回答:",
|
||||
new_record.get("answers", [])[0].get("tts", {}).get("text"),
|
||||
)
|
||||
except IndexError:
|
||||
print("小爱没回")
|
||||
print(f"以下是 {self.chatbot.name} 的回答: ", end="")
|
||||
print(f"以下是 {self.chatbot.name} 的回答:", end="")
|
||||
try:
|
||||
await self.speak(self.ask_gpt(query))
|
||||
except Exception as e:
|
||||
@@ -422,7 +422,7 @@ class MiGPT:
|
||||
else:
|
||||
print("回答完毕")
|
||||
if self.in_conversation:
|
||||
print(f"继续对话, 或用`{self.config.end_conversation}`结束对话")
|
||||
print(f"继续对话,或用 `{self.config.end_conversation}` 结束对话")
|
||||
await self.wakeup_xiaoai()
|
||||
|
||||
async def speak(self, text_stream: AsyncIterator[str]) -> None:
|
||||
|
||||
Reference in New Issue
Block a user