Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add --conversation_id, normalize method, do_action #7

Merged
merged 2 commits into from
Feb 20, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fix: coversionid
  • Loading branch information
yihong0618 committed Feb 20, 2023
commit cd10ad704a412db073fe0bc6b3fe5d0af6b448e8
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,14 @@ play chatgpt with xiaomi ai speaker
3. 参考 [revChatGPT](https://github.com/acheong08/ChatGPT) 项目 README 配置 chatGPT 的 config
4. run `python xiaogpt.py --hardware ${your_hardware}` hardware 你看小爱屁股上有型号,输入进来
5. 跑起来之后就可以问小爱同学问题了,“帮我回答开头的问题” 会发送一份给 ChatGPT 然后小爱同学用 tts 回答
6. 如果你想用 conversation_id 来持续对话,可以加上 --conversation_id="xxxxxxxx"

e.g.
```shell
python3 xiaogpt.py --hardware LX06;
# or
python3 xiaogpt.py --hardware LX06 --conversation_id="xxxxxxxx";

```

## QA
Expand Down
7 changes: 5 additions & 2 deletions xiaogpt.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def _init_cookie(self):
def _init_first_data_and_chatbot(self):
data = self.get_latest_ask_from_xiaoai()
self.last_timestamp, self.last_record = self.get_last_timestamp_and_record(data)
self.chatbot = Chatbot(configure(), conversation_id=self.conversation_id)
self.chatbot = Chatbot(configure())

def get_latest_ask_from_xiaoai(self):
r = self.s.get(
Expand Down Expand Up @@ -142,7 +142,10 @@ def run_forever(self):
# waiting for xiaoai speaker done
time.sleep(8)
self.do_action(self.tts_command, "正在问GPT我们不是会员还用的API有点慢")
data = list(self.chatbot.ask(query))[-1]
if self.conversation_id:
data = list(self.chatbot.ask(query))[-1]
else:
data = list(self.chatbot.ask(query, conversation_id=self.conversation_id))[-1]
if message := data.get("message", ""):
# xiaoai tts did not support space
message = self.normalize(message)
Expand Down