xiaogpt 3.4__tar.gz → 3.10__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-3.4 → xiaogpt-3.10}/PKG-INFO +1 -1
  2. {xiaogpt-3.4 → xiaogpt-3.10}/pyproject.toml +1 -1
  3. {xiaogpt-3.4 → xiaogpt-3.10}/xiaogpt/bot/gemini_bot.py +8 -4
  4. {xiaogpt-3.4 → xiaogpt-3.10}/xiaogpt/cli.py +3 -2
  5. {xiaogpt-3.4 → xiaogpt-3.10}/xiaogpt/config.py +2 -1
  6. {xiaogpt-3.4 → xiaogpt-3.10}/xiaogpt/tts/live.py +5 -0
  7. {xiaogpt-3.4 → xiaogpt-3.10}/xiaogpt/xiaogpt.py +16 -7
  8. {xiaogpt-3.4 → xiaogpt-3.10}/LICENSE +0 -0
  9. {xiaogpt-3.4 → xiaogpt-3.10}/README.md +0 -0
  10. {xiaogpt-3.4 → xiaogpt-3.10}/xiaogpt/__init__.py +0 -0
  11. {xiaogpt-3.4 → xiaogpt-3.10}/xiaogpt/__main__.py +0 -0
  12. {xiaogpt-3.4 → xiaogpt-3.10}/xiaogpt/bot/__init__.py +0 -0
  13. {xiaogpt-3.4 → xiaogpt-3.10}/xiaogpt/bot/base_bot.py +0 -0
  14. {xiaogpt-3.4 → xiaogpt-3.10}/xiaogpt/bot/chatgptapi_bot.py +0 -0
  15. {xiaogpt-3.4 → xiaogpt-3.10}/xiaogpt/bot/doubao_bot.py +0 -0
  16. {xiaogpt-3.4 → xiaogpt-3.10}/xiaogpt/bot/glm_bot.py +0 -0
  17. {xiaogpt-3.4 → xiaogpt-3.10}/xiaogpt/bot/langchain_bot.py +0 -0
  18. {xiaogpt-3.4 → xiaogpt-3.10}/xiaogpt/bot/llama_bot.py +0 -0
  19. {xiaogpt-3.4 → xiaogpt-3.10}/xiaogpt/bot/moonshot_bot.py +0 -0
  20. {xiaogpt-3.4 → xiaogpt-3.10}/xiaogpt/bot/qwen_bot.py +0 -0
  21. {xiaogpt-3.4 → xiaogpt-3.10}/xiaogpt/bot/yi_bot.py +0 -0
  22. {xiaogpt-3.4 → xiaogpt-3.10}/xiaogpt/langchain/callbacks.py +0 -0
  23. {xiaogpt-3.4 → xiaogpt-3.10}/xiaogpt/langchain/chain.py +0 -0
  24. {xiaogpt-3.4 → xiaogpt-3.10}/xiaogpt/langchain/examples/email/mail_box.py +0 -0
  25. {xiaogpt-3.4 → xiaogpt-3.10}/xiaogpt/langchain/examples/email/mail_summary_tools.py +0 -0
  26. {xiaogpt-3.4 → xiaogpt-3.10}/xiaogpt/tts/__init__.py +0 -0
  27. {xiaogpt-3.4 → xiaogpt-3.10}/xiaogpt/tts/base.py +0 -0
  28. {xiaogpt-3.4 → xiaogpt-3.10}/xiaogpt/tts/file.py +0 -0
  29. {xiaogpt-3.4 → xiaogpt-3.10}/xiaogpt/tts/mi.py +0 -0
  30. {xiaogpt-3.4 → xiaogpt-3.10}/xiaogpt/utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: xiaogpt
3
- Version: 3.4
3
+ Version: 3.10
4
4
  Summary: Play ChatGPT or other LLM with xiaomi AI speaker
5
5
  Author-Email: yihong0618 <zouzou0208@gmail.com>
6
6
  License: MIT
@@ -31,7 +31,7 @@ dependencies = [
31
31
  "lingua-language-detector>=2.0.2; python_version < \"3.13\"",
32
32
  ]
33
33
  dynamic = []
34
- version = "3.4"
34
+ version = "3.10"
35
35
 
36
36
  [project.license]
37
37
  text = "MIT"
