xiaobot

package module
v0.0.0-...-130d3a1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 20, 2023 License: MIT Imports: 18 Imported by: 0

README

xiaobot

Play ChatGPT with Xiaomi AI Speaker

fork from xiaogpt and convert to Go

支持的 AI 类型

  • ChatGPT API
  • NewBing WIP

准备

  1. ChatGPT Key
  2. 小爱音响
  3. 能正常联网的环境或 proxy

使用

  • 跑起来之后就可以问小爱同学问题了,“帮我"开头的问题,会发送一份给 ChatGPT 然后小爱同学用 tts 回答
  • 默认用目前 ubus, 如果你的设备不支持 ubus 可以使用配置 use_command 来使用 command 来 tts
  • 配置 mute_xiaoai 选项,可以快速停掉小爱的回答
  • 如果有能力可以自行替换唤醒词,也可以去掉唤醒词
  • 使用 gpt-3 的 api 那样可以更流畅的对话,速度快, 请 google 如何用 openai api 命令 --use_gpt3

config.toml

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

  • 环境变量 > config
xiaobot -c config.toml

配置项说明

参数 说明 默认值
hardware 设备型号
account 小爱账户
password 小爱账户密码
openai_key openai的apikey
cookie 小爱账户cookie (如果用上面密码登录可以不填)
mi_did 设备did
use_command 使用 MI command 与小爱交互 false
mute_xiaoai 快速停掉小爱自己的回答 true
verbose 是否打印详细日志 false
bot 使用的 bot 类型,目前支持gpt3,chatgptapi和newbing chatgptapi
enable_edge_tts 使用Edge TTS WIP false
edge_tts_voice Edge TTS 的嗓音 WIP zh-CN-XiaoxiaoNeural
prompt 自定义prompt 请用100字以内回答
keyword 自定义请求词列表 ["请问"]
change_prompt_keyword 更改提示词触发列表 ["更改提示词"]
start_conversation 开始持续对话关键词 开始持续对话
end_conversation 结束持续对话关键词 结束持续对话
stream 使用流式响应,获得更快的响应 WIP false
proxy 支持 HTTP 代理,传入 http proxy URL ""
gpt_options OpenAI API 的参数字典 {}
bing_cookie_path NewBing使用的cookie路径,参考[这里]获取 也可通过环境变量 COOKIE_FILE 设置
bing_cookies NewBing使用的cookie字典,参考[这里]获取

注意

  1. 请开启小爱同学的蓝牙
  2. 如果要更改提示词和 PROMPT 在代码最上面自行更改
  3. 目前已知 LX04 和 L05B L05C 可能需要使用 use_command

TODO

  1. 支持流式响应
  2. 支持Newbing
  3. UI 优化

感谢

Documentation

Index

Constants

View Source
const LatestAskApi = "" /* 127-byte string literal not displayed */
View Source
const MicoApi = "micoapi"
View Source
const TTSIndex = 0
View Source
const WakeupIndex = 1
View Source
const WakeupKeyword = "小爱同学"

Variables

View Source
var ChangePromptKeyWord = []string{"更改提示词"}
View Source
var DefaultCommand = [2]string{"5-1", "5-5"}
View Source
var EdgeTtsDict = map[string]string{
	"用英语": "en-US-AriaNeural",
	"用日语": "ja-JP-NanamiNeural",
	"用法语": "fr-BE-CharlineNeural",
	"用韩语": "ko-KR-SunHiNeural",
	"用德语": "de-AT-JonasNeural",
}
View Source
var HardwareCommandDict = map[string][2]string{

	"LX06":  {"5-1", "5-5"},
	"L05B":  {"5-3", "5-4"},
	"S12A":  {"5-1", "5-5"},
	"LX01":  {"5-1", "5-5"},
	"L06A":  {"5-1", "5-5"},
	"LX04":  {"5-1", "5-4"},
	"L05C":  {"5-3", "5-4"},
	"L17A":  {"7-3", "7-4"},
	"X08E":  {"7-3", "7-4"},
	"LX05A": {"5-1", "5-5"},
	"LX5A":  {"5-1", "5-5"},
	"L07A":  {"5-1", "5-5"},
	"L15A":  {"7-3", "7-4"},
	"X6A":   {"7-3", "7-4"},
}
View Source
var JarvisKeyWords = []string{"帮我", "请回答"}
View Source
var Prompt = "以下请用100字以内回答,请只回答文字不要带链接"

