Skip to content

Commit e21e254

Browse files
authored
Merge pull request #49 from code-kern-ai/refinery-reduction
Refinery reduction
2 parents 96f58fc + 5c2bf02 commit e21e254

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+91
-4326
lines changed

src/components/projects/projectId/attributes/attributeId/AttributeCalculations.tsx

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import { TOOLTIPS_DICT } from "@/src/util/tooltip-constants";
2424
import { selectAllUsers, selectOrganizationId, setComments } from "@/src/reduxStore/states/general";
2525
import { CommentDataManager } from "@/src/util/classes/comments";
2626
import { CommentType } from "@/src/types/shared/comments";
27-
import BricksIntegrator from "@/src/components/shared/bricks-integrator/BricksIntegrator";
2827
import { AttributeCodeLookup } from "@/src/util/classes/attribute-calculation";
2928
import KernDropdown from "@/submodules/react-components/components/KernDropdown";
3029
import { useWebsocket } from "@/submodules/react-components/hooks/web-socket/useWebsocket";
@@ -35,6 +34,7 @@ import { getLookupListsByProjectId } from "@/src/services/base/lookup-lists";
3534
import { getLabelingTasksByProjectId, getProjectTokenization } from "@/src/services/base/project";
3635
import { getAttributeByAttributeId, updateAttribute } from "@/src/services/base/project-setting";
3736
import { Application, CurrentPage } from "@/submodules/react-components/hooks/web-socket/constants";
37+
import { VisitBricksButton } from "@/src/components/shared/bricks/VisitBricksButton";
3838

3939
const EDITOR_OPTIONS = { theme: 'vs-light', language: 'python', readOnly: false };
4040

@@ -53,18 +53,13 @@ export default function AttributeCalculation() {
5353
const [isNameOpen, setIsNameOpen] = useState(false);
5454
const [duplicateNameExists, setDuplicateNameExists] = useState(false);
5555
const [tooltipsArray, setTooltipsArray] = useState<string[]>([]);
56-
const [isInitial, setIsInitial] = useState(null); //null as add state to differentiate between initial, not and unchecked
5756
const [editorOptions, setEditorOptions] = useState(EDITOR_OPTIONS);
5857
const [tokenizationProgress, setTokenizationProgress] = useState(0);
5958
const [editorValue, setEditorValue] = useState('');
6059
const [attributeName, setAttributeName] = useState('');
6160
const [checkUnsavedChanges, setCheckUnsavedChanges] = useState(false);
6261
const [enableRunButton, setEnableButton] = useState(false);
6362

64-
useEffect(() => {
65-
if (!currentAttribute) return;
66-
if (isInitial == null) setIsInitial(AttributeCodeLookup.isCodeStillTemplate(currentAttribute.sourceCode, currentAttribute.dataType))
67-
}, [currentAttribute]);
6863

6964
useEffect(() => {
7065
if (!projectId) return;
@@ -202,9 +197,6 @@ export default function AttributeCalculation() {
202197
}, attributeNew.dataType);
203198
}
204199

205-
function openBricksIntegrator() {
206-
document.getElementById('bricks-integrator-open-button').click();
207-
}
208200

209201
function onScrollEvent(event: any) {
210202
if (!(event.target instanceof HTMLElement)) return;
@@ -233,13 +225,6 @@ export default function AttributeCalculation() {
233225
});
234226
}
235227

