From 41365cb3bc22b7feb0cafd9a0558e1426b7d08a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20M=C3=BCller?= Date: Tue, 31 Mar 2026 16:42:32 +0200 Subject: [PATCH 1/2] Refactor model constants in server.ts for improved configurability in custom LLM gateway deployments using PERPLEXITY_BASE_URL --- src/server.ts | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/server.ts b/src/server.ts index d649ccb..8a8eac5 100644 --- a/src/server.ts +++ b/src/server.ts @@ -13,6 +13,11 @@ import { ChatCompletionResponseSchema, SearchResponseSchema } from "./validation const PERPLEXITY_API_KEY = process.env.PERPLEXITY_API_KEY; const PERPLEXITY_BASE_URL = process.env.PERPLEXITY_BASE_URL || "https://api.perplexity.ai"; + +const SONAR_PRO_MODEL = process.env.SONAR_PRO_MODEL || "sonar-pro"; +const SONAR_REASONING_MODEL = process.env.SONAR_REASONING_MODEL || "sonar-reasoning-pro"; +const SONAR_DEEP_RESEARCH_MODEL = process.env.SONAR_DEEP_RESEARCH_MODEL || "sonar-deep-research"; + const VERSION = "0.9.0"; export function getProxyUrl(): string | undefined { @@ -98,7 +103,7 @@ async function makeApiRequest( clearTimeout(timeoutId); if (error instanceof Error && error.name === "AbortError") { throw new Error(`Request timeout: Perplexity API did not respond within ${TIMEOUT_MS}ms. Consider increasing PERPLEXITY_TIMEOUT_MS.`); - } + } throw new Error(`Network error while calling Perplexity API: ${error}`); } clearTimeout(timeoutId); @@ -191,12 +196,12 @@ export async function consumeSSEStream(response: Response): Promise { - const useStreaming = model === "sonar-deep-research"; + const useStreaming = model === SONAR_DEEP_RESEARCH_MODEL; const body: Record = { model: model, @@ -393,7 +398,7 @@ export function createPerplexityServer(serviceOrigin?: string) { ...(search_domain_filter && { search_domain_filter }), ...(search_context_size && { search_context_size }), }; - const result = await performChatCompletion(messages, "sonar-pro", false, serviceOrigin, Object.keys(options).length > 0 ? options : undefined); + const result = await performChatCompletion(messages, SONAR_PRO_MODEL, false, serviceOrigin, Object.keys(options).length > 0 ? options : undefined); return { content: [{ type: "text" as const, text: result }], structuredContent: { response: result }, @@ -431,7 +436,7 @@ export function createPerplexityServer(serviceOrigin?: string) { const options = { ...(reasoning_effort && { reasoning_effort }), }; - const result = await performChatCompletion(messages, "sonar-deep-research", stripThinking, serviceOrigin, Object.keys(options).length > 0 ? options : undefined); + const result = await performChatCompletion(messages, SONAR_DEEP_RESEARCH_MODEL, stripThinking, serviceOrigin, Object.keys(options).length > 0 ? options : undefined); return { content: [{ type: "text" as const, text: result }], structuredContent: { response: result }, @@ -473,7 +478,7 @@ export function createPerplexityServer(serviceOrigin?: string) { ...(search_domain_filter && { search_domain_filter }), ...(search_context_size && { search_context_size }), }; - const result = await performChatCompletion(messages, "sonar-reasoning-pro", stripThinking, serviceOrigin, Object.keys(options).length > 0 ? options : undefined); + const result = await performChatCompletion(messages, SONAR_REASONING_MODEL, stripThinking, serviceOrigin, Object.keys(options).length > 0 ? options : undefined); return { content: [{ type: "text" as const, text: result }], structuredContent: { response: result }, From 2928bc86ce1492c10a0c2988f4777a814869ce9d Mon Sep 17 00:00:00 2001 From: maximilianmueller-tchibo Date: Tue, 31 Mar 2026 17:05:30 +0200 Subject: [PATCH 2/2] Update server.ts --- src/server.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/server.ts b/src/server.ts index 8a8eac5..534d6e4 100644 --- a/src/server.ts +++ b/src/server.ts @@ -103,7 +103,7 @@ async function makeApiRequest( clearTimeout(timeoutId); if (error instanceof Error && error.name === "AbortError") { throw new Error(`Request timeout: Perplexity API did not respond within ${TIMEOUT_MS}ms. Consider increasing PERPLEXITY_TIMEOUT_MS.`); - } + } throw new Error(`Network error while calling Perplexity API: ${error}`); } clearTimeout(timeoutId);