xiaogpt 2.21__tar.gz → 2.23__tar.gz

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.
Files changed (30) hide show
  1. {xiaogpt-2.21 → xiaogpt-2.23}/PKG-INFO +2 -2
  2. {xiaogpt-2.21 → xiaogpt-2.23}/pyproject.toml +2 -2
  3. {xiaogpt-2.21 → xiaogpt-2.23}/xiaogpt/bot/bard_bot.py +3 -1
  4. {xiaogpt-2.21 → xiaogpt-2.23}/xiaogpt/bot/chatgptapi_bot.py +6 -2
  5. {xiaogpt-2.21 → xiaogpt-2.23}/xiaogpt/bot/gemini_bot.py +3 -2
  6. xiaogpt-2.23/xiaogpt/bot/glm_bot.py +63 -0
  7. {xiaogpt-2.21 → xiaogpt-2.23}/xiaogpt/bot/gpt3_bot.py +4 -1
  8. {xiaogpt-2.21 → xiaogpt-2.23}/xiaogpt/bot/newbing_bot.py +6 -2
  9. {xiaogpt-2.21 → xiaogpt-2.23}/xiaogpt/bot/qwen_bot.py +13 -8
  10. {xiaogpt-2.21 → xiaogpt-2.23}/xiaogpt/cli.py +2 -2
  11. {xiaogpt-2.21 → xiaogpt-2.23}/xiaogpt/langchain/examples/email/mail_box.py +6 -4
  12. {xiaogpt-2.21 → xiaogpt-2.23}/xiaogpt/tts/openai.py +6 -1
  13. xiaogpt-2.21/xiaogpt/bot/glm_bot.py +0 -43
  14. {xiaogpt-2.21 → xiaogpt-2.23}/LICENSE +0 -0
  15. {xiaogpt-2.21 → xiaogpt-2.23}/README.md +0 -0
  16. {xiaogpt-2.21 → xiaogpt-2.23}/xiaogpt/__init__.py +0 -0
  17. {xiaogpt-2.21 → xiaogpt-2.23}/xiaogpt/__main__.py +0 -0
  18. {xiaogpt-2.21 → xiaogpt-2.23}/xiaogpt/bot/__init__.py +0 -0
  19. {xiaogpt-2.21 → xiaogpt-2.23}/xiaogpt/bot/base_bot.py +0 -0
  20. {xiaogpt-2.21 → xiaogpt-2.23}/xiaogpt/bot/langchain_bot.py +0 -0
  21. {xiaogpt-2.21 → xiaogpt-2.23}/xiaogpt/config.py +0 -0
  22. {xiaogpt-2.21 → xiaogpt-2.23}/xiaogpt/langchain/callbacks.py +0 -0
  23. {xiaogpt-2.21 → xiaogpt-2.23}/xiaogpt/langchain/chain.py +0 -0
  24. {xiaogpt-2.21 → xiaogpt-2.23}/xiaogpt/langchain/examples/email/mail_summary_tools.py +0 -0
  25. {xiaogpt-2.21 → xiaogpt-2.23}/xiaogpt/tts/__init__.py +0 -0
  26. {xiaogpt-2.21 → xiaogpt-2.23}/xiaogpt/tts/base.py +0 -0
  27. {xiaogpt-2.21 → xiaogpt-2.23}/xiaogpt/tts/edge.py +0 -0
  28. {xiaogpt-2.21 → xiaogpt-2.23}/xiaogpt/tts/mi.py +0 -0
  29. {xiaogpt-2.21 → xiaogpt-2.23}/xiaogpt/utils.py +0 -0
  30. {xiaogpt-2.21 → xiaogpt-2.23}/xiaogpt/xiaogpt.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: xiaogpt
