Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Security solution] Add model parameter to token telemetry #187783

Merged
merged 1 commit into from
Jul 8, 2024
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
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