feat(AI Transform Node): Telemetry (no-changelog) (#10398)

This commit is contained in:
Michael Kret 2024-08-14 16:41:35 +03:00 committed by GitHub
parent 4d222ac19d
commit 4dc34ba745
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 31 additions and 3 deletions

View file

@ -10,6 +10,7 @@ import { getSchemas, getParentNodes } from './utils';
import { ASK_AI_EXPERIMENT } from '@/constants'; import { ASK_AI_EXPERIMENT } from '@/constants';
import { usePostHog } from '@/stores/posthog.store'; import { usePostHog } from '@/stores/posthog.store';
import { useRootStore } from '@/stores/root.store'; import { useRootStore } from '@/stores/root.store';
import { useTelemetry } from '@/composables/useTelemetry';
import { generateCodeForPrompt } from '@/api/ai'; import { generateCodeForPrompt } from '@/api/ai';
import { format } from 'prettier'; import { format } from 'prettier';
@ -144,6 +145,11 @@ async function onSubmit() {
}; };
emit('valueChanged', updateInformation); emit('valueChanged', updateInformation);
useTelemetry().trackAiTransform('generationFinished', {
prompt: prompt.value,
code: formattedCode,
});
break; break;
default: default:
return; return;
@ -156,6 +162,11 @@ async function onSubmit() {
stopLoading(); stopLoading();
} catch (error) { } catch (error) {
useTelemetry().trackAiTransform('generationFinished', {
prompt: prompt.value,
code: '',
hasError: true,
});
showMessage({ showMessage({
type: 'error', type: 'error',
title: i18n.baseText('codeNodeEditor.askAi.generationFailed'), title: i18n.baseText('codeNodeEditor.askAi.generationFailed'),

View file

@ -167,6 +167,20 @@ export class Telemetry {
} }
} }
trackAiTransform(event: string, properties: IDataObject = {}) {
if (this.rudderStack) {
properties.session_id = useRootStore().pushRef;
properties.ndv_session_id = useNDVStore().pushRef;
switch (event) {
case 'generationFinished':
this.track('Ai Transform code generation finished', properties, { withPostHog: true });
default:
break;
}
}
}
trackNodesPanel(event: string, properties: IDataObject = {}) { trackNodesPanel(event: string, properties: IDataObject = {}) {
if (this.rudderStack) { if (this.rudderStack) {
properties.nodes_panel_session_id = this.userNodesPanelSession.pushRef; properties.nodes_panel_session_id = this.userNodesPanelSession.pushRef;

View file

@ -32,7 +32,7 @@ export class AiTransform implements INodeType {
properties: [ properties: [
{ {
displayName: 'Instructions', displayName: 'Instructions',
name: 'generate', name: 'instructions',
type: 'button', type: 'button',
default: '', default: '',
description: description:
@ -92,7 +92,7 @@ export class AiTransform implements INodeType {
code = this.getNodeParameter(codeParameterName, index) as string; code = this.getNodeParameter(codeParameterName, index) as string;
if (!code) { if (!code) {
const instructions = this.getNodeParameter('generate', index) as string; const instructions = this.getNodeParameter('instructions', index) as string;
if (!instructions) { if (!instructions) {
throw new NodeOperationError(node, 'Missing instructions to generate code', { throw new NodeOperationError(node, 'Missing instructions to generate code', {
description: description:

View file

@ -13,6 +13,7 @@ import type {
import { ApplicationError } from './errors/application.error'; import { ApplicationError } from './errors/application.error';
import { import {
AGENT_LANGCHAIN_NODE_TYPE, AGENT_LANGCHAIN_NODE_TYPE,
AI_TRANSFORM_NODE_TYPE,
CHAIN_LLM_LANGCHAIN_NODE_TYPE, CHAIN_LLM_LANGCHAIN_NODE_TYPE,
CHAIN_SUMMARIZATION_LANGCHAIN_NODE_TYPE, CHAIN_SUMMARIZATION_LANGCHAIN_NODE_TYPE,
EXECUTE_WORKFLOW_NODE_TYPE, EXECUTE_WORKFLOW_NODE_TYPE,
@ -207,7 +208,9 @@ export function generateNodesGraph(
nodeItem.src_node_id = options.nodeIdMap[node.id]; nodeItem.src_node_id = options.nodeIdMap[node.id];
} }
if (node.type === AGENT_LANGCHAIN_NODE_TYPE) { if (node.type === AI_TRANSFORM_NODE_TYPE && options?.isCloudDeployment) {
nodeItem.prompts = { instructions: node.parameters.instructions as string };
} else if (node.type === AGENT_LANGCHAIN_NODE_TYPE) {
nodeItem.agent = (node.parameters.agent as string) ?? 'conversationalAgent'; nodeItem.agent = (node.parameters.agent as string) ?? 'conversationalAgent';
} else if (node.type === MERGE_NODE_TYPE) { } else if (node.type === MERGE_NODE_TYPE) {
nodeItem.operation = node.parameters.mode as string; nodeItem.operation = node.parameters.mode as string;