Skip to content

Commit 7fa8ce8

Browse files
committed
feat: map azure model to openai model in ts
1 parent 0bf4479 commit 7fa8ce8

File tree

2 files changed

+54
-8
lines changed

2 files changed

+54
-8
lines changed

templates/types/streaming/express/src/controllers/engine/settings.ts

+27-4
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export const initSettings = async () => {
4747
break;
4848
case "azure-openai":
4949
initAzureOpenAI();
50+
break;
5051
default:
5152
initOpenAI();
5253
break;
@@ -71,27 +72,49 @@ function initOpenAI() {
7172
}
7273

7374
function initAzureOpenAI() {
75+
// Map Azure OpenAI model names to OpenAI model names (only for TS)
76+
const AZURE_OPENAI_MODEL_MAP: Record<string, string> = {
77+
"gpt-35-turbo": "gpt-3.5-turbo",
78+
"gpt-35-turbo-16k": "gpt-3.5-turbo-16k",
79+
"gpt-4o": "gpt-4o",
80+
"gpt-4": "gpt-4",
81+
"gpt-4-32k": "gpt-4-32k",
82+
"gpt-4-turbo": "gpt-4-turbo",
83+
"gpt-4-turbo-2024-04-09": "gpt-4-turbo",
84+
"gpt-4-vision-preview": "gpt-4-vision-preview",
85+
"gpt-4-1106-preview": "gpt-4-1106-preview",
86+
"gpt-4o-2024-05-13": "gpt-4o-2024-05-13",
87+
};
88+
7489
const azureConfig = {
75-
model: process.env.MODEL ?? "gpt-4o",
7690
apiKey: process.env.AZURE_OPENAI_KEY,
7791
endpoint: process.env.AZURE_OPENAI_ENDPOINT,
7892
apiVersion:
7993
process.env.AZURE_OPENAI_API_VERSION || process.env.OPENAI_API_VERSION,
80-
deployment: process.env.AZURE_OPENAI_DEPLOYMENT,
8194
};
8295

8396
Settings.llm = new OpenAI({
97+
model:
98+
AZURE_OPENAI_MODEL_MAP[process.env.MODEL ?? "gpt-35-turbo"] ??
99+
"gpt-3.5-turbo",
84100
maxTokens: process.env.LLM_MAX_TOKENS
85101
? Number(process.env.LLM_MAX_TOKENS)
86102
: undefined,
87-
azure: azureConfig,
103+
azure: {
104+
...azureConfig,
105+
deployment: process.env.AZURE_OPENAI_LLM_DEPLOYMENT,
106+
},
88107
});
89108

90109
Settings.embedModel = new OpenAIEmbedding({
110+
model: process.env.EMBEDDING_MODEL,
91111
dimensions: process.env.EMBEDDING_DIM
92112
? parseInt(process.env.EMBEDDING_DIM)
93113
: undefined,
94-
azure: azureConfig,
114+
azure: {
115+
...azureConfig,
116+
deployment: process.env.AZURE_OPENAI_EMBEDDING_DEPLOYMENT,
117+
},
95118
});
96119
}
97120

templates/types/streaming/nextjs/app/api/chat/engine/settings.ts

+27-4
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export const initSettings = async () => {
4747
break;
4848
case "azure-openai":
4949
initAzureOpenAI();
50+
break;
5051
default:
5152
initOpenAI();
5253
break;
@@ -71,27 +72,49 @@ function initOpenAI() {
7172
}
7273

7374
function initAzureOpenAI() {
75+
// Map Azure OpenAI model names to OpenAI model names (only for TS)
76+
const AZURE_OPENAI_MODEL_MAP: Record<string, string> = {
77+
"gpt-35-turbo": "gpt-3.5-turbo",
78+
"gpt-35-turbo-16k": "gpt-3.5-turbo-16k",
79+
"gpt-4o": "gpt-4o",
80+
"gpt-4": "gpt-4",
81+
"gpt-4-32k": "gpt-4-32k",
82+
"gpt-4-turbo": "gpt-4-turbo",
83+
"gpt-4-turbo-2024-04-09": "gpt-4-turbo",
84+
"gpt-4-vision-preview": "gpt-4-vision-preview",
85+
"gpt-4-1106-preview": "gpt-4-1106-preview",
86+
"gpt-4o-2024-05-13": "gpt-4o-2024-05-13",
87+
};
88+
7489
const azureConfig = {
75-
model: process.env.MODEL ?? "gpt-4o",
7690
apiKey: process.env.AZURE_OPENAI_KEY,
7791
endpoint: process.env.AZURE_OPENAI_ENDPOINT,
7892
apiVersion:
7993
process.env.AZURE_OPENAI_API_VERSION || process.env.OPENAI_API_VERSION,
80-
deployment: process.env.AZURE_OPENAI_DEPLOYMENT,
8194
};
8295

8396
Settings.llm = new OpenAI({
97+
model:
98+
AZURE_OPENAI_MODEL_MAP[process.env.MODEL ?? "gpt-35-turbo"] ??
99+
"gpt-3.5-turbo",
84100
maxTokens: process.env.LLM_MAX_TOKENS
85101
? Number(process.env.LLM_MAX_TOKENS)
86102
: undefined,
87-
azure: azureConfig,
103+
azure: {
104+
...azureConfig,
105+
deployment: process.env.AZURE_OPENAI_LLM_DEPLOYMENT,
106+
},
88107
});
89108

90109
Settings.embedModel = new OpenAIEmbedding({
110+
model: process.env.EMBEDDING_MODEL,
91111
dimensions: process.env.EMBEDDING_DIM
92112
? parseInt(process.env.EMBEDDING_DIM)
93113
: undefined,
94-
azure: azureConfig,
114+
azure: {
115+
...azureConfig,
116+
deployment: process.env.AZURE_OPENAI_EMBEDDING_DEPLOYMENT,
117+
},
95118
});
96119
}
97120

0 commit comments

Comments
 (0)