🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.
TypeScript analyticsautogenevaluationlangchainlarge-language-modelsllama-indexllmllm-evaluationllm-observabilityllmopsmonitoringobservabilityopen-sourceopenaiplaygroundprompt-engineeringprompt-managementself-hostedycombinator
feat(llm-connections): allow {model} templated in baseUrl for OpenAI adapter (#10617)
Hassieb Pakzadfcb52712ba13
diff --git a/packages/shared/src/server/llm/fetchLLMCompletion.ts b/packages/shared/src/server/llm/fetchLLMCompletion.tsindex d7672eb292..c129f96d19 100644--- a/packages/shared/src/server/llm/fetchLLMCompletion.ts+++ b/packages/shared/src/server/llm/fetchLLMCompletion.ts@@ -271,6 +271,11 @@ export async function fetchLLMCompletion(}}} else if (modelParams.adapter === LLMAdapter.OpenAI) {+ const processedBaseURL = processOpenAIBaseURL({+ url: baseURL,+ modelName: modelParams.model,+ });+chatModel = new ChatOpenAI({openAIApiKey: apiKey,modelName: modelParams.model,@@ -283,7 +288,7 @@ export async function fetchLLMCompletion(callbacks: finalCallbacks,maxRetries,configuration: {- baseURL,+ baseURL: processedBaseURL,defaultHeaders: extraHeaders,...(proxyAgent && { httpAgent: proxyAgent }),},@@ -474,3 +479,22 @@ export async function fetchLLMCompletion(await processTracedEvents();}}++/**+ * Process baseURL template for OpenAI adapter only.+ * Replaces {model} placeholder with actual model name.+ * This is a workaround for proxies that require the model name in the URL azureOpenAIBasePath+ * while having OpenAI compliance otherwise+ */+function processOpenAIBaseURL(params: {+ url: string | null | undefined;+ modelName: string;+}): string | null | undefined {+ const { url, modelName } = params;++ if (!url || !url.includes("{model}")) {+ return url;+ }++ return url.replace("{model}", modelName);+}