xiaogpt 2.83__py3-none-any.whl → 2.84__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- xiaogpt/utils.py +22 -1
- xiaogpt/xiaogpt.py +6 -20
- {xiaogpt-2.83.dist-info → xiaogpt-2.84.dist-info}/METADATA +5 -2
- {xiaogpt-2.83.dist-info → xiaogpt-2.84.dist-info}/RECORD +7 -7
- {xiaogpt-2.83.dist-info → xiaogpt-2.84.dist-info}/WHEEL +0 -0
- {xiaogpt-2.83.dist-info → xiaogpt-2.84.dist-info}/entry_points.txt +0 -0
- {xiaogpt-2.83.dist-info → xiaogpt-2.84.dist-info}/licenses/LICENSE +0 -0
xiaogpt/utils.py
CHANGED
@@ -5,11 +5,14 @@ import os
|
|
5
5
|
import re
|
6
6
|
import socket
|
7
7
|
from http.cookies import SimpleCookie
|
8
|
-
from typing import AsyncIterator
|
8
|
+
from typing import TYPE_CHECKING, AsyncIterator
|
9
9
|
from urllib.parse import urlparse
|
10
10
|
|
11
11
|
from requests.utils import cookiejar_from_dict
|
12
12
|
|
13
|
+
if TYPE_CHECKING:
|
14
|
+
from lingua import LanguageDetector
|
15
|
+
|
13
16
|
|
14
17
|
### HELP FUNCTION ###
|
15
18
|
def parse_cookie_string(cookie_string):
|
@@ -69,3 +72,21 @@ def get_hostname() -> str:
|
|
69
72
|
with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as s:
|
70
73
|
s.connect(("8.8.8.8", 80))
|
71
74
|
return s.getsockname()[0]
|
75
|
+
|
76
|
+
|
77
|
+
def _get_detector() -> LanguageDetector | None:
|
78
|
+
try:
|
79
|
+
from lingua import LanguageDetectorBuilder
|
80
|
+
except ImportError:
|
81
|
+
return None
|
82
|
+
return LanguageDetectorBuilder.from_all_spoken_languages().build()
|
83
|
+
|
84
|
+
|
85
|
+
_detector = _get_detector()
|
86
|
+
|
87
|
+
|
88
|
+
def detect_language(text: str) -> str:
|
89
|
+
if _detector is None:
|
90
|
+
return "zh" # default to Chinese if langdetect module is not available
|
91
|
+
lang = _detector.detect_language_of(text)
|
92
|
+
return lang.iso_code_639_1.name.lower() if lang is not None else "zh"
|
xiaogpt/xiaogpt.py
CHANGED
@@ -24,9 +24,7 @@ from xiaogpt.config import (
|
|
24
24
|
Config,
|
25
25
|
)
|
26
26
|
from xiaogpt.tts import TTS, MiTTS, TetosTTS
|
27
|
-
from xiaogpt.utils import
|
28
|
-
parse_cookie_string,
|
29
|
-
)
|
27
|
+
from xiaogpt.utils import detect_language, parse_cookie_string
|
30
28
|
|
31
29
|
EOF = object()
|
32
30
|
|
@@ -390,11 +388,6 @@ class MiGPT:
|
|
390
388
|
query = f"{query},{self.config.prompt}"
|
391
389
|
# some model can not detect the language code, so we need to add it
|
392
390
|
|
393
|
-
if self.config.tts != "mi": # mi only say Chinese
|
394
|
-
query += (
|
395
|
-
",并用本段话的language code作为开头,用|分隔,如:en-US|你好……"
|
396
|
-
)
|
397
|
-
|
398
391
|
if self.config.mute_xiaoai:
|
399
392
|
await self.stop_if_xiaoai_is_playing()
|
400
393
|
else:
|
@@ -420,18 +413,11 @@ class MiGPT:
|
|
420
413
|
await self.wakeup_xiaoai()
|
421
414
|
|
422
415
|
async def speak(self, text_stream: AsyncIterator[str]) -> None:
|
423
|
-
|
424
|
-
#
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
lang, first_chunk = "", text
|
429
|
-
|
430
|
-
lang = (
|
431
|
-
matches[0]
|
432
|
-
if (matches := re.findall(r"([a-z]{2}-[A-Z]{2})", lang))
|
433
|
-
else "zh-CN"
|
434
|
-
)
|
416
|
+
first_chunk = await text_stream.__anext__()
|
417
|
+
# Detect the language from the first chunk
|
418
|
+
# Add suffix '-' because tetos expects it to exist when selecting voices
|
419
|
+
# however, the nation code is never used.
|
420
|
+
lang = detect_language(first_chunk) + "-"
|
435
421
|
|
436
422
|
async def gen(): # reconstruct the generator
|
437
423
|
yield first_chunk
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: xiaogpt
|
3
|
-
Version: 2.
|
3
|
+
Version: 2.84
|
4
4
|
Summary: Play ChatGPT or other LLM with xiaomi AI speaker
|
5
5
|
Author-Email: yihong0618 <zouzou0208@gmail.com>
|
6
6
|
License: MIT
|
@@ -25,6 +25,7 @@ Requires-Dist: tetos>=0.2.1
|
|
25
25
|
Requires-Dist: groq>=0.5.0
|
26
26
|
Requires-Dist: pyyaml>=6.0.1
|
27
27
|
Requires-Dist: langchain-community>=0.0.38
|
28
|
+
Requires-Dist: lingua-language-detector>=2.0.2; python_version < "3.13"
|
28
29
|
Requires-Dist: aiohttp==3.9.5; extra == "locked"
|
29
30
|
Requires-Dist: aiosignal==1.3.1; extra == "locked"
|
30
31
|
Requires-Dist: annotated-types==0.6.0; extra == "locked"
|
@@ -71,6 +72,7 @@ Requires-Dist: langchain-community==0.2.0; extra == "locked"
|
|
71
72
|
Requires-Dist: langchain-core==0.2.0; extra == "locked"
|
72
73
|
Requires-Dist: langchain-text-splitters==0.2.0; extra == "locked"
|
73
74
|
Requires-Dist: langsmith==0.1.45; extra == "locked"
|
75
|
+
Requires-Dist: lingua-language-detector==2.0.2; python_version < "3.13" and extra == "locked"
|
74
76
|
Requires-Dist: markdown-it-py==3.0.0; extra == "locked"
|
75
77
|
Requires-Dist: marshmallow==3.20.1; extra == "locked"
|
76
78
|
Requires-Dist: mdurl==0.1.2; extra == "locked"
|
@@ -420,9 +422,10 @@ docker run -v <your-config-dir>:/config -p 9527:9527 -e XIAOGPT_HOSTNAME=<your i
|
|
420
422
|
|
421
423
|
注意端口必须映射为与容器内一致,XIAOGPT_HOSTNAME 需要设置为宿主机的 IP 地址,否则小爱无法正常播放语音。
|
422
424
|
|
423
|
-
##
|
425
|
+
## 推荐的类似项目
|
424
426
|
|
425
427
|
- [XiaoBot](https://github.com/longbai/xiaobot) -> Go语言版本的Fork, 带支持不同平台的UI
|
428
|
+
- [MiGPT](https://github.com/idootop/mi-gpt) -> Node.js 版,支持流式响应和长短期记忆
|
426
429
|
|
427
430
|
## 感谢
|
428
431
|
|
@@ -1,7 +1,7 @@
|
|
1
|
-
xiaogpt-2.
|
2
|
-
xiaogpt-2.
|
3
|
-
xiaogpt-2.
|
4
|
-
xiaogpt-2.
|
1
|
+
xiaogpt-2.84.dist-info/METADATA,sha256=8e1CykmWgHpBPc8GwcJPlGlwEbve_qqOdNYLZBjI9X0,29950
|
2
|
+
xiaogpt-2.84.dist-info/WHEEL,sha256=vnE8JVcI2Wz7GRKorsPArnBdnW2SWKWGow5gu5tHlRU,90
|
3
|
+
xiaogpt-2.84.dist-info/entry_points.txt,sha256=zLFzA72qQ_eWBepdA2YU5vdXFqORH8wXhv2Ox1vnYP8,46
|
4
|
+
xiaogpt-2.84.dist-info/licenses/LICENSE,sha256=XdClh516MvlnOf9749JZHCxSB7y6_fyXcWmLDz6IkZY,1063
|
5
5
|
xiaogpt/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
6
6
|
xiaogpt/__main__.py,sha256=MSmt_5Xg84uHqzTN38JwgseJK8rsJn_11A8WD99VtEo,61
|
7
7
|
xiaogpt/bot/__init__.py,sha256=BDGvj1JuWVw47qfREWGKnSXeiFg6DVJJAz2rHVryqmc,1160
|
@@ -25,6 +25,6 @@ xiaogpt/tts/__init__.py,sha256=xasHDrmgECirf1MSyrfURSaMBqtdZBi3cQNeDvPo_cQ,145
|
|
25
25
|
xiaogpt/tts/base.py,sha256=k0ZUcLJZWU5U_fXu_w-cLFgZpE2KkV89ARbVDXLqTck,4665
|
26
26
|
xiaogpt/tts/mi.py,sha256=1MzCB27DBohPQ_4Xz4W_FV9p-chJFDavOHB89NviLcM,1095
|
27
27
|
xiaogpt/tts/tetos.py,sha256=fkuOSYGqAfJyyPEXbsiOS--CewGf1JUiahoN33nzOAA,1058
|
28
|
-
xiaogpt/utils.py,sha256=
|
29
|
-
xiaogpt/xiaogpt.py,sha256=
|
30
|
-
xiaogpt-2.
|
28
|
+
xiaogpt/utils.py,sha256=YYmRDNtccxqB9gyN_xhKZwgL1_PNYEp7So_-jt2tiVg,2668
|
29
|
+
xiaogpt/xiaogpt.py,sha256=3Q8Au9QcJy1fRGrMd0XKYbUn9_uKvVPce8PE-DA6heg,16153
|
30
|
+
xiaogpt-2.84.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|