Functions

func Normalize

func Normalize(message string) string

Types

type Config

type Config struct {
	Hardware             string                 `json:"hardware" toml:"hardware"`
	Account              string                 `json:"account" toml:"account"`
	Password             string                 `json:"password" toml:"password"`
	OpenAIKey            string                 `json:"openai_key" toml:"openai_key"`
	OpenAIBackend        string                 `json:"openai_backend" toml:"openai_backend"`
	Proxy                string                 `json:"proxy,omitempty" toml:"proxy,omitempty"`
	MiDID                string                 `json:"mi_did" toml:"mi_did"`
	Keywords             []string               `json:"keyword" toml:"keyword"`
	ChangePromptKeywords []string               `json:"change_prompt_keyword" toml:"change_prompt_keyword"`
	Prompt               string                 `json:"prompt" toml:"prompt"`
	MuteXiaoAI           bool                   `json:"mute_xiaoai" toml:"mute_xiaoai"`
	Bot                  string                 `json:"bot" toml:"bot"`
	APIBase              string                 `json:"api_base,omitempty" toml:"api_base,omitempty"`
	UseCommand           bool                   `json:"use_command" toml:"use_command"`
	Verbose              bool                   `json:"verbose" toml:"verbose"`
	StartConversation    string                 `json:"start_conversation" toml:"start_conversation"`
	EndConversation      string                 `json:"end_conversation" toml:"end_conversation"`
	Stream               bool                   `json:"stream" toml:"stream"`
	EnableEdgeTTS        bool                   `json:"enable_edge_tts" toml:"enable_edge_tts"`
	EdgeTTSVoice         string                 `json:"edge_tts_voice" toml:"edge_tts_voice"`
	GPTOptions           map[string]interface{} `json:"gpt_options" toml:"gpt_options"`
	//BingCookiePath       string                 `json:"bing_cookie_path" toml:"bing_cookie_path"`
	//BingCookies          map[string]interface{} `json:"bing_cookies,omitempty" toml:"bing_cookies,omitempty"`
	TokenPath string `json:"token_path" toml:"token_path"`
}

func NewConfigFromFile

func NewConfigFromFile(path string) (*Config, error)

func NewConfigFromOptions

func NewConfigFromOptions(options map[string]interface{}) (*Config, error)

func (*Config) PostInit

func (c *Config) PostInit() error

func (*Config) ReadFromFile

func (c *Config) ReadFromFile(configPath string) (err error)

type MiBot

type MiBot struct {
	LastTimestamp  int64
	InConversation bool
	// contains filtered or unexported fields
}

func NewMiBot

func NewMiBot(config *Config) *MiBot

func (*MiBot) Run

func (mt *MiBot) Run() error

type Record

type Record struct {
	BitSet  []int `json:"bitSet"`
	Answers []struct {
		BitSet []int  `json:"bitSet"`
		Type   string `json:"type"`
		Tts    struct {
			BitSet []int  `json:"bitSet"`
			Text   string `json:"text"`
		} `json:"tts"`
	} `json:"answers"`
	Time      int64  `json:"time"`
	Query     string `json:"query"`
	RequestID string `json:"requestId"`
}

type Records

type Records struct {
	BitSet      []int    `json:"bitSet"`
	Records     []Record `json:"records"`
	NextEndTime int64    `json:"nextEndTime"`
}

type StatusInfo

type StatusInfo struct {
	Status   int `json:"status"`
	Volume   int `json:"volume"`
	LoopType int `json:"loop_type"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL