MCPcopy
hub / github.com/yihong0618/xiaogpt

github.com/yihong0618/xiaogpt @v3.23 sqlite

repository ↗ · DeepWiki ↗ · release v3.23 ↗
148 symbols 522 edges 27 files 9 documented · 6%
README

xiaogpt

PyPI Docker Image Version (latest by date)

https://user-images.githubusercontent.com/15976103/226803357-72f87a41-a15b-409e-94f5-e2d262eecd53.mp4

Play ChatGPT and other LLM with Xiaomi AI Speaker

image image

支持的 AI 类型

获取小米音响 DID

系统和 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

export MI_PASS=xxx | set MI_USER=xxx

set MI_PASS=xxx | $env:MI_USER="xxx"

$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" |

  • 注意不同 shell 对环境变量的处理是不同的,尤其是 powershell 赋值时,可能需要双引号来包括值。
  • 如果获取 did 报错时,请更换一下无线网络,有很大概率解决问题。

一点原理

不用 root 使用小爱同学和 ChatGPT 交互折腾记

准备

  1. ChatGPT id
  2. 小爱音响
  3. 能正常联网的环境或 proxy
  4. python3.8+

使用

  • pip install -U --force-reinstall xiaogpt[locked]
  • 参考我 fork 的 MiService 项目 README 并在本地 terminal 跑 micli list 拿到你音响的 DID 成功 别忘了设置 export MI_DID=xxx 这个 MI_DID 用
  • run xiaogpt --hardware ${your_hardware} --use_chatgpt_api hardware 你看小爱屁股上有型号,输入进来,如果在屁股上找不到或者型号不对,可以用 micli mina 找到型号
  • 跑起来之后就可以问小爱同学问题了,“帮我"开头的问题,会发送一份给 ChatGPT 然后小爱同学用 tts 回答
  • 如果上面不可用,可以尝试用手机抓包,https://userprofile.mina.mi.com/device_profile/v2/conversation 找到 cookie 利用 --cookie '${cookie}' cookie 别忘了用单引号包裹
  • 默认用目前 ubus, 如果你的设备不支持 ubus 可以使用 --use_command 来使用 command 来 tts
  • 使用 --mute_xiaoai 选项,可以快速停掉小爱的回答
  • 使用 --account ${account} --password ${password}
  • 如果有能力可以自行替换唤醒词,也可以去掉唤醒词
  • 使用 --use_chatgpt_api 的 api 那样可以更流畅的对话,速度特别快,达到了对话的体验,openai api, 命令 --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 能力 (如何获取 fish voice 见下)
  • 可以使用 --tts openai 来获取 openai tts 能力
  • 可以使用 --tts azure --azure_tts_speech_key <your-speech-key> 来获取 Azure TTS 能力
  • 可以使用 --use_langchain 替代 --use_chatgpt_api 来调用 LangChain(默认 chatgpt)服务,实现上网检索、数学运算..

e.g.

export OPENAI_API_KEY=${your_api_key}
xiaogpt --hardware LX06 --use_chatgpt_api
# or
xiaogpt --hardware LX06 --cookie ${cookie} --use_chatgpt_api
# 如果你想直接输入账号密码
xiaogpt --hardware LX06 --account ${your_xiaomi_account} --password ${your_password} --use_chatgpt_api
# 如果你想 mute 小米的回答
xiaogpt --hardware LX06  --mute_xiaoai --use_chatgpt_api
# 使用流式响应,获得更快的响应
xiaogpt --hardware LX06  --mute_xiaoai --stream
# 如果你想使用 google 的 gemini
xiaogpt --hardware LX06  --mute_xiaoai --use_gemini --gemini_key ${gemini_key}
# 如果你想使用自己的 google gemini 服务
python3 xiaogpt.py --hardware LX06  --mute_xiaoai --use_gemini --gemini_key ${gemini_key} --gemini_api_domain ${gemini_api_domain}
# 如果你想使用阿里的通义千问
xiaogpt --hardware LX06  --mute_xiaoai --use_qwen --qwen_key ${qwen_key}
# 如果你想使用 kimi
xiaogpt --hardware LX06  --mute_xiaoai --use_moonshot_api --moonshot_api_key ${moonshot_api_key}
# 如果你想使用 llama3
xiaogpt --hardware LX06  --mute_xiaoai --use_llama --llama_api_key ${llama_api_key}
# 如果你想使用 01
xiaogpt --hardware LX06  --mute_xiaoai --use_yi_api --ti_api_key ${yi_api_key}
# 如果你想使用 LangChain+SerpApi 实现上网检索或其他本地服务(目前仅支持 stream 模式)
export OPENAI_API_KEY=${your_api_key}
export SERPAPI_API_KEY=${your_serpapi_key}
xiaogpt --hardware Lx06 --use_langchain --mute_xiaoai --stream --openai_key ${your_api_key} --serpapi_api_key ${your_serpapi_key}

使用 git clone 运行

