Skip to content

Commit

Permalink
handle multi speak answers
Browse files Browse the repository at this point in the history
  • Loading branch information
JarbasAl committed Nov 25, 2023
1 parent 849eacc commit 70617d8
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,24 @@ def build_msg_history(self, message):
messages = [] # tuple of question, answer

q = None
ans = None
for m in self.sessions[sess.session_id]:
if m[0] == "user":
q = m[1]
q = m[1] # track question
if ans is not None:
# save previous q/a pair
messages.append((q, ans))
q = None
ans = None
elif m[0] == "ai":
if q is not None:
messages.append((q, m[1]))
q = None
if ans is None:
ans = m[1] # track answer
else: # merge multi speak answers
ans = f"{ans}. {m[1]}"

# save last q/a pair
if ans is not None and q is not None:
messages.append((q, ans))
return messages

def ask_chatgpt(self, message):
Expand Down

0 comments on commit 70617d8

Please sign in to comment.