Skip to content

Commit

Permalink
aggregate all user messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Judd committed Jun 28, 2024
1 parent 73ce4d7 commit 8fed353
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions scripts/openai_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,18 @@ def do_POST(self):
stream = obj['stream']
if 'messages' in obj:
counter = 0
for x in obj['messages']:
flag = True
# aggregate all user messages
for i in range(len(obj['messages']) - 1, -1, -1):
x = obj['messages'][i]
if x['role'] == 'user':
counter = counter + 1
prompt = x['content']
else:
flag = False

if flag:
prompt = x['content'] + '\n' + prompt

restart = counter < 2

responder_cls = ChatCompletionStreamResponder if stream else ChatCompletionNonStreamResponder
Expand Down

0 comments on commit 8fed353

Please sign in to comment.