export OPENAI_API_KEY=${your_api_key}
python3 xiaogpt.py --hardware LX06
# or
python3 xiaogpt.py --hardware LX06 --cookie ${cookie}
# 如果你想直接输入账号密码
python3 xiaogpt.py --hardware LX06 --account ${your_xiaomi_account} --password ${your_password} --use_chatgpt_api
# 如果你想 mute 小米的回答
python3 xiaogpt.py --hardware LX06  --mute_xiaoai
# 使用流式响应,获得更快的响应
python3 xiaogpt.py --hardware LX06  --mute_xiaoai --stream
# 如果你想使用 ChatGLM api
python3 xiaogpt.py --hardware LX06  --mute_xiaoai --use_glm --glm_key ${glm_key}
# 如果你想使用 google 的 gemini
python3 xiaogpt.py --hardware LX06  --mute_xiaoai --use_gemini --gemini_key ${gemini_key}
# 如果你想使用自己的 google gemini 服务
python3 xiaogpt.py --hardware LX06  --mute_xiaoai --use_gemini --gemini_key ${gemini_key} --gemini_api_domain ${gemini_api_domain}
# 如果你想使用阿里的通义千问
python3 xiaogpt.py --hardware LX06  --mute_xiaoai --use_qwen --qwen_key ${qwen_key}
# 如果你想使用 kimi
xiaogpt --hardware LX06  --mute_xiaoai --use_moonshot_api --moonshot_api_key ${moonshot_api_key}
# 如果你想使用 01
xiaogpt --hardware LX06  --mute_xiaoai --use_yi_api --ti_api_key ${yi_api_key}
# 如果你想使用豆包
python3 xiaogpt.py --hardware LX06  --mute_xiaoai --use_doubao --stream --volc_access_key xxxx --volc_secret_key xxx
# 如果你想使用 llama3
python3 xiaogpt.py --hardware LX06  --mute_xiaoai --use_llama --llama_api_key ${llama_api_key}
# 如果你想使用 LangChain+SerpApi 实现上网检索或其他本地服务(目前仅支持 stream 模式)
export OPENAI_API_KEY=${your_api_key}
export SERPAPI_API_KEY=${your_serpapi_key}
python3 xiaogpt.py --hardware Lx06 --use_langchain --mute_xiaoai --stream --openai_key ${your_api_key} --serpapi_api_key ${your_serpapi_key}

config.yaml

如果想通过单一配置文件启动也是可以的,可以通过 --config 参数指定配置文件,config 文件必须是合法的 Yaml 或 JSON 格式 参数优先级

  • cli args > default > config
python3 xiaogpt.py --config xiao_config.yaml
# or
xiaogpt --config xiao_config.yaml

或者

cp xiao_config.yaml.example xiao_config.yaml
python3 xiaogpt.py

若要指定 OpenAI 的模型参数,如 model, temporature, top_p, 请在 config.yaml 中指定:

gpt_options:
  temperature: 0.9
  top_p: 0.9

具体参数作用请参考 Open AI API 文档。 ChatGLM 文档

配置项说明

参数 说明 默认值 可选值
hardware 设备型号
account 小爱账户
password 小爱账户密码
openai_key openai 的 apikey
moonshot_api_key moonshot kimi 的 apikey
yi_api_key 01 wanwu 的 apikey
llama_api_key groq 的 llama3 apikey
serpapi_api_key serpapi 的 key 参考 SerpAPI
glm_key chatglm 的 apikey
gemini_key gemini 的 apikey 参考
gemini_api_domain gemini 的自定义域名 参考
qwen_key qwen 的 apikey 参考
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 edgeopenaiazurevolcbaidugoogleminimax
tts_options TTS 参数字典,参考 tetos 获取可用参数

Core symbols most depended-on inside this repo

add_message
called by 6
xiaogpt/bot/base_bot.py
get_messages
called by 5
xiaogpt/bot/base_bot.py
stop_if_xiaoai_is_playing
called by 4
xiaogpt/xiaogpt.py
main
called by 3
xiaogpt/cli.py
parse_cookie_string
called by 2
xiaogpt/utils.py
split_sentences
called by 2
xiaogpt/utils.py
get_hostname
called by 2
xiaogpt/utils.py
init_all_data
called by 2
xiaogpt/xiaogpt.py

Shape

Method 115
Class 22
Function 11

Languages

Python100%

Modules by API surface

xiaogpt/xiaogpt.py29 symbols
xiaogpt/bot/base_bot.py11 symbols
xiaogpt/tts/live.py10 symbols
xiaogpt/tts/file.py10 symbols
xiaogpt/langchain/callbacks.py8 symbols
xiaogpt/utils.py7 symbols
xiaogpt/bot/langchain_bot.py7 symbols
xiaogpt/config.py6 symbols
xiaogpt/bot/doubao_bot.py6 symbols
xiaogpt/bot/chatgptapi_bot.py6 symbols
xiaogpt/tts/base.py5 symbols
xiaogpt/langchain/examples/email/mail_box.py5 symbols

Dependencies from manifests, versioned

aiohappyeyeballs2.6.1 · 1×
aiohttp3.12.15 · 1×
aiosignal1.4.0 · 1×
annotated-types0.6.0 · 1×
anyio4.3.0 · 1×
async-timeout4.0.3 · 1×
attrs23.2.0 · 1×
azure-cognitiveservices-speech1.37.0 · 1×
beautifulsoup44.13.4 · 1×
cachetools5.3.2 · 1×
certifi2024.2.2 · 1×
cffi1.17.1 · 1×

For agents

$ claude mcp add xiaogpt \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact