xiaogpt 2.21__py3-none-any.whl → 2.23__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/bot/bard_bot.py +3 -1
- xiaogpt/bot/chatgptapi_bot.py +6 -2
- xiaogpt/bot/gemini_bot.py +3 -2
- xiaogpt/bot/glm_bot.py +29 -9
- xiaogpt/bot/gpt3_bot.py +4 -1
- xiaogpt/bot/newbing_bot.py +6 -2
- xiaogpt/bot/qwen_bot.py +13 -8
- xiaogpt/cli.py +2 -2
- xiaogpt/langchain/examples/email/mail_box.py +6 -4
- xiaogpt/tts/openai.py +6 -1
- {xiaogpt-2.21.dist-info → xiaogpt-2.23.dist-info}/METADATA +2 -2
- {xiaogpt-2.21.dist-info → xiaogpt-2.23.dist-info}/RECORD +15 -15
- {xiaogpt-2.21.dist-info → xiaogpt-2.23.dist-info}/WHEEL +0 -0
- {xiaogpt-2.21.dist-info → xiaogpt-2.23.dist-info}/entry_points.txt +0 -0
- {xiaogpt-2.21.dist-info → xiaogpt-2.23.dist-info}/licenses/LICENSE +0 -0
xiaogpt/bot/bard_bot.py
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
"""ChatGLM bot"""
|
2
|
+
|
2
3
|
from __future__ import annotations
|
3
4
|
|
4
5
|
from typing import Any
|
5
6
|
|
6
|
-
from bardapi import BardAsync
|
7
7
|
from rich import print
|
8
8
|
|
9
9
|
from xiaogpt.bot.base_bot import BaseBot, ChatHistoryMixin
|
@@ -16,6 +16,8 @@ class BardBot(ChatHistoryMixin, BaseBot):
|
|
16
16
|
self,
|
17
17
|
bard_token: str,
|
18
18
|
) -> None:
|
19
|
+
from bardapi import BardAsync
|
20
|
+
|
19
21
|
self._bot = BardAsync(token=bard_token)
|
20
22
|
self.history = []
|
21
23
|
|
xiaogpt/bot/chatgptapi_bot.py
CHANGED
@@ -1,15 +1,17 @@
|
|
1
1
|
from __future__ import annotations
|
2
2
|
|
3
3
|
import dataclasses
|
4
|
-
from typing import ClassVar
|
4
|
+
from typing import TYPE_CHECKING, ClassVar
|
5
5
|
|
6
6
|
import httpx
|
7
|
-
import openai
|
8
7
|
from rich import print
|
9
8
|
|
10
9
|
from xiaogpt.bot.base_bot import BaseBot, ChatHistoryMixin
|
11
10
|
from xiaogpt.utils import split_sentences
|
12
11
|
|
12
|
+
if TYPE_CHECKING:
|
13
|
+
import openai
|
14
|
+
|
13
15
|
|
14
16
|
@dataclasses.dataclass
|
15
17
|
class ChatGPTBot(ChatHistoryMixin, BaseBot):
|
@@ -22,6 +24,8 @@ class ChatGPTBot(ChatHistoryMixin, BaseBot):
|
|
22
24
|
history: list[tuple[str, str]] = dataclasses.field(default_factory=list, init=False)
|
23
25
|
|
24
26
|
def _make_openai_client(self, sess: httpx.AsyncClient) -> openai.AsyncOpenAI:
|
27
|
+
import openai
|
28
|
+
|
25
29
|
if self.api_base and self.api_base.rstrip("/").endswith("openai.azure.com"):
|
26
30
|
return openai.AsyncAzureOpenAI(
|
27
31
|
api_key=self.openai_key,
|
xiaogpt/bot/gemini_bot.py
CHANGED
@@ -1,11 +1,10 @@
|
|
1
1
|
"""Google Gemini bot"""
|
2
|
+
|
2
3
|
from __future__ import annotations
|
3
4
|
|
4
5
|
from typing import Any
|
5
6
|
|
6
7
|
from rich import print
|
7
|
-
import google.generativeai as genai
|
8
|
-
from google.generativeai.types.generation_types import StopCandidateException
|
9
8
|
|
10
9
|
from xiaogpt.bot.base_bot import BaseBot, ChatHistoryMixin
|
11
10
|
|
@@ -34,6 +33,8 @@ class GeminiBot(ChatHistoryMixin, BaseBot):
|
|
34
33
|
name = "Gemini"
|
35
34
|
|
36
35
|
def __init__(self, gemini_key: str) -> None:
|
36
|
+
import google.generativeai as genai
|
37
|
+
|
37
38
|
genai.configure(api_key=gemini_key)
|
38
39
|
self.history = []
|
39
40
|
model = genai.GenerativeModel(
|
xiaogpt/bot/glm_bot.py
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
"""ChatGLM bot"""
|
2
|
+
|
2
3
|
from __future__ import annotations
|
3
4
|
|
4
5
|
from typing import Any
|
5
6
|
|
6
|
-
import zhipuai
|
7
7
|
from rich import print
|
8
8
|
|
9
9
|
from xiaogpt.bot.base_bot import BaseBot, ChatHistoryMixin
|
@@ -14,8 +14,12 @@ class GLMBot(ChatHistoryMixin, BaseBot):
|
|
14
14
|
default_options = {"model": "chatglm_turbo"}
|
15
15
|
|
16
16
|
def __init__(self, glm_key: str) -> None:
|
17
|
+
from zhipuai import ZhipuAI
|
18
|
+
|
19
|
+
self.model = "glm-4" # Change glm model here
|
20
|
+
|
17
21
|
self.history = []
|
18
|
-
|
22
|
+
self.client = ZhipuAI(api_key=glm_key)
|
19
23
|
|
20
24
|
@classmethod
|
21
25
|
def from_config(cls, config):
|
@@ -24,20 +28,36 @@ class GLMBot(ChatHistoryMixin, BaseBot):
|
|
24
28
|
def ask(self, query, **options):
|
25
29
|
ms = self.get_messages()
|
26
30
|
kwargs = {**self.default_options, **options}
|
27
|
-
kwargs["
|
31
|
+
kwargs["model"] = self.model
|
28
32
|
ms.append({"role": "user", "content": f"{query}"})
|
33
|
+
kwargs["messages"] = ms
|
29
34
|
try:
|
30
|
-
r =
|
35
|
+
r = self.client.chat.completions.create(**kwargs)
|
31
36
|
except Exception as e:
|
32
37
|
print(str(e))
|
33
38
|
return
|
34
|
-
message =
|
35
|
-
for i in r.events():
|
36
|
-
message += str(i.data)
|
39
|
+
message = r.choices[0].message.content
|
37
40
|
|
38
41
|
self.add_message(query, message)
|
39
42
|
print(message)
|
40
43
|
return message
|
41
44
|
|
42
|
-
def ask_stream(self, query: str, **options: Any):
|
43
|
-
|
45
|
+
async def ask_stream(self, query: str, **options: Any):
|
46
|
+
ms = self.get_messages()
|
47
|
+
kwargs = {**self.default_options, **options}
|
48
|
+
kwargs["model"] = self.model
|
49
|
+
ms.append({"role": "user", "content": f"{query}"})
|
50
|
+
kwargs["messages"] = ms
|
51
|
+
kwargs["stream"] = True
|
52
|
+
try:
|
53
|
+
r = self.client.chat.completions.create(**kwargs)
|
54
|
+
except Exception as e:
|
55
|
+
print(str(e))
|
56
|
+
return
|
57
|
+
full_content = ""
|
58
|
+
for chunk in r:
|
59
|
+
content = chunk.choices[0].delta.content
|
60
|
+
full_content += content
|
61
|
+
print(content, end="")
|
62
|
+
yield content
|
63
|
+
self.add_message(query, full_content)
|
xiaogpt/bot/gpt3_bot.py
CHANGED
@@ -4,7 +4,6 @@ import dataclasses
|
|
4
4
|
from typing import ClassVar
|
5
5
|
|
6
6
|
import httpx
|
7
|
-
import openai
|
8
7
|
from rich import print
|
9
8
|
|
10
9
|
from xiaogpt.bot.base_bot import BaseBot, ChatHistoryMixin
|
@@ -26,6 +25,8 @@ class GPT3Bot(ChatHistoryMixin, BaseBot):
|
|
26
25
|
)
|
27
26
|
|
28
27
|
async def ask(self, query, **options):
|
28
|
+
import openai
|
29
|
+
|
29
30
|
data = {
|
30
31
|
"prompt": query,
|
31
32
|
"model": "text-davinci-003",
|
@@ -50,6 +51,8 @@ class GPT3Bot(ChatHistoryMixin, BaseBot):
|
|
50
51
|
return completion.choices[0].text
|
51
52
|
|
52
53
|
async def ask_stream(self, query, **options):
|
54
|
+
import openai
|
55
|
+
|
53
56
|
data = {
|
54
57
|
"prompt": query,
|
55
58
|
"model": "text-davinci-003",
|
xiaogpt/bot/newbing_bot.py
CHANGED
@@ -2,8 +2,6 @@ from __future__ import annotations
|
|
2
2
|
|
3
3
|
import re
|
4
4
|
|
5
|
-
from EdgeGPT import Chatbot, ConversationStyle
|
6
|
-
|
7
5
|
from xiaogpt.bot.base_bot import BaseBot, ChatHistoryMixin
|
8
6
|
from xiaogpt.utils import split_sentences
|
9
7
|
|
@@ -19,6 +17,8 @@ class NewBingBot(ChatHistoryMixin, BaseBot):
|
|
19
17
|
bing_cookies: dict | None = None,
|
20
18
|
proxy: str | None = None,
|
21
19
|
):
|
20
|
+
from EdgeGPT import Chatbot
|
21
|
+
|
22
22
|
self.history = []
|
23
23
|
self._bot = Chatbot(
|
24
24
|
cookiePath=bing_cookie_path, cookies=bing_cookies, proxy=proxy
|
@@ -40,6 +40,8 @@ class NewBingBot(ChatHistoryMixin, BaseBot):
|
|
40
40
|
return s.strip()
|
41
41
|
|
42
42
|
async def ask(self, query, **options):
|
43
|
+
from EdgeGPT import ConversationStyle
|
44
|
+
|
43
45
|
kwargs = {"conversation_style": ConversationStyle.balanced, **options}
|
44
46
|
completion = await self._bot.ask(prompt=query, **kwargs)
|
45
47
|
try:
|
@@ -51,6 +53,8 @@ class NewBingBot(ChatHistoryMixin, BaseBot):
|
|
51
53
|
return text
|
52
54
|
|
53
55
|
async def ask_stream(self, query, **options):
|
56
|
+
from EdgeGPT import ConversationStyle
|
57
|
+
|
54
58
|
kwargs = {"conversation_style": ConversationStyle.balanced, **options}
|
55
59
|
try:
|
56
60
|
completion = self._bot.ask_stream(prompt=query, **kwargs)
|
xiaogpt/bot/qwen_bot.py
CHANGED
@@ -1,12 +1,10 @@
|
|
1
|
-
"""
|
1
|
+
"""Qwen bot"""
|
2
|
+
|
2
3
|
from __future__ import annotations
|
3
4
|
|
5
|
+
from http import HTTPStatus
|
4
6
|
from typing import Any
|
5
7
|
|
6
|
-
from http import HTTPStatus
|
7
|
-
import dashscope
|
8
|
-
from dashscope import Generation
|
9
|
-
from dashscope.api_entities.dashscope_response import Role
|
10
8
|
from rich import print
|
11
9
|
|
12
10
|
from xiaogpt.bot.base_bot import BaseBot, ChatHistoryMixin
|
@@ -16,9 +14,10 @@ class QwenBot(ChatHistoryMixin, BaseBot):
|
|
16
14
|
name = "Qian Wen"
|
17
15
|
|
18
16
|
def __init__(self, qwen_key: str) -> None:
|
19
|
-
|
20
|
-
|
21
|
-
|
17
|
+
import dashscope
|
18
|
+
from dashscope.api_entities.dashscope_response import Role
|
19
|
+
|
20
|
+
self.history = []
|
22
21
|
dashscope.api_key = qwen_key
|
23
22
|
|
24
23
|
@classmethod
|
@@ -26,6 +25,9 @@ class QwenBot(ChatHistoryMixin, BaseBot):
|
|
26
25
|
return cls(qwen_key=config.qwen_key)
|
27
26
|
|
28
27
|
async def ask(self, query, **options):
|
28
|
+
from dashscope import Generation
|
29
|
+
from dashscope.api_entities.dashscope_response import Role
|
30
|
+
|
29
31
|
# from https://help.aliyun.com/zh/dashscope/developer-reference/api-details
|
30
32
|
self.history.append({"role": Role.USER, "content": query})
|
31
33
|
|
@@ -61,6 +63,9 @@ class QwenBot(ChatHistoryMixin, BaseBot):
|
|
61
63
|
return "没有返回"
|
62
64
|
|
63
65
|
async def ask_stream(self, query: str, **options: Any):
|
66
|
+
from dashscope import Generation
|
67
|
+
from dashscope.api_entities.dashscope_response import Role
|
68
|
+
|
64
69
|
self.history.append({"role": Role.USER, "content": query})
|
65
70
|
responses = Generation.call(
|
66
71
|
Generation.Models.qwen_turbo,
|
xiaogpt/cli.py
CHANGED
@@ -195,8 +195,8 @@ def main():
|
|
195
195
|
)
|
196
196
|
|
197
197
|
options = parser.parse_args()
|
198
|
-
if options.bot in ["
|
199
|
-
raise Exception("For now
|
198
|
+
if options.bot in ["bard"] and options.stream:
|
199
|
+
raise Exception("For now Bard do not support stream")
|
200
200
|
config = Config.from_options(options)
|
201
201
|
|
202
202
|
miboy = MiGPT(config)
|
@@ -1,13 +1,13 @@
|
|
1
|
-
import imaplib
|
2
1
|
import email
|
3
|
-
from datetime import datetime, timedelta
|
4
2
|
import html
|
5
|
-
|
3
|
+
import imaplib
|
6
4
|
import re
|
7
|
-
import openai
|
8
5
|
import smtplib
|
6
|
+
from datetime import datetime, timedelta
|
9
7
|
from email.mime.text import MIMEText
|
10
8
|
|
9
|
+
from bs4 import BeautifulSoup
|
10
|
+
|
11
11
|
|
12
12
|
class Mailbox:
|
13
13
|
# Gmail account settings need to be configured
|
@@ -115,6 +115,8 @@ class Mailbox:
|
|
115
115
|
return ""
|
116
116
|
|
117
117
|
def get_summary_by_ai(self, email_content: str, prompt: str) -> str:
|
118
|
+
import openai
|
119
|
+
|
118
120
|
print("Asking AI to summarize email content...")
|
119
121
|
|
120
122
|
# Request ChatGPT for summary
|
xiaogpt/tts/openai.py
CHANGED
@@ -2,13 +2,16 @@ from __future__ import annotations
|
|
2
2
|
|
3
3
|
import tempfile
|
4
4
|
from pathlib import Path
|
5
|
+
from typing import TYPE_CHECKING
|
5
6
|
|
6
7
|
import httpx
|
7
|
-
import openai
|
8
8
|
|
9
9
|
from xiaogpt.tts.base import AudioFileTTS
|
10
10
|
from xiaogpt.utils import calculate_tts_elapse
|
11
11
|
|
12
|
+
if TYPE_CHECKING:
|
13
|
+
import openai
|
14
|
+
|
12
15
|
|
13
16
|
class OpenAITTS(AudioFileTTS):
|
14
17
|
default_voice = "alloy"
|
@@ -32,6 +35,8 @@ class OpenAITTS(AudioFileTTS):
|
|
32
35
|
return Path(output_file.name), calculate_tts_elapse(text)
|
33
36
|
|
34
37
|
def _make_openai_client(self, sess: httpx.AsyncClient) -> openai.AsyncOpenAI:
|
38
|
+
import openai
|
39
|
+
|
35
40
|
api_base = self.config.api_base
|
36
41
|
if api_base and api_base.rstrip("/").endswith("openai.azure.com"):
|
37
42
|
raise NotImplementedError("TTS is not supported for Azure OpenAI")
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: xiaogpt
|
3
|
-
Version: 2.
|
3
|
+
Version: 2.23
|
4
4
|
Summary: Play ChatGPT or other LLM with xiaomi AI speaker
|
5
5
|
Author-Email: yihong0618 <zouzou0208@gmail.com>
|
6
6
|
License: MIT
|
@@ -13,7 +13,7 @@ Requires-Dist: miservice_fork
|
|
13
13
|
Requires-Dist: openai>=1
|
14
14
|
Requires-Dist: aiohttp
|
15
15
|
Requires-Dist: rich
|
16
|
-
Requires-Dist: zhipuai
|
16
|
+
Requires-Dist: zhipuai==2.0.1
|
17
17
|
Requires-Dist: bardapi
|
18
18
|
Requires-Dist: edge-tts>=6.1.3
|
19
19
|
Requires-Dist: EdgeGPT==0.1.26
|
@@ -1,30 +1,30 @@
|
|
1
|
-
xiaogpt-2.
|
2
|
-
xiaogpt-2.
|
3
|
-
xiaogpt-2.
|
4
|
-
xiaogpt-2.
|
1
|
+
xiaogpt-2.23.dist-info/METADATA,sha256=pV5ExJ_7YpAmcJg6iK5dukVjN4haD59AYx4NIOdMhzY,18887
|
2
|
+
xiaogpt-2.23.dist-info/WHEEL,sha256=N2J68yzZqJh3mI_Wg92rwhw0rtJDFpZj9bwQIMJgaVg,90
|
3
|
+
xiaogpt-2.23.dist-info/entry_points.txt,sha256=zLFzA72qQ_eWBepdA2YU5vdXFqORH8wXhv2Ox1vnYP8,46
|
4
|
+
xiaogpt-2.23.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=O3Wq7WRwTVdKJdKZxkBtCPdRJ8uXrQE0dqHa1ekOnfQ,1073
|
8
|
-
xiaogpt/bot/bard_bot.py,sha256=
|
8
|
+
xiaogpt/bot/bard_bot.py,sha256=qC8m87mWvtbiwipKl_OMYCqRbh79gkyZEytgz5DysC0,840
|
9
9
|
xiaogpt/bot/base_bot.py,sha256=oKn6LLFHXol4hKrSrjnxknrOqrcGICtT_GPPYRNxpkw,1467
|
10
|
-
xiaogpt/bot/chatgptapi_bot.py,sha256=
|
11
|
-
xiaogpt/bot/gemini_bot.py,sha256=
|
12
|
-
xiaogpt/bot/glm_bot.py,sha256=
|
13
|
-
xiaogpt/bot/gpt3_bot.py,sha256=
|
10
|
+
xiaogpt/bot/chatgptapi_bot.py,sha256=Z4FX7F6j2n6NoUCqH6LliAAew94zaQXzp1blsE5yKoc,3656
|
11
|
+
xiaogpt/bot/gemini_bot.py,sha256=udKrWYP7U83AWpNBggwRp9bvgR2DTHqLMX9E_DLFv-I,1840
|
12
|
+
xiaogpt/bot/glm_bot.py,sha256=QoMJbnu5_rHDz4tzwn7gh3IoAuw7E4hZQLAfziMAvNY,1825
|
13
|
+
xiaogpt/bot/gpt3_bot.py,sha256=enX45_wrGjAtOh-anf8KnjCJluWSARZbjTGD_WZgoms,2781
|
14
14
|
xiaogpt/bot/langchain_bot.py,sha256=4Uz5iOYzA2ongCklS-9zBse2fw-7kEE_9wITH7wdVCc,1944
|
15
|
-
xiaogpt/bot/newbing_bot.py,sha256=
|
16
|
-
xiaogpt/bot/qwen_bot.py,sha256=
|
17
|
-
xiaogpt/cli.py,sha256=
|
15
|
+
xiaogpt/bot/newbing_bot.py,sha256=afUmw6tyMXbgGZvfQQWaA5h0-e0V0isFolW-WGhd0Vs,2289
|
16
|
+
xiaogpt/bot/qwen_bot.py,sha256=n0WIeixAisd2_Vvky18FQFGcDIF3Cc2q2qp4ExCNBho,3521
|
17
|
+
xiaogpt/cli.py,sha256=aLmpwjYw6tKPNy-WPZIE2XD5oLHsjSksova_PpH85II,5057
|
18
18
|
xiaogpt/config.py,sha256=uo82JTKhujet0ro2SN3cOw2GXE-AamyzL7EmeFiGS5o,6287
|
19
19
|
xiaogpt/langchain/callbacks.py,sha256=yR9AXQt9OHVYBWC47Q1I_BUT4Xg9iM44vnW2vv0BLpE,2616
|
20
20
|
xiaogpt/langchain/chain.py,sha256=z0cqRlL0ElWnf31ByxZBN7AKOT-svXQDt5_NDft_nYc,1495
|
21
|
-
xiaogpt/langchain/examples/email/mail_box.py,sha256=
|
21
|
+
xiaogpt/langchain/examples/email/mail_box.py,sha256=xauqrjE4-G4XPQnokUPE-MZgAaHQ_VrUDLlbfYTdCoo,6372
|
22
22
|
xiaogpt/langchain/examples/email/mail_summary_tools.py,sha256=6cWvBJUaA7iaywcHdbUoww8WiCtaNw3TmwyxyF4DY7E,1561
|
23
23
|
xiaogpt/tts/__init__.py,sha256=UDMNJTobFrw3Ichhvck6rHU-oREnoj8RUC_E3M9dMU8,130
|
24
24
|
xiaogpt/tts/base.py,sha256=6VlTqQ_RJBbTb-perlMsnKg2qwfgKj4ELhzbdF0HD6c,4922
|
25
25
|
xiaogpt/tts/edge.py,sha256=yMFGxRTi086XS1d_mbMzQ365bvG4KgAz8ZptaoDAfGU,1172
|
26
26
|
xiaogpt/tts/mi.py,sha256=9HkgGWByAs7k8sTpRdVlgJnnmjc44RNAccJa6tGDlXk,1096
|
27
|
-
xiaogpt/tts/openai.py,sha256=
|
27
|
+
xiaogpt/tts/openai.py,sha256=_Qk12zYY-UuXLKvQVe3PqIvCmoRW9OcVCqQRoGCXvNc,1533
|
28
28
|
xiaogpt/utils.py,sha256=B7NCH7g19hcwHDXsnBJPTU6UcWnXoEntKWm-pgcet2I,2072
|
29
29
|
xiaogpt/xiaogpt.py,sha256=_viWq5w4-rGCTsuDetPPih-4qkPZem9FtXK-tPyChlA,15473
|
30
|
-
xiaogpt-2.
|
30
|
+
xiaogpt-2.23.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|