Skip to content

Commit d946dea

Browse files
authored
fix: Cherry-pick PR #14487: Fix OpenAI model configuration in Azure AI Search template (#14490)
* Initial plan * Cherry-pick #14487: fix openai model in azure ai search template for dev branch - Add conditional OpenAI model configuration in app.js.tpl and app.ts.tpl - Fix API key reference from azureOpenAIApiKey to apiKey for OpenAI scenarios - Ensures proper model configuration for both OpenAI and Azure OpenAI --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]>
1 parent 47cd3fc commit d946dea

File tree

4 files changed

+18
-2
lines changed

4 files changed

+18
-2
lines changed

templates/vsc/js/custom-copilot-rag-azure-ai-search/src/app/app.js.tpl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,20 @@ app.on('message', async ({ send, activity }) => {
8585
const prompt = new ChatPrompt({
8686
messages,
8787
instructions: enhancedInstructions,
88+
{{#useOpenAI}}
89+
model: new OpenAIChatModel({
90+
model: config.openAIModelName,
91+
apiKey: config.openAIKey
92+
})
93+
{{/useOpenAI}}
94+
{{#useAzureOpenAI}}
8895
model: new OpenAIChatModel({
8996
model: config.azureOpenAIDeploymentName,
9097
apiKey: config.azureOpenAIKey,
9198
endpoint: config.azureOpenAIEndpoint,
9299
apiVersion: "2024-10-21"
93100
})
101+
{{/useAzureOpenAI}}
94102
});
95103

96104
const response = await prompt.send(activity.text);

templates/vsc/js/custom-copilot-rag-azure-ai-search/src/app/azureAISearchDataSource.js.tpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ class AzureAISearchDataSource {
104104
async getEmbeddingVector(text) {
105105
{{#useOpenAI}}
106106
const client = new OpenAI({
107-
apiKey: this.options.azureOpenAIApiKey
107+
apiKey: this.options.apiKey
108108
});
109109
const result = await client.embeddings.create({
110110
input: text,

templates/vsc/ts/custom-copilot-rag-azure-ai-search/src/app/app.ts.tpl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,20 @@ app.on('message', async ({ send, activity }) => {
8686
const prompt = new ChatPrompt({
8787
messages,
8888
instructions: enhancedInstructions,
89+
{{#useOpenAI}}
90+
model: new OpenAIChatModel({
91+
model: config.openAIModelName,
92+
apiKey: config.openAIKey
93+
})
94+
{{/useOpenAI}}
95+
{{#useAzureOpenAI}}
8996
model: new OpenAIChatModel({
9097
model: config.azureOpenAIDeploymentName,
9198
apiKey: config.azureOpenAIKey,
9299
endpoint: config.azureOpenAIEndpoint,
93100
apiVersion: "2024-10-21"
94101
})
102+
{{/useAzureOpenAI}}
95103
});
96104

97105
const response = await prompt.send(activity.text);

templates/vsc/ts/custom-copilot-rag-azure-ai-search/src/app/azureAISearchDataSource.ts.tpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ export class AzureAISearchDataSource {
168168
private async getEmbeddingVector(text: string): Promise<number[]> {
169169
{{#useOpenAI}}
170170
const client = new OpenAI({
171-
apiKey: this.options.azureOpenAIApiKey
171+
apiKey: this.options.apiKey
172172
});
173173
const result = await client.embeddings.create({
174174
input: text,

0 commit comments

Comments
 (0)