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) {