|
| 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 | +}); |
0 commit comments