Skip to content

Commit

Permalink
fix: #179 check did first (#210)
Browse files Browse the repository at this point in the history
  • Loading branch information
yihong0618 committed Apr 5, 2023
1 parent 90add61 commit a625b1e
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions xiaogpt/xiaogpt.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,17 @@ async def _init_data_hardware(self):
# if use cookie do not need init
return
hardware_data = await self.mina_service.device_list()
# fix multi xiaoai problems we check did first
# why we use this way to fix?
# some videos and articles already in the Internet
# we do not want to change old way, so we check if miotDID in `env` first
# to set device id

for h in hardware_data:
if did := os.getenv("MI_DID"):
if h.get("miotDID", "") == str(did):
self.device_id = h.get("deviceID")
break
if h.get("hardware", "") == self.config.hardware:
self.device_id = h.get("deviceID")
break
Expand Down Expand Up @@ -212,11 +222,7 @@ def need_change_prompt(self, record):
if self.config.bot == "gpt3":
return False
query = record.get("query", "")
return (
self.in_conversation
and not query.startswith(WAKEUP_KEYWORD)
or query.startswith(tuple(self.config.change_prompt_keyword))
)
return query.startswith(tuple(self.config.change_prompt_keyword))

def _change_prompt(self, new_prompt):
new_prompt = re.sub(
Expand Down Expand Up @@ -443,6 +449,7 @@ async def run_forever(self):

# we can change prompt
if self.need_change_prompt(new_record):
print(new_record)
self._change_prompt(new_record.get("query", ""))

if not self.need_ask_gpt(new_record):
Expand Down

0 comments on commit a625b1e

Please sign in to comment.