Skip to content

Commit 448004f

Browse files
committed
fix(llm): properly send prompt variable
1 parent e8534fe commit 448004f

File tree

7 files changed

+23
-29
lines changed

7 files changed

+23
-29
lines changed

services/api/src/app.ts

+3
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ const configSchema = z.object({
9494
AWS_SECRET_REGION: z.string().optional(),
9595
AWS_AI_LABEL_SUMMARY_PROMPT_ARN: z.string().optional(),
9696
AWS_AI_LABEL_SUMMARY_PROMPT_REGION: z.string().default("us-east-1"),
97+
AWS_AI_LABEL_SUMMARY_PROMPT_VARIABLE: z
98+
.string()
99+
.default("conversationInsights"),
97100
DB_HOST: z.string().optional(),
98101
DB_PORT: z.coerce.number().int().nonnegative().default(5432),
99102
DB_NAME: z.string().default("agora"),

services/api/src/commands/polis/import.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,8 @@ async function importToAgora({
408408
axiosPolis,
409409
polisDelayToFetch: 0,
410410
awsAiLabelSummaryPromptArn: undefined, // too expensive to run it at every import..
411-
awsAiLabelSummaryPromptRegion: "",
411+
awsAiLabelSummaryPromptRegion: "", // unused because of the above
412+
awsAiLabelSummaryPromptVariable: "", // unused because of the above
412413
});
413414
});
414415
log.info("Import done");

services/api/src/index.ts

+2-5
Original file line numberDiff line numberDiff line change
@@ -976,6 +976,8 @@ server.after(() => {
976976
actualAwsAiLabelSummaryPromptArn,
977977
awsAiLabelSummaryPromptRegion:
978978
config.AWS_AI_LABEL_SUMMARY_PROMPT_REGION,
979+
awsAiLabelSummaryPromptVariable:
980+
config.AWS_AI_LABEL_SUMMARY_PROMPT_VARIABLE,
979981
});
980982
reply.send(castVoteResponse);
981983
const proofChannel40EventId =
@@ -1149,11 +1151,6 @@ server.after(() => {
11491151
didWrite: didWrite,
11501152
proof: encodedUcan,
11511153
axiosPolis: axiosPolis,
1152-
polisDelayToFetch: config.POLIS_DELAY_TO_FETCH,
1153-
awsAiLabelSummaryPromptArn:
1154-
actualAwsAiLabelSummaryPromptArn,
1155-
awsAiLabelSummaryPromptRegion:
1156-
config.AWS_AI_LABEL_SUMMARY_PROMPT_REGION,
11571154
});
11581155
reply.send(newOpinionResponse);
11591156
const proofChannel40EventId =

services/api/src/service/comment.ts

-22
Original file line numberDiff line numberDiff line change
@@ -1018,9 +1018,6 @@ interface PostNewOpinionProps {
10181018
didWrite: string;
10191019
proof: string;
10201020
axiosPolis: AxiosInstance | undefined;
1021-
polisDelayToFetch: number;
1022-
awsAiLabelSummaryPromptArn: string | undefined;
1023-
awsAiLabelSummaryPromptRegion: string;
10241021
}
10251022

