Skip to content

Commit

Permalink
Add azure open ai base path for custom domains
Browse files Browse the repository at this point in the history
  • Loading branch information
punitda committed Nov 4, 2024
1 parent 4488ee0 commit 04879b2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
3 changes: 1 addition & 2 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,5 @@ AZURE_OPENAI_API_KEY=your-azure-openai-api-key
AZURE_OPENAI_API_INSTANCE_NAME=your-instance-name
AZURE_OPENAI_API_DEPLOYMENT_NAME=your-deployment-name
AZURE_OPENAI_API_VERSION=2024-08-01-preview

# Optional: Azure OpenAI Base Path (if using a different domain)
# AZURE_OPENAI_BASE_PATH=https://your-custom-domain.com/openai/deployments
# AZURE_OPENAI_API_BASE_PATH=https://your-custom-domain.com/openai/deployments
5 changes: 3 additions & 2 deletions src/agent/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export const initChatModelWithConfig = async (
azureOpenAIApiDeploymentName:
config.azureConfig.azureOpenAIApiDeploymentName,
azureOpenAIApiVersion: config.azureConfig.azureOpenAIApiVersion,
azureOpenAIBasePath: config.azureConfig.azureOpenAIBasePath,
}
: {}),
});
Expand Down Expand Up @@ -159,14 +160,14 @@ export const getModelConfig = (
azureOpenAIApiInstanceName: string;
azureOpenAIApiDeploymentName: string;
azureOpenAIApiVersion: string;
azureOpenAIBasePath?: string;
};
} => {
const customModelName = config.configurable?.customModelName as string;
if (!customModelName) {
throw new Error("Model name is missing in config.");
}

// Handle Azure OpenAI models
if (customModelName.startsWith("azure/")) {
const actualModelName = customModelName.replace("azure/", "");
return {
Expand All @@ -180,11 +181,11 @@ export const getModelConfig = (
process.env.AZURE_OPENAI_API_DEPLOYMENT_NAME || "",
azureOpenAIApiVersion:
process.env.AZURE_OPENAI_API_VERSION || "2024-08-01-preview",
azureOpenAIBasePath: process.env.AZURE_OPENAI_API_BASE_PATH,
},
};
}

// Handle existing model providers
if (customModelName.includes("gpt-")) {
return {
modelName: customModelName,
Expand Down

0 comments on commit 04879b2

Please sign in to comment.