Skip to content

Commit

Permalink
[Security solution] Add model parameter to token telemetry (elastic#1…
Browse files Browse the repository at this point in the history
  • Loading branch information
stephmilovic committed Jul 8, 2024
1 parent 92099b2 commit 2b5ff77
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
28 changes: 27 additions & 1 deletion x-pack/plugins/actions/server/lib/action_executor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1695,10 +1695,35 @@ describe('Event log', () => {
{ actionTypeId: '.gen-ai', completion_tokens: 9, prompt_tokens: 10, total_tokens: 19 }
);
});
test('reports telemetry for token count events with additional properties', async () => {
const executorMock = setupActionExecutorMock('.gen-ai', {} as ConnectorType['validate'], {
defaultModel: 'gpt-4',
apiProvider: 'OpenAI',
});
executorMock.mockResolvedValue({
actionId: '1',
status: 'ok',
// @ts-ignore
data: mockGenAi,
});
await actionExecutor.execute(executeParams);
expect(actionExecutorInitializationParams.analyticsService.reportEvent).toHaveBeenCalledWith(
GEN_AI_TOKEN_COUNT_EVENT.eventType,
{
actionTypeId: '.gen-ai',
completion_tokens: 9,
prompt_tokens: 10,
total_tokens: 19,
model: 'gpt-4',
provider: 'OpenAI',
}
);
});
});
function setupActionExecutorMock(
actionTypeId = 'test',
validationOverride?: ConnectorType['validate']
validationOverride?: ConnectorType['validate'],
additionalConfig?: Record<string, unknown>
) {
const thisConnectorType: jest.Mocked<ConnectorType> = {
...connectorType,
Expand All @@ -1712,6 +1737,7 @@ function setupActionExecutorMock(
actionTypeId,
config: {
bar: true,
...additionalConfig,
},
secrets: {
baz: true,
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/actions/server/lib/action_executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,7 @@ export class ActionExecutor {
...(actionTypeId === '.gen-ai' && config?.apiProvider != null
? { provider: config?.apiProvider }
: {}),
...(config?.defaultModel != null ? { model: config?.defaultModel } : {}),
});
}
})
Expand Down
8 changes: 8 additions & 0 deletions x-pack/plugins/actions/server/lib/event_based_telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const GEN_AI_TOKEN_COUNT_EVENT: EventTypeOpts<{
prompt_tokens: number;
completion_tokens: number;
provider?: string;
model?: string;
}> = {
eventType: 'gen_ai_token_count',
schema: {
Expand Down Expand Up @@ -51,6 +52,13 @@ export const GEN_AI_TOKEN_COUNT_EVENT: EventTypeOpts<{
optional: true,
},
},
model: {
type: 'keyword',
_meta: {
description: 'LLM model',
optional: true,
},
},
},
};

Expand Down

0 comments on commit 2b5ff77

Please sign in to comment.