10261023
interface ImportNewOpinionProps {
@@ -1116,9 +1113,6 @@ export async function postNewOpinion({
11161113
didWrite,
11171114
proof,
11181115
axiosPolis,
1119-
polisDelayToFetch,
1120-
awsAiLabelSummaryPromptArn,
1121-
awsAiLabelSummaryPromptRegion,
11221116
}: PostNewOpinionProps): Promise<CreateCommentResponse> {
11231117
const isLocked = await useCommonPost().isPostSlugIdLocked({
11241118
postSlugId: conversationSlugId,
@@ -1252,22 +1246,6 @@ export async function postNewOpinion({
12521246
}
12531247
});
12541248

1255-
if (axiosPolis !== undefined) {
1256-
polisService
1257-
.delayedPolisGetAndUpdateMath({
1258-
db,
1259-
conversationId,
1260-
conversationSlugId,
1261-
axiosPolis,
1262-
polisDelayToFetch,
1263-
awsAiLabelSummaryPromptArn,
1264-
awsAiLabelSummaryPromptRegion,
1265-
})
1266-
.catch((e: unknown) => {
1267-
log.error(e);
1268-
});
1269-
}
1270-
12711249
return {
12721250
success: true,
12731251
opinionSlugId: opinionSlugId,

services/api/src/service/llmLabelSummary.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ interface UpdateAiLabelsAndSummariesProps {
3131
conversationId: number;
3232
awsAiLabelSummaryPromptArn: string | undefined;
3333
awsAiLabelSummaryPromptRegion: string;
34+
awsAiLabelSummaryPromptVariable: string;
3435
}
3536

3637
interface OpinionInsight {
@@ -59,6 +60,7 @@ export async function updateAiLabelsAndSummaries({
5960
conversationId,
6061
awsAiLabelSummaryPromptArn,
6162
awsAiLabelSummaryPromptRegion,
63+
awsAiLabelSummaryPromptVariable,
6264
}: UpdateAiLabelsAndSummariesProps): Promise<void> {
6365
if (awsAiLabelSummaryPromptArn === undefined) {
6466
log.warn(
@@ -74,6 +76,7 @@ export async function updateAiLabelsAndSummaries({
7476
conversationInsights,
7577
awsAiLabelSummaryPromptArn,
7678
awsAiLabelSummaryPromptRegion,
79+
awsAiLabelSummaryPromptVariable,
7780
});
7881
await doUpdateAiLabelsAndSummaries({
7982
db,
@@ -177,12 +180,14 @@ interface InvokeRemoteModelProps {
177180
conversationInsights: ConversationInsights;
178181
awsAiLabelSummaryPromptArn: string;
179182
awsAiLabelSummaryPromptRegion: string;
183+
awsAiLabelSummaryPromptVariable: string;
180184
}
181185

182186
async function invokeRemoteModel({
183187
conversationInsights,
184188
awsAiLabelSummaryPromptArn,
185189
awsAiLabelSummaryPromptRegion,
190+
awsAiLabelSummaryPromptVariable,
186191
}: InvokeRemoteModelProps): Promise<
187192
GenLabelSummaryOutputStrict | GenLabelSummaryOutputLoose
188193
> {
@@ -193,7 +198,11 @@ async function invokeRemoteModel({
193198
modelId: awsAiLabelSummaryPromptArn,
194199
contentType: "application/json",
195200
accept: "application/json",
196-
body: JSON.stringify(conversationInsights),
201+
body: JSON.stringify({
202+
promptVariables: {
203+
[awsAiLabelSummaryPromptVariable]: conversationInsights,
204+
},
205+
}),
197206
});
198207
// we let this throw if any error occurs, it will be caught by the generic error handler
199208
const response = await client.send(command);

services/api/src/service/polis.ts

+3
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ interface DelayedPolisGetAndUpdateMathProps {
190190
polisDelayToFetch: number;
191191
awsAiLabelSummaryPromptArn: string | undefined;
192192
awsAiLabelSummaryPromptRegion: string;
193+
awsAiLabelSummaryPromptVariable: string;
193194
}
194195

195196
export async function delayedPolisGetAndUpdateMath({
@@ -200,6 +201,7 @@ export async function delayedPolisGetAndUpdateMath({
200201
polisDelayToFetch,
201202
awsAiLabelSummaryPromptArn,
202203
awsAiLabelSummaryPromptRegion,
204+
awsAiLabelSummaryPromptVariable,
203205
}: DelayedPolisGetAndUpdateMathProps) {
204206
if (polisDelayToFetch === -1) {
205207
log.info("Get polis math results is turned off");
@@ -790,6 +792,7 @@ export async function delayedPolisGetAndUpdateMath({
790792
conversationId: conversationId,
791793
awsAiLabelSummaryPromptArn: awsAiLabelSummaryPromptArn,
792794
awsAiLabelSummaryPromptRegion,
795+
awsAiLabelSummaryPromptVariable,
793796
});
794797
});
795798
}

services/api/src/service/voting.ts

+3
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,7 @@ interface CastVoteForOpinionSlugIdProps {
318318
voteNotifMilestones: number[];
319319
awsAiLabelSummaryPromptArn: string | undefined;
320320
awsAiLabelSummaryPromptRegion: string;
321+
awsAiLabelSummaryPromptVariable: string;
321322
}
322323

323324
export async function castVoteForOpinionSlugId({
@@ -332,6 +333,7 @@ export async function castVoteForOpinionSlugId({
332333
voteNotifMilestones,
333334
awsAiLabelSummaryPromptArn,
334335
awsAiLabelSummaryPromptRegion,
336+
awsAiLabelSummaryPromptVariable,
335337
}: CastVoteForOpinionSlugIdProps): Promise<boolean> {
336338
const { conversationSlugId, conversationId } =
337339
await useCommonComment().getOpinionMetadataFromOpinionSlugId({
@@ -695,6 +697,7 @@ export async function castVoteForOpinionSlugId({
695697
polisDelayToFetch,
696698
awsAiLabelSummaryPromptArn,
697699
awsAiLabelSummaryPromptRegion,
700+
awsAiLabelSummaryPromptVariable, // unused because of the above
698701
})
699702
.catch((e: unknown) => {
700703
log.error(e);

0 commit comments

Comments
 (0)