xiaogpt

repository·main·Indexed 27 days ago

https://github.com/yihong0618/xiaogpt

A tool that allows users to interact with various Large Language Models (LLMs)—including ChatGPT, Gemini, Qwen, Llama3, and others—through a Xiaomi AI Speaker. It supports multiple TTS engines such as edge, openai, azure, and fish, and can be configured via CLI arguments, YAML/JSON files, or Docker.

Tokens
4.2K
Snippets
10
Records
28
Agent score
91%

What's inside xiaogpt

  1. Run xiaogpt using Docker

    main
    You can run xiaogpt using the official Docker image yihong0618/xiaogpt. You must provide an OPENAI_API_KEY via environment variables. You can pass command-line arguments directly to the container to configure your Xiaomi account, password, and hardware ID.
  2. Configure xiaogpt with a configuration file in Docker

    main

    To use a configuration file (e.g., config.yaml) within a Docker container, mount a local directory to /config and use the --config flag pointing to the path inside the container.

    docker run -v <your-config-dir>:/config yihong0618/xiaogpt --config=/config/config.yaml
    
    # Using host network mode
    docker run -v <your-config-dir>:/config --network=host yihong0618/xiaogpt --config=/config/config.yaml
  3. Build xiaogpt Docker image locally

    main
    You can build the Docker image from source. If you encounter slow dependency installation, you can use the --build-arg to specify a mirror (e.g., Tsinghua). For Apple Silicon (M1/M2) users needing an x86 image, use buildx.
  4. Run TTS providers in Docker (Edge/Azure/OpenAI/etc.)

    main

    Some TTS providers (like edge-tts) start a local HTTP service. When running in Docker, you must map the container port to the host and set the XIAOGPT_HOSTNAME environment variable to your host's IP address so the Xiaomi device can reach the service.

    docker run -v <your-config-dir>:/config -p 9527:9527 -e XIAOGPT_HOSTNAME=<your ip> yihong0618/xiaogpt --config=/config/config.yaml
  5. Get Xiaomi Speaker DID

    main

    To interact with your Xiaomi speaker, you need its DID (Device ID). You can obtain this using the miservice_fork package.

    Linux/macOS (sh/bash)

    1. pip install miservice_fork
    2. export MI_USER=xxx and export MI_PASS=xxx
    3. micli list (to find your DID)
    4. export MI_DID=xxx

    Windows CMD

    1. pip install miservice_fork
    2. set MI_USER=xxx and set MI_PASS=xxx
    3. micli list
    4. set MI_DID=xxx

    Windows PowerShell

    1. pip install miservice_fork
    2. $env:MI_USER="xxx" and $env:MI_PASS="xxx"
    3. micli list
    4. $env:MI_DID="xxx"

    Note: If micli list fails, try switching your wireless network.

    pip install miservice_fork
    export MI_USER=xxx
    export MI_PASS=xxx
    micli list
    export MI_DID=xxx
  6. Configure xiaogpt via config.yaml

    main

    You can start xiaogpt using a configuration file (YAML or JSON) via the --config flag.

    Priority order: CLI arguments > default > config file.

    To set OpenAI model parameters like temperature or top_p, use the gpt_options key in your YAML file.

    gpt_options:
      temperature: 0.9
      top_p: 0.9
    python3 xiaogpt.py --config xiao_config.yaml
  7. Configure AI Bot and TTS types

    main

    You can specify which AI engine and Text-to-Speech (TTS) engine to use via the bot and tts configuration keys.

    • bot: Supported values are chatgptapi, newbing, qwen, and gemini. Default is chatgptapi.
    • tts: Supported values are mi, edge, openai, azure, volc, baidu, google, and minimax. Default is mi.
  8. Configure xiaogpt parameters

    main

    The xiaogpt project uses several configuration parameters to manage AI models, Xiaomi speaker credentials, and interaction behaviors. You can configure these via environment variables or direct input depending on your setup.

    | 参数 | 说明 | 默认值 | 可选值 |
    | --------------------- | ---------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------- |
    | hardware | 设备型号 | | |
    | account | 小爱账户 | | |
    | password | 小爱账户密码 | | |
    | 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/) | | |
    | 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 | | |
    | 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字以内回答` | |
    | keyword | 自定义请求词列表 | `["请"]` | |
    | change_prompt_keyword | 更改提示词触发列表 | `["更改提示词"]` | |
    | start_conversation | 开始持续对话关键词 | `开始持续对话` | |
    | end_conversation | 结束持续对话关键词 | `结束持续对话` | |
    | stream | 使用流式响应,获得更快的响应 | `true` | |
    | proxy | 支持 HTTP 代理,传入 http proxy URL | "" | |
    | gpt_options | OpenAI API 的参数字典 | `{}` | |
    | deployment_id | Azure OpenAI 服务的 deployment ID | | |
    | 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/)获取 | |
  9. Troubleshoot Xiaomi Login Failures

    main

    If you encounter Login failed errors (often due to Xiaomi's regional security controls preventing overseas logins to mainland accounts), use cookie-based login.

    1. On a local machine, find the .mi.token file in your user folder (C:\Users\<username> on Windows or ~/ on Linux).
    2. Transfer this .mi.token file to your server.
    3. Re-run the command to log in using the token.