3
- Version: 2.21
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
@@ -16,7 +16,7 @@ dependencies = [
16
16
  "openai>=1",
17
17
  "aiohttp",
18
18
  "rich",
19
- "zhipuai",
19
+ "zhipuai==2.0.1",
20
20
  "bardapi",
21
21
  "edge-tts>=6.1.3",
22
22
  "EdgeGPT==0.1.26",
@@ -28,7 +28,7 @@ dependencies = [
28
28
  "dashscope==1.10.0",
29
29
  ]
30
30
  dynamic = []
31
- version = "2.21"
31
+ version = "2.23"
32
32
 
33
33
  [project.license]
34
34
  text = "MIT"
@@ -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
 
@@ -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,
@@ -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(
@@ -0,0 +1,63 @@
1
+ """ChatGLM bot"""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import Any
6
+
7
+ from rich import print
8
+
9
+ from xiaogpt.bot.base_bot import BaseBot, ChatHistoryMixin
10
+
11
+
12
+ class GLMBot(ChatHistoryMixin, BaseBot):
13
+ name = "Chat GLM"
14
+ default_options = {"model": "chatglm_turbo"}
15
+
16
+ def __init__(self, glm_key: str) -> None:
17
+ from zhipuai import ZhipuAI
18
+
19
+ self.model = "glm-4" # Change glm model here
20
+
21
+ self.history = []
22
+ self.client = ZhipuAI(api_key=glm_key)
23
+
24
+ @classmethod
25
+ def from_config(cls, config):
26
+ return cls(glm_key=config.glm_key)
27
+
28
+ def ask(self, query, **options):
29
+ ms = self.get_messages()
30
+ kwargs = {**self.default_options, **options}
31
+ kwargs["model"] = self.model
32
+ ms.append({"role": "user", "content": f"{query}"})
33
+ kwargs["messages"] = ms
34
+ try:
35
+ r = self.client.chat.completions.create(**kwargs)
36
+ except Exception as e:
37
+ print(str(e))
38
+ return
39
+ message = r.choices[0].message.content
40
+
41
+ self.add_message(query, message)
42
+ print(message)
43
+ return message
44
+
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)
@@ -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",
@@ -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)
@@ -1,12 +1,10 @@
1
- """ChatGLM bot"""
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
- self.history = [
20
- {"role": Role.SYSTEM, "content": "You are a helpful assistant."}
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,
@@ -195,8 +195,8 @@ def main():
195
195
  )
196
196
 
197
197
  options = parser.parse_args()
198
- if options.bot in ["glm", "bard"] and options.stream:
199
- raise Exception("For now ChatGLM do not support stream")
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
- from bs4 import BeautifulSoup
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
@@ -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,43 +0,0 @@
1
- """ChatGLM bot"""
2
- from __future__ import annotations
3
-
4
- from typing import Any
5
-
6
- import zhipuai
7
- from rich import print
8
-
9
- from xiaogpt.bot.base_bot import BaseBot, ChatHistoryMixin
10
-
11
-
12
- class GLMBot(ChatHistoryMixin, BaseBot):
13
- name = "Chat GLM"
14
- default_options = {"model": "chatglm_turbo"}
15
-
16
- def __init__(self, glm_key: str) -> None:
17
- self.history = []
18
- zhipuai.api_key = glm_key
19
-
20
- @classmethod
21
- def from_config(cls, config):
22
- return cls(glm_key=config.glm_key)
23
-
24
- def ask(self, query, **options):
25
- ms = self.get_messages()
26
- kwargs = {**self.default_options, **options}
27
- kwargs["prompt"] = ms
28
- ms.append({"role": "user", "content": f"{query}"})
29
- try:
30
- r = zhipuai.model_api.sse_invoke(**kwargs)
31
- except Exception as e:
32
- print(str(e))
33
- return
34
- message = ""
35
- for i in r.events():
36
- message += str(i.data)
37
-
38
- self.add_message(query, message)
39
- print(message)
40
- return message
41
-
42
- def ask_stream(self, query: str, **options: Any):
43
- raise Exception("GLM do not support stream")
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes