xiaogpt 2.24__py3-none-any.whl → 2.26__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/qwen_bot.py CHANGED
@@ -60,6 +60,9 @@ class QwenBot(ChatHistoryMixin, BaseBot):
60
60
  response.message,
61
61
  )
62
62
  )
63
+ # we need to pop the wrong history
64
+ print(f"Will pop the wrong question {query}")
65
+ self.history.pop()
63
66
  return "没有返回"
64
67
 
65
68
  async def ask_stream(self, query: str, **options: Any):
xiaogpt/xiaogpt.py CHANGED
@@ -51,6 +51,7 @@ class MiGPT:
51
51
  self.log.setLevel(logging.DEBUG if config.verbose else logging.INFO)
52
52
  self.log.addHandler(RichHandler())
53
53
  self.log.debug(config)
54
+ self.mi_session = ClientSession()
54
55
 
55
56
  async def poll_latest_ask(self):
56
57
  async with ClientSession() as session:
@@ -78,8 +79,8 @@ class MiGPT:
78
79
  async def init_all_data(self, session):
79
80
  await self.login_miboy(session)
80
81
  await self._init_data_hardware()
81
- session.cookie_jar.update_cookies(self.get_cookie())
82
- self.cookie_jar = session.cookie_jar
82
+ self.mi_session.cookie_jar.update_cookies(self.get_cookie())
83
+ self.cookie_jar = self.mi_session.cookie_jar
83
84
  self.tts # init tts
84
85
 
85
86
  async def login_miboy(self, session):
@@ -215,14 +216,17 @@ class MiGPT:
215
216
  data = await r.json()
216
217
  except Exception:
217
218
  self.log.warning("get latest ask from xiaoai error, retry")
218
- if i == 2:
219
+ if i == 1:
219
220
  # tricky way to fix #282 #272 # if it is the third time we re init all data
220
221
  print("Maybe outof date trying to re init it")
221
- await self.init_all_data(self.session)
222
+ await self._retry()
222
223
  else:
223
224
  return self._get_last_query(data)
224
225
  return None
225
226
 
227
+ async def _retry(self):
228
+ await self.init_all_data(self.mi_session)
229
+
226
230
  def _get_last_query(self, data: dict) -> dict | None:
227
231
  if d := data.get("data"):
228
232
  records = json.loads(d).get("records")
@@ -339,71 +343,69 @@ class MiGPT:
339
343
  )
340
344
 
341
345
  async def run_forever(self):
342
- async with ClientSession() as session:
343
- self.session = session
344
- await self.init_all_data(session)
345
- task = asyncio.create_task(self.poll_latest_ask())
346
- assert task is not None # to keep the reference to task, do not remove this
347
- print(
348
- f"Running xiaogpt now, 用[green]{'/'.join(self.config.keyword)}[/]开头来提问"
349
- )
350
- print(f"或用[green]{self.config.start_conversation}[/]开始持续对话")
351
- while True:
352
- self.polling_event.set()
353
- new_record = await self.last_record.get()
354
- self.polling_event.clear() # stop polling when processing the question
355
- query = new_record.get("query", "").strip()
356
-
357
- if query == self.config.start_conversation:
358
- if not self.in_conversation:
359
- print("开始对话")
360
- self.in_conversation = True
361
- await self.wakeup_xiaoai()
362
- await self.stop_if_xiaoai_is_playing()
363
- continue
364
- elif query == self.config.end_conversation:
365
- if self.in_conversation:
366
- print("结束对话")
367
- self.in_conversation = False
368
- await self.stop_if_xiaoai_is_playing()
369
- continue
346
+ await self.init_all_data(self.mi_session)
347
+ task = asyncio.create_task(self.poll_latest_ask())
348
+ assert task is not None # to keep the reference to task, do not remove this
349
+ print(
350
+ f"Running xiaogpt now, 用[green]{'/'.join(self.config.keyword)}[/]开头来提问"
351
+ )
352
+ print(f"或用[green]{self.config.start_conversation}[/]开始持续对话")
353
+ while True:
354
+ self.polling_event.set()
355
+ new_record = await self.last_record.get()
356
+ self.polling_event.clear() # stop polling when processing the question
357
+ query = new_record.get("query", "").strip()
358
+
359
+ if query == self.config.start_conversation:
360
+ if not self.in_conversation:
361
+ print("开始对话")
362
+ self.in_conversation = True
363
+ await self.wakeup_xiaoai()
364
+ await self.stop_if_xiaoai_is_playing()
365
+ continue
366
+ elif query == self.config.end_conversation:
367
+ if self.in_conversation:
368
+ print("结束对话")
369
+ self.in_conversation = False
370
+ await self.stop_if_xiaoai_is_playing()
371
+ continue
370
372
 
