Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import {
getGenAiConfig,
getActionTypeTitle,
getConnectorTypeTitle,
GenAiConfig,
OpenAiProviderType,
AiConfigCatchAll,
} from './helpers';
import { PRECONFIGURED_CONNECTOR } from './translations';
import {
Expand All @@ -19,7 +19,7 @@ import {
type ActionTypeRegistryContract,
} from '@kbn/alerts-ui-shared';

const mockConnector = (config: GenAiConfig, isPreconfigured = false) => ({
const mockConnector = (config: AiConfigCatchAll, isPreconfigured = false) => ({
isPreconfigured,
config,
actionTypeId: 'test-action',
Expand All @@ -43,6 +43,17 @@ describe('getGenAiConfig', () => {
});
});

test('extracts defaultModel from inference config', () => {
const connector = mockConnector({
providerConfig: {
model_id: 'rainbow-sprinkles',
},
}) as ActionConnector;
expect(getGenAiConfig(connector)).toEqual({
defaultModel: 'rainbow-sprinkles',
});
});

test('extracts api-version from Azure API URL', () => {
const connector = mockConnector({
apiProvider: OpenAiProviderType.AzureAi,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,44 @@ export interface GenAiConfig {
defaultModel?: string;
}

export interface AiConfigCatchAll {
apiProvider?: OpenAiProviderType;
apiUrl?: string;
defaultModel?: string;
// inference fields
providerConfig?: {
model_id?: string;
};
model_id?: string;
url?: string;
}

/**
* Returns the GenAiConfig for a given ActionConnector. Note that if the connector is preconfigured,
* the config MAY be undefined if exposeConfig: true is absent
*
* @param connector
*/
export const getGenAiConfig = (connector: ActionConnector | undefined): GenAiConfig => {
const config = (connector as ActionConnectorProps<GenAiConfig, unknown>)?.config;
const { apiProvider, apiUrl, defaultModel } = config ?? {};
return {
const config = (connector as ActionConnectorProps<AiConfigCatchAll, unknown>)?.config;
const {
apiProvider,
apiUrl,
defaultModel,
providerConfig,
model_id: modelId,
url,
} = config ?? {};

return {
apiProvider,
apiUrl: apiUrl ?? url,
defaultModel:
apiProvider === OpenAiProviderType.AzureAi
(apiProvider === OpenAiProviderType.AzureAi
? getAzureApiVersionParameter(apiUrl ?? '')
: defaultModel,
: defaultModel) ??
providerConfig?.model_id ??
modelId,
};
};

Expand Down