@@ -32,13 +32,15 @@ safety_settings = [
32
32
  class GeminiBot(ChatHistoryMixin, BaseBot):
33
33
  name = "Gemini"
34
34
 
35
- def __init__(self, gemini_key: str, gemini_api_domain: str) -> None:
35
+ def __init__(
36
+ self, gemini_key: str, gemini_api_domain: str, gemini_model: str
37
+ ) -> None:
36
38
  import google.generativeai as genai
37
39
 
38
40
  from google.auth import api_key
39
41
 
40
42
  credentials = api_key.Credentials(gemini_key)
41
- if len(gemini_api_domain) > 0:
43
+ if gemini_api_domain:
42
44
  print("Use custom gemini_api_domain: " + gemini_api_domain)
43
45
  credentials._universe_domain = gemini_api_domain
44
46
  genai.configure(
@@ -54,7 +56,7 @@ class GeminiBot(ChatHistoryMixin, BaseBot):
54
56
 
55
57
  self.history = []
56
58
  model = genai.GenerativeModel(
57
- model_name="gemini-pro",
59
+ model_name=gemini_model or "gemini-2.0-flash-lite",
58
60
  generation_config=generation_config,
59
61
  safety_settings=safety_settings,
60
62
  )
@@ -63,7 +65,9 @@ class GeminiBot(ChatHistoryMixin, BaseBot):
63
65
  @classmethod
64
66
  def from_config(cls, config):
65
67
  return cls(
66
- gemini_key=config.gemini_key, gemini_api_domain=config.gemini_api_domain
68
+ gemini_key=config.gemini_key,
69
+ gemini_api_domain=config.gemini_api_domain,
70
+ gemini_model=config.gemini_model,
67
71
  )
68
72
 
69
73
  async def ask(self, query, **options):
@@ -111,9 +111,10 @@ def main():
111
111
  )
112
112
  parser.add_argument(
113
113
  "--verbose",
114
+ "-v",
114
115
  dest="verbose",
115
- action="store_true",
116
- default=None,
116
+ action="count",
117
+ default=0,
117
118
  help="show info",
118
119
  )
119
120
  parser.add_argument(
@@ -59,6 +59,7 @@ class Config:
59
59
  llama_api_key: str = os.getenv("GROQ_API_KEY", "") # use groq
60
60
  glm_key: str = os.getenv("CHATGLM_KEY", "")
61
61
  gemini_key: str = os.getenv("GEMINI_KEY", "") # keep the old rule
62
+ gemini_model: str = os.getenv("GEMINI_MODEL", "") # keep the old rule
62
63
  qwen_key: str = os.getenv("DASHSCOPE_API_KEY", "") # keep the old rule
63
64
  serpapi_api_key: str = os.getenv("SERPAPI_API_KEY", "")
64
65
  gemini_api_domain: str = os.getenv(
@@ -77,7 +78,7 @@ class Config:
77
78
  api_base: str | None = None
78
79
  deployment_id: str | None = None
79
80
  use_command: bool = False
80
- verbose: bool = False
81
+ verbose: int = 0
81
82
  start_conversation: str = "开始持续对话"
82
83
  end_conversation: str = "结束持续对话"
83
84
  stream: bool = False
@@ -27,11 +27,15 @@ class HTTPRequestHandler(BaseHTTPRequestHandler):
27
27
  self.end_headers()
28
28
  key = self.path.split("/")[-1]
29
29
  queue = get_queue(key)
30
+ chunks: list[bytes] = []
30
31
  while True:
31
32
  chunk = queue.get()
33
+ chunks.append(chunk)
32
34
  if chunk == b"":
33
35
  break
34
36
  self.wfile.write(chunk)
37
+ for chunk in chunks:
38
+ queue.put_nowait(chunk)
35
39
 
36
40
  def log_message(self, format, *args):
37
41
  logger.debug(f"{self.address_string()} - {format}", *args)
@@ -76,6 +80,7 @@ class TetosLiveTTS(TTS):
76
80
 
77
81
  while True:
78
82
  if await self.get_if_xiaoai_is_playing():
83
+ logger.debug("Xiaoai is playing, waiting")
79
84
  await asyncio.sleep(1)
80
85
  else:
81
86
  break
@@ -57,15 +57,20 @@ class MiGPT:
57
57
  async def poll_latest_ask(self):
58
58
  async with ClientSession() as session:
59
59
  session._cookie_jar = self.cookie_jar
60
+ log_polling = int(self.config.verbose) > 1
60
61
  while True:
61
- self.log.debug(
62
- "Listening new message, timestamp: %s", self.last_timestamp
63
- )
62
+ if log_polling:
63
+ self.log.debug(
64
+ "Listening new message, timestamp: %s", self.last_timestamp
65
+ )
64
66
  new_record = await self.get_latest_ask_from_xiaoai(session)
65
67
  start = time.perf_counter()
66
- self.log.debug(
67
- "Polling_event, timestamp: %s %s", self.last_timestamp, new_record
68
- )
68
+ if log_polling:
69
+ self.log.debug(
70
+ "Polling_event, timestamp: %s %s",
71
+ self.last_timestamp,
72
+ new_record,
73
+ )
69
74
  await self.polling_event.wait()
70
75
  if (
71
76
  self.config.mute_xiaoai
@@ -75,7 +80,10 @@ class MiGPT:
75
80
  await self.stop_if_xiaoai_is_playing()
76
81
  if (d := time.perf_counter() - start) < 1:
77
82
  # sleep to avoid too many request
78
- self.log.debug("Sleep %f, timestamp: %s", d, self.last_timestamp)
83
+ if log_polling:
84
+ self.log.debug(
85
+ "Sleep %f, timestamp: %s", d, self.last_timestamp
86
+ )
79
87
  # if you want force mute xiaoai, comment this line below.
80
88
  await asyncio.sleep(1 - d)
81
89
 
@@ -334,6 +342,7 @@ class MiGPT:
334
342
  async def stop_if_xiaoai_is_playing(self):
335
343
  is_playing = await self.get_if_xiaoai_is_playing()
336
344
  if is_playing:
345
+ self.log.debug("Muting xiaoai")
337
346
  # stop it
338
347
  await self.mina_service.player_pause(self.device_id)
339
348
 
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
File without changes
File without changes
File without changes
File without changes