371
- # we can change prompt
372
- if self.need_change_prompt(new_record):
373
- print(new_record)
374
- self._change_prompt(new_record.get("query", ""))
373
+ # we can change prompt
374
+ if self.need_change_prompt(new_record):
375
+ print(new_record)
376
+ self._change_prompt(new_record.get("query", ""))
375
377
 
376
- if not self.need_ask_gpt(new_record):
377
- self.log.debug("No new xiao ai record")
378
- continue
378
+ if not self.need_ask_gpt(new_record):
379
+ self.log.debug("No new xiao ai record")
380
+ continue
379
381
 
380
- # drop 帮我回答
381
- query = re.sub(rf"^({'|'.join(self.config.keyword)})", "", query)
382
+ # drop 帮我回答
383
+ query = re.sub(rf"^({'|'.join(self.config.keyword)})", "", query)
382
384
 
383
- print("-" * 20)
384
- print("问题:" + query + "?")
385
- if not self.chatbot.has_history():
386
- query = f"{query},{self.config.prompt}"
387
- if self.config.mute_xiaoai:
388
- await self.stop_if_xiaoai_is_playing()
389
- else:
390
- # waiting for xiaoai speaker done
391
- await asyncio.sleep(8)
392
- await self.do_tts(f"正在问{self.chatbot.name}请耐心等待")
393
- try:
394
- print(
395
- "以下是小爱的回答: ",
396
- new_record.get("answers", [])[0].get("tts", {}).get("text"),
397
- )
398
- except IndexError:
399
- print("小爱没回")
400
- print(f"以下是 {self.chatbot.name} 的回答: ", end="")
401
- try:
402
- await self.tts.synthesize(query, self.ask_gpt(query))
403
- except Exception as e:
404
- print(f"{self.chatbot.name} 回答出错 {str(e)}")
405
- else:
406
- print("回答完毕")
407
- if self.in_conversation:
408
- print(f"继续对话, 或用`{self.config.end_conversation}`结束对话")
409
- await self.wakeup_xiaoai()
385
+ print("-" * 20)
386
+ print("问题:" + query + "?")
387
+ if not self.chatbot.has_history():
388
+ query = f"{query},{self.config.prompt}"
389
+ if self.config.mute_xiaoai:
390
+ await self.stop_if_xiaoai_is_playing()
391
+ else:
392
+ # waiting for xiaoai speaker done
393
+ await asyncio.sleep(8)
394
+ await self.do_tts(f"正在问{self.chatbot.name}请耐心等待")
395
+ try:
396
+ print(
397
+ "以下是小爱的回答: ",
398
+ new_record.get("answers", [])[0].get("tts", {}).get("text"),
399
+ )
400
+ except IndexError:
401
+ print("小爱没回")
402
+ print(f"以下是 {self.chatbot.name} 的回答: ", end="")
403
+ try:
404
+ await self.tts.synthesize(query, self.ask_gpt(query))
405
+ except Exception as e:
406
+ print(f"{self.chatbot.name} 回答出错 {str(e)}")
407
+ else:
408
+ print("回答完毕")
409
+ if self.in_conversation:
410
+ print(f"继续对话, 或用`{self.config.end_conversation}`结束对话")
411
+ await self.wakeup_xiaoai()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: xiaogpt
3
- Version: 2.24
3
+ Version: 2.26
4
4
  Summary: Play ChatGPT or other LLM with xiaomi AI speaker
