Skip to content

Commit fbf3c9e

Browse files
committed
Pushed llm playground record post processing to helper
1 parent afeca3c commit fbf3c9e

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

src/components/projects/projectId/attributes/attributeId/LLM/LLMPlaygroundModal.tsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { DataTypeEnum } from "@/src/types/shared/general";
1818
import { runAttributeLlmPlayground } from "@/src/services/base/attribute";
1919
import { jsonCopy } from "@/submodules/javascript-functions/general";
2020
import { TEMPLATE_EXAMPLES, TEMPLATE_OPTIONS } from "./llmTemplates";
21-
import { LLM_PROVIDER_OPTIONS } from "@/src/util/components/projects/projectId/settings/attribute-calculation-helper";
21+
import { LLM_PROVIDER_OPTIONS, postProcessLLMPlaygroundRecordData } from "@/src/util/components/projects/projectId/settings/attribute-calculation-helper";
2222

2323
const ACCEPT_BUTTON = { buttonCaption: "Use current values for attribute", useButton: true };
2424
const DISPLAY_STATES = [AttributeState.AUTOMATICALLY_CREATED, AttributeState.UPLOADED, AttributeState.USABLE]
@@ -45,15 +45,12 @@ export default function LLMPlaygroundModal() {
4545
const searchAndSetWithFilter = useCallback((filter) => {
4646
searchRecordsExtended(projectId, filter, 0, 1, (res) => {
4747
if (res && res.recordList) {
48-
if (res.recordList.length == 0) {
48+
const parsedData = postProcessLLMPlaygroundRecordData(res.recordList);
49+
if (!parsedData) {
4950
console.warn("No records found -> using random instead");
5051
get1RandomRecords();
5152
return;
5253
}
53-
const parsedData = res.recordList.map((record) => {
54-
const parsed = JSON.parse(record.recordData);
55-
return ({ ...parsed.data, id: parsed.id });
56-
});
5754
setRecordData(parsedData);
5855
}
5956
});

src/util/components/projects/projectId/settings/attribute-calculation-helper.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,11 @@ export const LLM_PROVIDER_OPTIONS = [
4848
'Open AI',
4949
'Azure'
5050
];
51+
52+
export function postProcessLLMPlaygroundRecordData(recordList: any[]): any[] {
53+
if (!recordList || recordList.length == 0) return null;
54+
return recordList.map((record) => {
55+
const parsed = JSON.parse(record.recordData);
56+
return ({ ...parsed.data, id: parsed.id });
57+
});
58+
}

0 commit comments

Comments
 (0)