Skip to content

Commit b9c3f7a

Browse files
committed
refactor: add session id and mode
1 parent 86c8e7e commit b9c3f7a

File tree

4 files changed

+22
-5
lines changed

4 files changed

+22
-5
lines changed

packages/backend/src/graphql/__tests__/mutations/ai/generate-ai-steps.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ const DEFAULT_MOCKED_OUTPUT = {
7474
const DEFAULT_INPUT = {
7575
prompt:
7676
'#### Start the workflow\nNew FormSG submission\n\n#### Actions\nSend a welcome email to the new user\nSend a welcome SMS to the new user',
77+
isFormMode: true,
78+
sessionId: '123',
7779
}
7880

7981
describe('generateAiSteps mutation', () => {

packages/backend/src/graphql/mutations/ai/generate-ai-steps.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const generateAiSteps: MutationResolvers['generateAiSteps'] = async (
3333

3434
try {
3535
const validatedInput = INPUT_SCHEMA.parse(params.input)
36-
const { prompt: userPrompt } = validatedInput
36+
const { prompt: userPrompt, isFormMode, sessionId } = validatedInput
3737

3838
if (!context.currentUser) {
3939
throw new ForbiddenError('Not authorised!')
@@ -47,12 +47,23 @@ const generateAiSteps: MutationResolvers['generateAiSteps'] = async (
4747
const { prompt: systemPrompt } = prompt
4848

4949
const result = await startActiveObservation(
50-
'generate-ai-steps',
50+
'generate-steps',
5151
async (trace) => {
52+
const tags = ['ai-builder', 'generate-steps']
53+
// TODO(kevinkim-ogp): we add the tags based on the input mode on the frontend
54+
// whether it was from form or chat
55+
// to be removed once A/B test is complete
56+
if (isFormMode) {
57+
tags.push('form')
58+
} else {
59+
tags.push('chat')
60+
}
61+
5262
trace.updateTrace({
5363
userId: context.currentUser.email,
5464
environment: appConfig.appEnv,
55-
tags: ['graphql', 'ai-steps', 'generate-object'],
65+
tags,
66+
sessionId: sessionId ?? '',
5667
})
5768

5869
trace.update({
@@ -62,7 +73,7 @@ const generateAiSteps: MutationResolvers['generateAiSteps'] = async (
6273
})
6374

6475
const generation = trace.startObservation(
65-
'ai-stream-generation',
76+
'generate-steps',
6677
{
6778
model: MODEL_TYPE,
6879
input: [
@@ -85,7 +96,7 @@ const generateAiSteps: MutationResolvers['generateAiSteps'] = async (
8596
prompt: userPrompt,
8697
experimental_telemetry: {
8798
isEnabled: true,
88-
functionId: 'generate-ai-steps',
99+
functionId: 'generate-steps',
89100
},
90101
})
91102

packages/backend/src/graphql/mutations/ai/schemas/input.zod.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,6 @@ export const INPUT_SCHEMA = z.object({
66
.trim()
77
.min(15, 'Prompt must be at least 15 characters')
88
.max(3000, 'Prompt must not exceed 3000 characters'),
9+
isFormMode: z.boolean(),
10+
sessionId: z.string().nullish(),
911
})

packages/backend/src/graphql/schema.graphql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ type Mutation {
128128

129129
input GenerateAiStepsInput {
130130
prompt: String!
131+
isFormMode: Boolean!
132+
sessionId: String
131133
}
132134

133135
type AdminMutation {

0 commit comments

Comments
 (0)