5
5
  Author-Email: yihong0618 <zouzou0208@gmail.com>
6
6
  License: MIT
@@ -1,7 +1,7 @@
1
- xiaogpt-2.24.dist-info/METADATA,sha256=GA-UMnOxQYoWlWtYCVywOTtekubGkGWLO1xs-byJZkI,18887
2
- xiaogpt-2.24.dist-info/WHEEL,sha256=N2J68yzZqJh3mI_Wg92rwhw0rtJDFpZj9bwQIMJgaVg,90
3
- xiaogpt-2.24.dist-info/entry_points.txt,sha256=zLFzA72qQ_eWBepdA2YU5vdXFqORH8wXhv2Ox1vnYP8,46
4
- xiaogpt-2.24.dist-info/licenses/LICENSE,sha256=XdClh516MvlnOf9749JZHCxSB7y6_fyXcWmLDz6IkZY,1063
1
+ xiaogpt-2.26.dist-info/METADATA,sha256=Stcpqotc2KK6q0ALFxKMvWkflyPcTi5xho3d9tCjlzE,18887
2
+ xiaogpt-2.26.dist-info/WHEEL,sha256=N2J68yzZqJh3mI_Wg92rwhw0rtJDFpZj9bwQIMJgaVg,90
3
+ xiaogpt-2.26.dist-info/entry_points.txt,sha256=zLFzA72qQ_eWBepdA2YU5vdXFqORH8wXhv2Ox1vnYP8,46
4
+ xiaogpt-2.26.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
@@ -13,7 +13,7 @@ xiaogpt/bot/glm_bot.py,sha256=QoMJbnu5_rHDz4tzwn7gh3IoAuw7E4hZQLAfziMAvNY,1825
13
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
15
  xiaogpt/bot/newbing_bot.py,sha256=afUmw6tyMXbgGZvfQQWaA5h0-e0V0isFolW-WGhd0Vs,2289
16
- xiaogpt/bot/qwen_bot.py,sha256=n0WIeixAisd2_Vvky18FQFGcDIF3Cc2q2qp4ExCNBho,3521
16
+ xiaogpt/bot/qwen_bot.py,sha256=325lMa4Z38rRh47HDa3J4XjvSs4SWOqMVhrMWzkGNo4,3657
17
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
@@ -26,5 +26,5 @@ xiaogpt/tts/edge.py,sha256=yMFGxRTi086XS1d_mbMzQ365bvG4KgAz8ZptaoDAfGU,1172
26
26
  xiaogpt/tts/mi.py,sha256=9HkgGWByAs7k8sTpRdVlgJnnmjc44RNAccJa6tGDlXk,1096
27
27
  xiaogpt/tts/openai.py,sha256=_Qk12zYY-UuXLKvQVe3PqIvCmoRW9OcVCqQRoGCXvNc,1533
28
28
  xiaogpt/utils.py,sha256=B7NCH7g19hcwHDXsnBJPTU6UcWnXoEntKWm-pgcet2I,2072
29
- xiaogpt/xiaogpt.py,sha256=_viWq5w4-rGCTsuDetPPih-4qkPZem9FtXK-tPyChlA,15473
30
- xiaogpt-2.24.dist-info/RECORD,,
29
+ xiaogpt/xiaogpt.py,sha256=QfXkDux6984znX1EdLgBcPcS8xxti9YEMZkcWgt2jjI,15273
30
+ xiaogpt-2.26.dist-info/RECORD,,
File without changes