(messages)
| 87 | } |
| 88 | |
| 89 | function mergeConsecutiveRoles(messages) { |
| 90 | if (messages.length <= 1) return messages; |
| 91 | const merged = []; |
| 92 | for (const msg of messages) { |
| 93 | const last = merged[merged.length - 1]; |
| 94 | if (last && last.role === msg.role) { |
| 95 | const lastBlocks = toBlocks(last.content); |
| 96 | const newBlocks = toBlocks(msg.content); |
| 97 | last.content = [...lastBlocks, ...newBlocks]; |
| 98 | } else { |
| 99 | merged.push({ ...msg }); |
| 100 | } |
| 101 | } |
| 102 | return merged; |
| 103 | } |
| 104 | |
| 105 | // ─── 内联 responsesToChatCompletions(与 src/openai-handler.ts 保持同步) |
| 106 | function responsesToChatCompletions(body) { |
no test coverage detected