Browse Source

fix Conversation roles must alternate user/assistant/user/assistant/... bug (#6880)

### What problem does this PR solve?

The old logic filters out all assistant messages from messages, which,
in multi-turn conversations, results in only user messages being
retained. This leads to an error in locally deployed models:
Conversation roles must alternate user/assistant/user/assistant/...

### Type of change

- [x] Bug Fix (non-breaking change which fixes an issue)
- [ ] New Feature (non-breaking change which adds functionality)
- [ ] Documentation Update
- [ ] Refactoring
- [ ] Performance Improvement
- [ ] Other (please describe):
tags/v0.18.0
dylan 6 months ago
parent
commit
9d9f2dacd2
No account linked to committer's email address
1 changed files with 7 additions and 2 deletions
  1. 7
    2
      api/apps/sdk/session.py

+ 7
- 2
api/apps/sdk/session.py View File

@@ -240,8 +240,13 @@ def chat_completion_openai_like(tenant_id, chat_id):
dia = dia[0]

# Filter system and non-sense assistant messages
msg = None
msg = [m for m in messages if m["role"] != "system" and (m["role"] != "assistant" or msg)]
msg = []
for m in messages:
if m["role"] == "system":
continue
if m["role"] == "assistant" and not msg:
continue
msg.append(m)

# tools = get_tools()
# toolcall_session = SimpleFunctionCallServer()

Loading…
Cancel
Save