Skip to content

Commit

Permalink
feat: switch to yaml config (#501)
Browse files Browse the repository at this point in the history
* feat: switch to yaml config
removal: Remove EdgeGPT(new bing) since it is no longer maintained

Signed-off-by: Frost Ming <me@frostming.com>

* fix: remove new bing

Signed-off-by: Frost Ming <me@frostming.com>

* 更新 README.md

* 更新 README.md
  • Loading branch information
frostming committed May 9, 2024
1 parent fbdee6b commit f274ec2
Show file tree
Hide file tree
Showing 10 changed files with 156 additions and 404 deletions.
111 changes: 51 additions & 60 deletions README.md

Large diffs are not rendered by default.

203 changes: 2 additions & 201 deletions pdm.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ dependencies = [
"rich",
"zhipuai>=2.0.1",
"httpx[socks]",
"EdgeGPT==0.1.26",
"langchain>=0.0.343",
"beautifulsoup4>=4.12.0",
"google-search-results>=2.4.2",
Expand All @@ -27,6 +26,7 @@ dependencies = [
"dashscope>=1.10.0",
"tetos>=0.2.1",
"groq>=0.5.0",
"pyyaml>=6.0.1",
]
license = {text = "MIT"}
dynamic = ["version", "optional-dependencies"]
Expand Down
6 changes: 0 additions & 6 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ async-timeout==4.0.3; python_version < "3.11"
attrs==23.2.0
azure-cognitiveservices-speech==1.37.0
beautifulsoup4==4.12.3
bingimagecreator==0.5.0
cachetools==5.3.2
certifi==2024.2.2
charset-normalizer==3.3.2
Expand All @@ -19,7 +18,6 @@ dashscope==1.18.0
dataclasses-json==0.6.3
distro==1.9.0
edge-tts==6.1.10
edgegpt==0.1.26
exceptiongroup==1.2.0; python_version < "3.11"
frozenlist==1.4.1
google-ai-generativelanguage==0.6.2
Expand Down Expand Up @@ -59,7 +57,6 @@ numpy==1.26.3
openai==1.25.1
orjson==3.10.0
packaging==23.2
prompt-toolkit==3.0.43
proto-plus==1.23.0
protobuf==4.25.1
pyasn1==0.5.1
Expand All @@ -70,7 +67,6 @@ pygments==2.17.2
pyjwt==2.8.0
pyparsing==3.1.2; python_version > "3.0"
pyyaml==6.0.1
regex==2023.12.25
requests==2.31.0
rich==13.7.1
rsa==4.9
Expand All @@ -85,7 +81,5 @@ typing-extensions==4.9.0
typing-inspect==0.9.0
uritemplate==4.1.1
urllib3==2.1.0
wcwidth==0.2.13
websockets==12.0
yarl==1.9.4
zhipuai==2.0.1.20240423.1
33 changes: 0 additions & 33 deletions xiao_config.json.example

This file was deleted.

94 changes: 94 additions & 0 deletions xiao_config.yaml.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# This is a YAML configuration file

# 小米设备型号,可在底部标签获得
hardware: LX06
# 小米账号
account: ""
# 小米密码
password: ""
# 小米账户 cookie (如果用上面密码登录可以不填)
cookie: ""
# 设备 DID,参考 https://github.com/yihong0618/MiService
mi_did: ""
# 使用 MI command 与小爱交互
use_command: false
# 快速停掉小爱自己的回答
mute_xiaoai: true
# 是否打印详细日志
verbose: false
# HTTP 代理地址
proxy: ""

# ===== 对话 AI 设置 =====
# 使用的 bot 类型,目前支持 chatgptapi, glm, gemini, langchain, qwen, doubao, moonshot, yi, llama,
bot: chatgptapi
# 自定义 prompt
prompt: "请用100字以内回答"
# 触发词列表
keyword:
- "请"
# 更改提示词触发列表
change_prompt_keyword:
- "更改提示词"
# 开始持续对话关键词
start_conversation: "开始持续对话"
# 结束持续对话关键词
end_conversation: "结束持续对话"
# 使用流式响应,获得更快的响应
stream: true
# 传给 Chatbot completion 接口的参数,比如要使用自定义模型:
# gpt_options:
# model: gpt4-turbo
gpt_options: {}

# ----- OpenAI -----
# OpenAI key
openai_key: ""
# OpenAI API 地址
# 例:OpenAI 代理地址: https://myopenai.com/v1/
# 或:Azure Open AI: https://abc.openai.azure.com/
api_base: "https://abc-def.openai.azure.com/"
# Azure Open AI 的 deployment id(如使用 Azure OpenAI)
deployment_id: ""


# ----- Moonshot(Kimi) -----
# Kimi 的 API key: https://platform.moonshot.cn/docs/api/chat#%E5%BF%AB%E9%80%9F%E5%BC%80%E5%A7%8B
moonshot_api_key: ""

# ----- Yi -----
# 零一万物的 API key: https://platform.lingyiwanwu.com/apikeys
yi_api_key: ""

# ----- Groq(Llama3) -----
# Groq API key: https://console.groq.com/docs/quickstart
llama_api_key: ""

# ----- SerpAPI(Bot 类型为 langchain 时需要) -----
# SerpAPI key: https://serpapi.com/
serpapi_api_key: ""

# ----- 智谱清言(ChatGLM) -----
# ChatGLM API key
glm_key: ""

# ----- Gemini -----
# Gemini key: https://makersuite.google.com/app/apikey
gemini_key: ""
# Gemini 自定义域名: https://github.com/antergone/palm-netlify-proxy
gemini_api_domain: ""

# ----- 通义千问(Qwen) -----
# Qwen API key: https://help.aliyun.com/zh/dashscope/developer-reference/api-details
qwen_key: ""

# ----- 火山(豆包)-----
# 火山引擎的 access key 和 secret key,参考 https://console.volcengine.com/iam/keymanage/
volc_access_key: ""
volc_secret_key: ""

# ===== 语音设置 =====
# 使用的 TTS 类型,目前支持 mi, edge, openai, azure, volc, baidu, google, minimax
tts: mi
# TTS 参数字典,参考 https://github.com/frostming/tetos 获取可用参数
tts_options: {}
7 changes: 2 additions & 5 deletions xiaogpt/bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@
from xiaogpt.bot.gemini_bot import GeminiBot
from xiaogpt.bot.glm_bot import GLMBot
from xiaogpt.bot.langchain_bot import LangChainBot
from xiaogpt.bot.newbing_bot import NewBingBot
from xiaogpt.bot.qwen_bot import QwenBot
from xiaogpt.bot.llama_bot import LlamaBot
from xiaogpt.bot.moonshot_bot import MoonshotBot
from xiaogpt.bot.qwen_bot import QwenBot
from xiaogpt.bot.yi_bot import YiBot
from xiaogpt.bot.llama_bot import LlamaBot
from xiaogpt.config import Config

BOTS: dict[str, type[BaseBot]] = {
"newbing": NewBingBot,
"chatgptapi": ChatGPTBot,
"glm": GLMBot,
"gemini": GeminiBot,
Expand All @@ -36,7 +34,6 @@ def get_bot(config: Config) -> BaseBot:

__all__ = [
"ChatGPTBot",
"NewBingBot",
"GLMBot",
"GeminiBot",
"MoonshotBot",
Expand Down
81 changes: 0 additions & 81 deletions xiaogpt/bot/newbing_bot.py

This file was deleted.

8 changes: 0 additions & 8 deletions xiaogpt/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,6 @@ def main():
const="langchain",
help="if use langchain",
)
bot_group.add_argument(
"--use_newbing",
dest="bot",
action="store_const",
const="newbing",
help="if use newbing",
)
bot_group.add_argument(
"--use_glm",
dest="bot",
Expand Down Expand Up @@ -198,7 +191,6 @@ def main():
help="bot type",
choices=[
"chatgptapi",
"newbing",
"glm",
"gemini",
"langchain",
Expand Down
15 changes: 6 additions & 9 deletions xiaogpt/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
from dataclasses import dataclass, field
from typing import Any, Iterable, Literal

import yaml

from xiaogpt.utils import validate_proxy

LATEST_ASK_API = "https://userprofile.mina.mi.com/device_profile/v2/conversation?source=dialogu&hardware={hardware}&timestamp={timestamp}&limit=2"
Expand Down Expand Up @@ -84,18 +86,10 @@ class Config:
] = "mi"
tts_options: dict[str, Any] = field(default_factory=dict)
gpt_options: dict[str, Any] = field(default_factory=dict)
bing_cookie_path: str = ""
bing_cookies: dict | None = None

def __post_init__(self) -> None:
if self.proxy:
validate_proxy(self.proxy)
if self.bot == "newbing":
if not (self.bing_cookie_path or self.bing_cookies):
raise Exception(
"New bing bot needs bing_cookie_path or bing_cookies, read this: "
"https://github.com/acheong08/EdgeGPT#getting-authentication-required"
)
if (
self.api_base
and self.api_base.endswith(("openai.azure.com", "openai.azure.com/"))
Expand Down Expand Up @@ -140,7 +134,10 @@ def from_options(cls, options: argparse.Namespace) -> Config:
def read_from_file(cls, config_path: str) -> dict:
result = {}
with open(config_path, "rb") as f:
config = json.load(f)
if config_path.endswith(".json"):
config = json.load(f)
else:
config = yaml.safe_load(f)
for key, value in config.items():
if value is None:
continue
Expand Down

0 comments on commit f274ec2

Please sign in to comment.