Skip to content

Commit d3079d7

Browse files
authored
[Inference] Fix Azure hostname check (#222499)
## Summary Fixes the Azure hostname check ### Checklist - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios
1 parent 937c5f9 commit d3079d7

File tree

2 files changed

+50
-2
lines changed

2 files changed

+50
-2
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
import { type InferenceConnector, InferenceConnectorType } from './connectors';
9+
import { getConnectorModel } from './get_connector_model';
10+
11+
describe('getConnectorModel', () => {
12+
describe('Azure hostname check', () => {
13+
it('should return a model from the Azure URL', () => {
14+
const connector = {
15+
type: InferenceConnectorType.OpenAI,
16+
config: {
17+
apiUrl: 'https://azure.com/v1/models/gpt-4',
18+
},
19+
} as unknown as InferenceConnector;
20+
21+
const model = getConnectorModel(connector);
22+
expect(model).toBe('gpt-4');
23+
});
24+
25+
it('should return a model from the Azure URL with subdomain', () => {
26+
const connector = {
27+
type: InferenceConnectorType.OpenAI,
28+
config: {
29+
apiUrl: 'https://subdomain.azure.com/v1/models/gpt-4o',
30+
},
31+
} as unknown as InferenceConnector;
32+
33+
const model = getConnectorModel(connector);
34+
expect(model).toBe('gpt-4o');
35+
});
36+
37+
it('should return undefined for unsupported API URL', () => {
38+
const connector = {
39+
type: InferenceConnectorType.OpenAI,
40+
config: {
41+
apiUrl: 'https://fake-azure.com/v1/models/unknown-model',
42+
},
43+
} as unknown as InferenceConnector;
44+
45+
const model = getConnectorModel(connector);
46+
expect(model).toBeUndefined();
47+
});
48+
});
49+
});

x-pack/platform/packages/shared/ai-infra/inference-common/src/connectors/get_connector_model.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,9 @@ const OPENAI_MODEL_NAMES = [
4141

4242
function getOpenAiModelFromUrl(apiUrl: string) {
4343
const url = new URL(apiUrl);
44-
if (url.hostname.endsWith('azure.com')) {
44+
if (url.hostname === 'azure.com' || url.hostname.endsWith('.azure.com')) {
4545
return OPENAI_MODEL_NAMES.find((modelName) => {
4646
return url.pathname.includes(modelName);
4747
});
4848
}
49-
return undefined;
5049
}

0 commit comments

Comments
 (0)