236-
function updateNameAndCodeBricksIntegrator(code: string) {
237-
setEditorValue(code);
238-
const regMatch: any = getPythonFunctionRegExMatch(code);
239-
updateSourceCode(code, regMatch[2]);
240-
setIsInitial(false);
241-
}
242-
243228
function refetchLabelingTasksAndProcess() {
244229
getLabelingTasksByProjectId(projectId, (res) => {
245230
const labelingTasks = postProcessLabelingTasks(res['data']['projectByProjectId']['labelingTasks']['edges']);
@@ -368,13 +353,7 @@ export default function AttributeCalculation() {
368353
<div className="flex flex-row items-center justify-between my-3">
369354
<div className="text-sm leading-5 font-medium text-gray-700 inline-block mr-2">Editor</div>
370355
<div className="flex flex-row flex-nowrap">
371-
<BricksIntegrator
372-
moduleTypeFilter="generator,classifier" functionType="Attribute"
373-
nameLookups={attributes.map(a => a.name)}
374-
preparedCode={(code: string) => {
375-
if (currentAttribute.state == AttributeState.USABLE) return;
376-
updateNameAndCodeBricksIntegrator(code);
377-
}} />
356+
<VisitBricksButton urlExtension="generators" tooltipPlacement="left" size="small" />
378357
<Tooltip content={TOOLTIPS_DICT.ATTRIBUTE_CALCULATION.AVAILABLE_LIBRARIES} placement="bottom" color="invert">
379358
<a href="https://github.com/code-kern-ai/refinery-ac-exec-env/blob/dev/requirements.txt"
380359
target="_blank"
@@ -386,19 +365,6 @@ export default function AttributeCalculation() {
386365
</div>
387366

388367
<div className="border mt-1 relative">
389-
{isInitial && <div
390-
className="absolute top-0 bottom-0 left-0 right-0 bg-gray-200 flex items-center justify-center z-10" style={{ opacity: '0.9' }}>
391-
<div className="flex flex-col gap-2">
392-
<button onClick={openBricksIntegrator}
393-
className="bg-white text-gray-900 text font-semibold px-4 py-2 rounded-md border border-gray-300 hover:bg-gray-50 focus:outline-none">
394-
Search in bricks
395-
</button>
396-
<button onClick={() => setIsInitial(false)}
397-
className="bg-white text-gray-900 text font-semibold px-4 py-2 rounded-md border border-gray-300 hover:bg-gray-50 focus:outline-none">
398-
Start from scratch
399-
</button>
400-
</div>
401-
</div>}
402368
<Editor
403369
height="400px"
404370
defaultLanguage={'python'}

src/components/projects/projectId/heuristics/HeuristicsOverview.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ import AddActiveLeanerModal from "./modals/AddActiveLearnerModal";
1414
import { postProcessingEmbeddings } from "@/src/util/components/projects/projectId/settings/embeddings-helper";
1515
import { CommentType } from "@/src/types/shared/comments";
1616
import { CommentDataManager } from "@/src/util/classes/comments";
17-
import { selectAllUsers, selectOrganizationId, setBricksIntegrator, setComments } from "@/src/reduxStore/states/general";
18-
import { getEmptyBricksIntegratorConfig } from "@/src/util/shared/bricks-integrator-helper";
17+
import { selectAllUsers, selectOrganizationId, setComments } from "@/src/reduxStore/states/general";
1918
import { useWebsocket } from "@/submodules/react-components/hooks/web-socket/useWebsocket";
2019
import { getAllComments } from "@/src/services/base/comment";
2120
import { getAttributes } from "@/src/services/base/attribute";
@@ -48,7 +47,6 @@ export function HeuristicsOverview() {
4847
dispatch(setAllAttributes(res.data['attributesByProjectId']));
4948
});
5049
}
51-
dispatch(setBricksIntegrator(getEmptyBricksIntegratorConfig()));
5250
}, [projectId]);
5351

5452
useEffect(() => {

src/components/projects/projectId/heuristics/heuristicId/active-learning/ActiveLearning.tsx

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,9 @@ import HeuristicStatistics from "../shared/HeuristicStatistics";
2121
import DangerZone from "@/src/components/shared/danger-zone/DangerZone";
2222
import { DangerZoneEnum } from "@/src/types/shared/danger-zone";
2323
import { getPythonClassName, getPythonClassRegExMatch } from "@/submodules/javascript-functions/python-functions-parser";
24-
import { selectAllUsers, setBricksIntegrator, setLabelsBricksIntegrator, setComments, selectOrganizationId } from "@/src/reduxStore/states/general";
24+
import { selectAllUsers, setComments, selectOrganizationId } from "@/src/reduxStore/states/general";
2525
import { CommentType } from "@/src/types/shared/comments";
2626
import { CommentDataManager } from "@/src/util/classes/comments";
27-
import BricksIntegrator from "@/src/components/shared/bricks-integrator/BricksIntegrator";
2827
import { InformationSourceCodeLookup, InformationSourceExamples } from "@/src/util/classes/heuristics";
2928
import { getInformationSourceTemplate } from "@/src/util/components/projects/projectId/heuristics/heuristics-helper";
3029
import KernDropdown from "@/submodules/react-components/components/KernDropdown";
@@ -35,6 +34,7 @@ import { getLabelingTasksByProjectId } from "@/src/services/base/project";
3534
import { getHeuristicByHeuristicId, getPayloadByPayloadId, updateHeuristicPost } from "@/src/services/base/heuristic";
3635
import { getEmbeddings } from "@/src/services/base/embedding";
3736
import { Application, CurrentPage } from "@/submodules/react-components/hooks/web-socket/constants";
37+
import { VisitBricksButton } from "@/src/components/shared/bricks/VisitBricksButton";
3838

3939
export default function ActiveLearning() {
4040
const dispatch = useDispatch();
@@ -49,7 +49,6 @@ export default function ActiveLearning() {
4949
const allUsers = useSelector(selectAllUsers);
5050

5151
const [lastTaskLogs, setLastTaskLogs] = useState<string[]>([]);
52-
const [isInitialAL, setIsInitialAL] = useState<boolean>(null); //null as add state to differentiate between initial, not and unchecked
5352
const [checkUnsavedChanges, setCheckUnsavedChanges] = useState(false);
5453

5554
useEffect(() => {
@@ -71,8 +70,6 @@ export default function ActiveLearning() {
7170
if (!embeddings) return;
7271
dispatch(setFilteredEmbeddings(embeddings.filter(e => embeddingRelevant(e, attributes, labelingTasks, currentHeuristic.labelingTaskId))));
7372
refetchTaskByTaskIdAndProcess();
74-
if (isInitialAL == null) setIsInitialAL(InformationSourceCodeLookup.isCodeStillTemplate(currentHeuristic.sourceCode.replace(embeddingsFiltered[0]?.name, '@@EMBEDDING@@')) != null)
75-
7673
}, [currentHeuristic]);
7774

7875
useEffect(() => {
@@ -255,23 +252,11 @@ export default function ActiveLearning() {
255252
)}
256253
</div>
257254
<div className="flex flex-row flex-nowrap items-center ml-auto">
258-
<BricksIntegrator
259-
moduleTypeFilter={currentHeuristic.labelingTaskType == 'MULTICLASS_CLASSIFICATION' ? 'classifier' : 'extractor'}
260-
executionTypeFilter="activeLearner"
261-
functionType="Heuristic"
262-
labelingTaskId={currentHeuristic.labelingTaskId}
263-
preparedCode={(code: string) => {
264-
updateSourceCode(code);
265-
setIsInitialAL(false);
266-
}}
267-
newTaskId={(value) => setValueToLabelingTask(value)}
268-
/>
255+
<VisitBricksButton tooltipPlacement="left" size="small" />
269256
</div>
270257
</div>
271258
<HeuristicsEditor
272-
isInitial={isInitialAL}
273259
updatedSourceCode={(code: string) => updateSourceCode(code)}
274-
setIsInitial={(val) => setIsInitialAL(val)}
275260
setCheckUnsavedChanges={(val) => setCheckUnsavedChanges(val)}
276261
/>
277262

src/components/projects/projectId/heuristics/heuristicId/labeling-function/LabelingFunction.tsx

Lines changed: 11 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ import { useRouter } from "next/router";
22
import HeuristicsLayout from "../shared/HeuristicsLayout";
33
import { useDispatch, useSelector } from "react-redux";
44
import { selectProjectId } from "@/src/reduxStore/states/project";
5-
import { useCallback, useEffect, useState } from "react";
5+
import { useCallback, useEffect, useMemo, useState } from "react";
66
import { selectHeuristic, setActiveHeuristics, updateHeuristicsState } from "@/src/reduxStore/states/pages/heuristics";
77
import { postProcessCurrentHeuristic, postProcessLastTaskLogs } from "@/src/util/components/projects/projectId/heuristics/heuristicId/heuristics-details-helper";
88
import { Tooltip } from "@nextui-org/react";
99
import { TOOLTIPS_DICT } from "@/src/util/tooltip-constants";
1010
import { postProcessLabelingTasks, postProcessLabelingTasksSchema } from "@/src/util/components/projects/projectId/settings/labeling-tasks-helper";
11-
import { selectVisibleAttributesHeuristics, selectLabelingTasksAll, setLabelingTasksAll, SELECT_LABELING_TASKS_ALL_SNAPSHOT_ACCESS } from "@/src/reduxStore/states/pages/settings";
11+
import { selectVisibleAttributesHeuristics, selectLabelingTasksAll, setLabelingTasksAll } from "@/src/reduxStore/states/pages/settings";
1212
import HeuristicsEditor from "../shared/HeuristicsEditor";
1313
import DangerZone from "@/src/components/shared/danger-zone/DangerZone";
1414
import HeuristicRunButtons from "../shared/HeuristicRunButtons";
@@ -22,10 +22,9 @@ import { SampleRecord } from "@/src/types/components/projects/projectId/heuristi
2222
import { getPythonFunctionRegExMatch } from "@/submodules/javascript-functions/python-functions-parser";
2323
import CalculationProgress from "./CalculationProgress";
2424
import { copyToClipboard } from "@/submodules/javascript-functions/general";
25-
import { selectAllUsers, selectOrganizationId, setBricksIntegrator, setComments } from "@/src/reduxStore/states/general";
25+
import { selectAllUsers, selectOrganizationId, setComments } from "@/src/reduxStore/states/general";
2626
import { CommentType } from "@/src/types/shared/comments";
2727
import { CommentDataManager } from "@/src/util/classes/comments";
28-
import BricksIntegrator from "@/src/components/shared/bricks-integrator/BricksIntegrator";
2928
import { InformationSourceCodeLookup, InformationSourceExamples } from "@/src/util/classes/heuristics";
3029
import { getInformationSourceTemplate } from "@/src/util/components/projects/projectId/heuristics/heuristics-helper";
3130
import KernDropdown from "@/submodules/react-components/components/KernDropdown";
@@ -36,8 +35,8 @@ import { useWebsocket } from "@/submodules/react-components/hooks/web-socket/use
3635
import { getAllComments } from "@/src/services/base/comment";
3736
import { getLabelingTasksByProjectId } from "@/src/services/base/project";
3837
import { getHeuristicByHeuristicId, getLabelingFunctionOn10Records, getPayloadByPayloadId, updateHeuristicPost } from "@/src/services/base/heuristic";
39-
import { getStoreSnapshotValue } from "@/src/reduxStore/store";
4038
import { Application, CurrentPage } from "@/submodules/react-components/hooks/web-socket/constants";
39+
import { VisitBricksButton } from "@/src/components/shared/bricks/VisitBricksButton";
4140

4241
export default function LabelingFunction() {
4342
const dispatch = useDispatch();
@@ -53,7 +52,6 @@ export default function LabelingFunction() {
5352
const [selectedAttribute, setSelectedAttribute] = useState<Attribute>(null);
5453
const [sampleRecords, setSampleRecords] = useState<SampleRecord>(null);
5554
const [displayLogWarning, setDisplayLogWarning] = useState<boolean>(false);
56-
const [isInitialLf, setIsInitialLf] = useState<boolean>(null); //null as add state to differentiate between initial, not and unchecked
5755
const [checkUnsavedChanges, setCheckUnsavedChanges] = useState(false);
5856
const [runOn10IsRunning, setRunOn10IsRunning] = useState(false);
5957
const [justClickedRun, setJustClickedRun] = useState(false);
@@ -73,9 +71,8 @@ export default function LabelingFunction() {
7371

7472
useEffect(() => {
7573
if (!currentHeuristic) return;
76-
if (isInitialLf == null) setIsInitialLf(InformationSourceCodeLookup.isCodeStillTemplate(currentHeuristic.sourceCode) != null);
7774
refetchTaskByTaskIdAndProcess();
78-
}, [currentHeuristic, isInitialLf]);
75+
}, [currentHeuristic]);
7976

8077
useEffect(() => {
8178
if (!projectId || allUsers.length == 0) return;
@@ -199,28 +196,14 @@ export default function LabelingFunction() {
199196
}
200197
}, [currentHeuristic]);
201198

202-
203-
const setValueToLabelingTask = useCallback((value: string) => {
204-
const labelingTask = labelingTasks.find(a => a.id == value);
205-
const updateHeuristic = (labelingTasks: any[], maxI: number, task?: any) => {
206-
const labelingTask = task || labelingTasks.find(a => a.id == value);
207-
if (!labelingTask && maxI > 0) {
208-
setTimeout(() => updateHeuristic(getStoreSnapshotValue(SELECT_LABELING_TASKS_ALL_SNAPSHOT_ACCESS), maxI - 1), 100);
209-
} else {
210-
updateHeuristicPost(projectId, currentHeuristic.id, labelingTask.id, currentHeuristic.sourceCode, currentHeuristic.description, currentHeuristic.name, (res) => {
211-
dispatch(updateHeuristicsState(currentHeuristic.id, { labelingTaskId: labelingTask.id, labelingTaskName: labelingTask.name, labels: labelingTask.labels }))
212-
});
213-
}
214-
}
215-
if (!labelingTask) {
216-
//try timeout as this is usually caused by race condition (creating the task+label through the integrator)
217-
setTimeout(() => updateHeuristic(getStoreSnapshotValue(SELECT_LABELING_TASKS_ALL_SNAPSHOT_ACCESS), 5), 100);
218-
} else updateHeuristic(labelingTasks, 0, labelingTask);
219-
}, [projectId, currentHeuristic, labelingTasks])
220-
221199
const orgId = useSelector(selectOrganizationId);
222200
useWebsocket(orgId, Application.REFINERY, CurrentPage.LABELING_FUNCTION, handleWebsocketNotification, projectId);
223201

202+
const bricksUrlExtension = useMemo(() => {
203+
if (currentHeuristic?.labelingTaskType == 'INFORMATION_EXTRACTION') return 'extractors';
204+
return "classifiers"
205+
}, [currentHeuristic?.labelingTaskType]);
206+
224207
return (
225208
<HeuristicsLayout updateSourceCode={(code: string) => updateSourceCodeToDisplay(code)}>
226209
{currentHeuristic && <div>
@@ -244,18 +227,7 @@ export default function LabelingFunction() {
244227
</div>
245228
<div className="flex items-center justify-center flex-shrink-0">
246229
<div className="flex flex-row flex-nowrap items-center ml-auto">
247-
<BricksIntegrator
248-
moduleTypeFilter={currentHeuristic.labelingTaskType == 'MULTICLASS_CLASSIFICATION' ? 'classifier' : 'extractor'}
249-
executionTypeFilter="pythonFunction,premium"
250-
functionType="Heuristic"
251-
labelingTaskId={currentHeuristic.labelingTaskId}
252-
preparedCode={(code: string) => {
253-
updateSourceCode(code);
254-
setIsInitialLf(false);
255-
}}
256-
newTaskId={(value) => setValueToLabelingTask(value)}
257-
/>
258-
230+
<VisitBricksButton urlExtension={bricksUrlExtension} tooltipPlacement="left" size="small" />
259231
<Tooltip content={TOOLTIPS_DICT.LABELING_FUNCTION.INSTALLED_LIBRARIES} color="invert" placement="left">
260232
<a href="https://github.com/code-kern-ai/refinery-lf-exec-env/blob/dev/requirements.txt"
261233
target="_blank"
@@ -267,9 +239,7 @@ export default function LabelingFunction() {
267239
</div>
268240
</div>
269241
<HeuristicsEditor
270-
isInitial={isInitialLf}
271242
updatedSourceCode={(code: string) => updateSourceCode(code)}
272-
setIsInitial={(val: boolean) => setIsInitialLf(val)}
273243
setCheckUnsavedChanges={(val: boolean) => setCheckUnsavedChanges(val)} />
274244

275245
<div className="mt-2 flex flex-grow justify-between items-center float-right">

0 commit comments

Comments
 (0)