From 0f52d3195e630bab54193e953a2f0b02b3d3927c Mon Sep 17 00:00:00 2001 From: "Charl P. Botha" Date: Sat, 31 May 2025 18:09:00 +0200 Subject: [PATCH] List cited sources after the response --- src/index.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 2984497..a242e74 100644 --- a/src/index.ts +++ b/src/index.ts @@ -232,10 +232,19 @@ class PerplexityServer { messages: [{ role: "user", content: prompt }], }); + // response.data can have a string[] .citations + // these are referred to in the return text as numbered citations e.g. [1] + const sourcesText = response.data.citations + ? `\n## Sources\nPlease keep the numbered citations inline.\n + ${response.data.citations + .map((c: string, i: number) => `${i + 1}: ${c}`) + .join("\n")}` + : ""; + return { content: [{ type: "text", - text: response.data.choices[0].message.content + text: response.data.choices[0].message.content + sourcesText, }] }; } catch (error) {