generated from ubiquity-os/plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathfind-ground-truths.ts
57 lines (52 loc) · 2.18 KB
/
find-ground-truths.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import { Context } from "../../types";
import { AppParamsHelper, GroundTruthsSystemMessage, ModelApplications } from "../../types/llm";
import { GROUND_TRUTHS_SYSTEM_MESSAGES } from "./prompts";
import { chatBotPayloadTypeguard, codeReviewPayloadTypeguard } from "../../types/typeguards";
import { validateGroundTruths } from "./validate";
import { logger } from "../../helpers/errors";
import { createGroundTruthSysMsg } from "./create-system-message";
export async function findGroundTruths<TApp extends ModelApplications = ModelApplications>(
context: Context,
application: TApp,
params: AppParamsHelper<TApp>
): Promise<string[]> {
const systemMsgObj = GROUND_TRUTHS_SYSTEM_MESSAGES[application];
// params are deconstructed to show quickly what's being passed to the function
if (chatBotPayloadTypeguard(params)) {
const { dependencies, devDependencies, languages } = params;
return findChatBotTruths(context, { dependencies, devDependencies, languages }, systemMsgObj);
} else if (codeReviewPayloadTypeguard(params)) {
const { taskSpecification } = params;
return findCodeReviewTruths(context, { taskSpecification }, systemMsgObj);
} else {
throw logger.error("Invalid payload type for ground truths");
}
}
async function findChatBotTruths(
context: Context,
params: AppParamsHelper<"chat-bot">,
systemMsgObj: GroundTruthsSystemMessage<"chat-bot">
): Promise<string[]> {
const {
adapters: {
openai: { completions },
},
} = context;
const systemMsg = createGroundTruthSysMsg(systemMsgObj);
const truths = await completions.createGroundTruthCompletion<"chat-bot">(context, JSON.stringify(params), systemMsg, "o1-mini");
return validateGroundTruths(truths);
}
async function findCodeReviewTruths(
context: Context,
params: AppParamsHelper<"code-review">,
systemMsgObj: GroundTruthsSystemMessage<"code-review">
): Promise<string[]> {
const {
adapters: {
openai: { completions },
},
} = context;
const systemMsg = createGroundTruthSysMsg(systemMsgObj);
const truths = await completions.createGroundTruthCompletion<"code-review">(context, params.taskSpecification, systemMsg, "gpt-4o");
return validateGroundTruths(truths);
}