mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-09-19 05:12:16 +03:00
fix(perplexity-web): preserve system contract on follow-up requests (#12443)
* fix(perplexity-web): preserve system contract on follow-up requests * fix(perplexity-web): preserve search hint on follow-up requests
This commit is contained in:
@@ -408,7 +408,12 @@ function searchHintEnabled(): boolean {
|
||||
}
|
||||
|
||||
export function buildQuery(parsed: ParsedMessages, followUpUuid: string | null): string {
|
||||
if (followUpUuid) return parsed.currentMsg;
|
||||
if (followUpUuid) {
|
||||
const sys = parsed.systemMsg.trim();
|
||||
const hint = searchHintEnabled() ? `\n\n${SEARCH_HINT}` : "";
|
||||
const contract = sys ? `${sys}${hint}` : "";
|
||||
return contract ? `${contract}\n\n${parsed.currentMsg}` : parsed.currentMsg;
|
||||
}
|
||||
|
||||
const obj: Record<string, unknown> = {};
|
||||
if (parsed.systemMsg.trim()) {
|
||||
|
||||
29
tests/unit/12104-perplexity-web-followup-contract.test.ts
Normal file
29
tests/unit/12104-perplexity-web-followup-contract.test.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import { test } from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { buildQuery } from "../../open-sse/executors/perplexity-web/protocol.ts";
|
||||
|
||||
test("PR #3: buildQuery preserves system contract on follow-up requests", () => {
|
||||
const parsed = {
|
||||
systemMsg: "You are an expert coder. <tool>contract</tool>",
|
||||
history: [],
|
||||
currentMsg: "How do I reverse a string in JS?"
|
||||
};
|
||||
|
||||
// Turn 1: followUpUuid is null
|
||||
const turn1Raw = buildQuery(parsed, null);
|
||||
const turn1Obj = JSON.parse(turn1Raw);
|
||||
assert.ok(turn1Obj.instructions !== undefined, "Turn 1 JSON should contain instructions");
|
||||
assert.equal(turn1Obj.instructions[0], "You are an expert coder. <tool>contract</tool>");
|
||||
|
||||
// Turn 2: follow-up request
|
||||
const parsedTurn2 = {
|
||||
systemMsg: "You are an expert coder. <tool>contract</tool>",
|
||||
history: [{ role: "user", content: "How do I reverse a string in JS?" }, { role: "assistant", content: "Use .reverse()" }],
|
||||
currentMsg: "What about Python?"
|
||||
};
|
||||
const turn2Output = buildQuery(parsedTurn2, "abc-123");
|
||||
|
||||
// Since we append systemMsg to currentMsg for follow-ups (Approach B)
|
||||
assert.ok(turn2Output.includes("<tool>contract</tool>"), "Follow-up query should preserve the tool contract");
|
||||
assert.ok(turn2Output.includes("What about Python?"), "Follow-up query should include the current message");
|
||||
});
|
||||
Reference in New Issue
Block a user