Skip to content

Commit

Permalink
@@@a/@@@u/@@@s roles are sticky
Browse files Browse the repository at this point in the history
  • Loading branch information
saulpw committed Nov 6, 2023
1 parent 48bb6f3 commit 1563c2d
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions aipl/clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,24 @@ def completion(self, aipl, v:str, **kwargs) -> str:
if 'client' in params:
del params['client']

# msgs = [_parse_msg(m) for m in v.splitlines()]
msgs = [_parse_msg(v)]
role = 'user'
def _get_role_msg(s:str):
if s.startswith('@@@s'):
return 'system', s[4:]
elif s.startswith('@@@a'):
return 'assistant', s[4:]
elif s.startswith('@@@u'):
return 'user', s[4:]
else:
return role, s

msgs = []
for m in v.splitlines():
role, msg = _get_role_msg(m)
if msgs and msgs[-1]['role'] == role:
msgs[-1]['content'] += '\n' + msg
else:
msgs.append(dict(role=role, content=msg))

resp = openai.ChatCompletion.create(
messages=msgs,
Expand Down

0 comments on commit 1563c2d

Please sign in to comment.