Skip to content

Commit c98e073

Browse files
committed
add matlab, dicom, and nirs placeholder in fileProcessors.ts
1 parent 20ce77f commit c98e073

2 files changed

Lines changed: 84 additions & 149 deletions

File tree

src/components/User/Dashboard/DatasetOrganizer/LLMPanel.tsx

Lines changed: 42 additions & 148 deletions
Original file line numberDiff line numberDiff line change
@@ -133,50 +133,11 @@ const LLMPanel: React.FC<LLMPanelProps> = ({
133133
const [generatingEvidence, setGeneratingEvidence] = useState(false); // Add loading spin to evidence button
134134
const [generatingTrio, setGeneratingTrio] = useState(false); // Add loading spin to trio button
135135
const [abortController, setAbortController] =
136-
useState<AbortController | null>(null); // ✅ Add this
136+
useState<AbortController | null>(null);
137137

138-
const [panelHeight, setPanelHeight] = useState<number>(350);
138+
const [panelHeight, setPanelHeight] = useState<number>(450);
139139
const [isResizing, setIsResizing] = useState(false);
140140

141-
// Helper functions
142-
// const getCountsByExtension = (): Record<string, number> => {
143-
// const counts: Record<string, number> = {};
144-
// files.forEach((f) => {
145-
// const ext = f.fileType || "unknown";
146-
// counts[ext] = (counts[ext] || 0) + 1;
147-
// });
148-
// return counts;
149-
// };
150-
151-
// const detectModality = (): string => {
152-
// const counts = getCountsByExtension();
153-
// if (counts.nifti > 0) return "mri";
154-
// if (counts.hdf5 > 0 || files.some((f) => f.name.endsWith(".snirf")))
155-
// return "nirs";
156-
// return "mixed";
157-
// };
158-
159-
// const getUserContextText = (): string => {
160-
// const readme = files.find((f) => f.name.toLowerCase().includes("readme"));
161-
// const instructions = files.find(
162-
// (f) =>
163-
// f.name.toLowerCase().includes("conversion") ||
164-
// f.name.toLowerCase().includes("instruction")
165-
// );
166-
// const participants = files.find((f) =>
167-
// f.name.toLowerCase().includes("participant")
168-
// );
169-
170-
// const parts = [];
171-
// if (readme?.content) parts.push(`README:\n${readme.content}`);
172-
// if (instructions?.content)
173-
// parts.push(`INSTRUCTIONS:\n${instructions.content}`);
174-
// if (participants?.content)
175-
// parts.push(`PARTICIPANTS:\n${participants.content}`);
176-
177-
// return parts.join("\n\n");
178-
// };
179-
180141
// ========================================================================
181142
// BUTTON 1: GENERATE EVIDENCE BUNDLE
182143
// ========================================================================
@@ -186,70 +147,44 @@ const LLMPanel: React.FC<LLMPanelProps> = ({
186147
return;
187148
}
188149

189-
setGeneratingEvidence(true); // ✅ Add this
150+
setGeneratingEvidence(true);
190151
setError(null);
191-
setStatus("Building evidence bundle..."); // ✅ Add this
152+
setStatus("Building evidence bundle...");
192153
try {
193-
//modify
194-
// const bundle = {
195-
// root: baseDirectoryPath,
196-
// counts_by_ext: getCountsByExtension(),
197-
// all_files: files
198-
// .filter((f) => !f.isUserMeta)
199-
// .map((f) => f.sourcePath || f.name),
200-
// documents: files
201-
// .filter(
202-
// (f) => f.content && ["text", "office"].includes(f.fileType || "")
203-
// )
204-
// .map((f) => ({
205-
// relpath: f.sourcePath || f.name,
206-
// filename: f.name,
207-
// type: f.fileType || "unknown",
208-
// content: f.content || "",
209-
// })),
210-
// user_hints: {
211-
// user_text: getUserContextText(),
212-
// modality_hint: detectModality(),
213-
// n_subjects: null,
214-
// },
215-
// };
216-
// ✅ Add this debug block
217-
console.log("=== FILES GOING INTO buildEvidenceBundle ===");
218-
console.log("Total files:", files.length);
219-
console.log(
220-
"Files with content:",
221-
files.filter((f) => !!f.content).length
222-
);
223-
console.log(
224-
"Files by fileType:",
225-
files.reduce((acc, f) => {
226-
acc[f.fileType || "undefined"] =
227-
(acc[f.fileType || "undefined"] || 0) + 1;
228-
return acc;
229-
}, {} as Record<string, number>)
230-
);
231-
console.log(
232-
"isUserMeta files:",
233-
files.filter((f) => f.isUserMeta).map((f) => f.name)
234-
);
154+
// console.log("=== FILES GOING INTO buildEvidenceBundle ===");
155+
// console.log("Total files:", files.length);
156+
// console.log(
157+
// "Files with content:",
158+
// files.filter((f) => !!f.content).length
159+
// );
160+
// console.log(
161+
// "Files by fileType:",
162+
// files.reduce((acc, f) => {
163+
// acc[f.fileType || "undefined"] =
164+
// (acc[f.fileType || "undefined"] || 0) + 1;
165+
// return acc;
166+
// }, {} as Record<string, number>)
167+
// );
168+
// console.log(
169+
// "isUserMeta files:",
170+
// files.filter((f) => f.isUserMeta).map((f) => f.name)
171+
// );
235172
// ==========================================
236173
const bundle = buildEvidenceBundle(files, baseDirectoryPath);
237174

238175
setEvidenceBundle(bundle);
239176
downloadJSON(bundle, "evidence_bundle.json");
240177
setStatus("✓ Evidence bundle generated and downloaded!");
241178
} catch (err: any) {
242-
setError("Failed to generate evidence bundle"); // ✅ Add this
179+
setError("Failed to generate evidence bundle");
243180
} finally {
244-
setGeneratingEvidence(false); // ✅ Add this
181+
setGeneratingEvidence(false);
245182
}
246183
};
247184

248185
// ========================================================================
249-
// BUTTON 2: GENERATE BIDS TRIO
186+
// BUTTON 2: Generate BIDS Trio with LLM calls
250187
// ========================================================================
251-
252-
// Button 2: Generate BIDS Trio with LLM calls
253188
const handleGenerateTrio = async () => {
254189
if (!evidenceBundle) {
255190
setError("Please generate evidence bundle first");
@@ -261,7 +196,7 @@ const LLMPanel: React.FC<LLMPanelProps> = ({
261196
return;
262197
}
263198

264-
// Create abort controller
199+
// Create abort controller
265200
const controller = new AbortController();
266201
setAbortController(controller);
267202

@@ -277,19 +212,6 @@ const LLMPanel: React.FC<LLMPanelProps> = ({
277212
// ==========================================
278213
setStatus("1/3 Generating dataset_description.json...");
279214
const ddPrompt = getDatasetDescriptionPrompt(userText);
280-
// const ddPrompt = `You are a BIDS dataset_description.json generator.
281-
282-
// EXTRACT from the following user-provided content:
283-
// ${userText}
284-
285-
// Generate a valid dataset_description.json with these fields:
286-
// - Name: Extract dataset name from content
287-
// - BIDSVersion: Use "1.10.0"
288-
// - DatasetType: Use "raw"
289-
// - License: Extract or use "PD"
290-
// - Authors: Extract author names (must be array)
291-
292-
// OUTPUT: Valid JSON only (no markdown, no explanations)`;
293215

294216
let ddResponse;
295217
if (currentProvider.isAnthropic) {
@@ -310,7 +232,7 @@ const LLMPanel: React.FC<LLMPanelProps> = ({
310232
const ollamaBaseUrl = ollamaUrl || "http://localhost:11434";
311233
ddResponse = await fetch(`${ollamaBaseUrl}/v1/chat/completions`, {
312234
method: "POST",
313-
signal: controller.signal, // ✅ Add to all fetch calls
235+
signal: controller.signal,
314236
headers: { "Content-Type": "application/json" },
315237
body: JSON.stringify({
316238
model,
@@ -320,7 +242,7 @@ const LLMPanel: React.FC<LLMPanelProps> = ({
320242
} else {
321243
ddResponse = await fetch(currentProvider.baseUrl, {
322244
method: "POST",
323-
signal: controller.signal, // ✅ Add to all fetch calls
245+
signal: controller.signal,
324246
headers: {
325247
"Content-Type": "application/json",
326248
Authorization: `Bearer ${apiKey}`,
@@ -350,24 +272,12 @@ const LLMPanel: React.FC<LLMPanelProps> = ({
350272
// ==========================================
351273
setStatus("2/3 Generating README.md...");
352274
const readmePrompt = getReadmePrompt(userText);
353-
// const readmePrompt = `Generate a BIDS README.md file.
354-
355-
// USER CONTEXT:
356-
// ${userText}
357-
358-
// Create a comprehensive README with sections:
359-
// - Overview (use user context)
360-
// - Dataset Description
361-
// - File Organization
362-
// - Usage Notes
363-
364-
// OUTPUT: Direct Markdown text (no JSON wrapper, no code fences)`;
365275

366276
let readmeResponse;
367277
if (currentProvider.isAnthropic) {
368278
readmeResponse = await fetch(currentProvider.baseUrl, {
369279
method: "POST",
370-
signal: controller.signal, // ✅ Add to all fetch calls
280+
signal: controller.signal,
371281
headers: {
372282
"Content-Type": "application/json",
373283
"x-api-key": apiKey,
@@ -383,7 +293,7 @@ const LLMPanel: React.FC<LLMPanelProps> = ({
383293
const ollamaBaseUrl = ollamaUrl || "http://localhost:11434";
384294
readmeResponse = await fetch(`${ollamaBaseUrl}/v1/chat/completions`, {
385295
method: "POST",
386-
signal: controller.signal, // ✅ Add to all fetch calls
296+
signal: controller.signal,
387297
headers: { "Content-Type": "application/json" },
388298
body: JSON.stringify({
389299
model,
@@ -393,7 +303,7 @@ const LLMPanel: React.FC<LLMPanelProps> = ({
393303
} else {
394304
readmeResponse = await fetch(currentProvider.baseUrl, {
395305
method: "POST",
396-
signal: controller.signal, // ✅ Add to all fetch calls
306+
signal: controller.signal,
397307
headers: {
398308
"Content-Type": "application/json",
399309
Authorization: `Bearer ${apiKey}`,
@@ -416,15 +326,6 @@ const LLMPanel: React.FC<LLMPanelProps> = ({
416326
// ==========================================
417327
setStatus("3/3 Generating participants.tsv...");
418328
const partsPrompt = getParticipantsPrompt(userText);
419-
// const partsPrompt = `Generate a BIDS participants.tsv file.
420-
421-
// USER CONTEXT:
422-
// ${userText}
423-
424-
// Extract participant information (IDs, demographics).
425-
// If no info available, create basic: participant_id\\nsub-01
426-
427-
// OUTPUT: Direct TSV text (no JSON, no code fences)`;
428329

429330
let partsResponse;
430331
if (currentProvider.isAnthropic) {
@@ -613,11 +514,11 @@ const LLMPanel: React.FC<LLMPanelProps> = ({
613514
const filePatterns = analyzeFilePatterns(files);
614515
const userContext = getUserContext(files);
615516
const annotations = getFileAnnotations(files);
616-
console.log("=== PROMPT BEING SENT TO LLM ===");
617-
console.log(fileSummary);
618-
console.log(filePatterns);
619-
console.log(userContext);
620-
console.log("=================================");
517+
// console.log("=== PROMPT BEING SENT TO LLM ===");
518+
// console.log(fileSummary);
519+
// console.log(filePatterns);
520+
// console.log(userContext);
521+
// console.log("=================================");
621522

622523
// UPDATED: Improved prompt that uses trio files
623524
const prompt = getConversionScriptPrompt(
@@ -753,7 +654,6 @@ const LLMPanel: React.FC<LLMPanelProps> = ({
753654
return (
754655
<Paper
755656
sx={{
756-
// position: "fixed",
757657
position: "absolute",
758658
bottom: 0,
759659
left: 0,
@@ -786,7 +686,6 @@ const LLMPanel: React.FC<LLMPanelProps> = ({
786686
width: 40,
787687
height: 3,
788688
backgroundColor: Colors.secondaryPurple,
789-
// borderRadius: 2,
790689
}}
791690
/>
792691
</Box>
@@ -869,7 +768,7 @@ const LLMPanel: React.FC<LLMPanelProps> = ({
869768
sx={{ mb: 2 }}
870769
/>
871770
)}
872-
{/* ADD THIS: Base Directory Path field (shows for ALL providers) */}
771+
{/* Base Directory Path field (shows for ALL providers) */}
873772
<TextField
874773
fullWidth
875774
required
@@ -916,11 +815,10 @@ const LLMPanel: React.FC<LLMPanelProps> = ({
916815
size="small"
917816
variant={evidenceBundle ? "contained" : "outlined"}
918817
onClick={handleGenerateEvidence}
919-
disabled={!baseDirectoryPath.trim() || generatingEvidence} // ✅ Add || generatingEvidence
818+
disabled={!baseDirectoryPath.trim() || generatingEvidence}
920819
startIcon={
921820
generatingEvidence ? <CircularProgress size={16} /> : null
922-
} // ✅ Add this
923-
// disabled={!baseDirectoryPath.trim()}
821+
}
924822
sx={{
925823
justifyContent: "flex-start",
926824
textTransform: "none",
@@ -936,7 +834,6 @@ const LLMPanel: React.FC<LLMPanelProps> = ({
936834
},
937835
}}
938836
>
939-
{/* {evidenceBundle ? "✓" : "1."} Generate Evidence Bundle */}
940837
{generatingEvidence
941838
? "Generating..."
942839
: evidenceBundle
@@ -949,11 +846,10 @@ const LLMPanel: React.FC<LLMPanelProps> = ({
949846
size="small"
950847
variant={trioGenerated ? "contained" : "outlined"}
951848
onClick={handleGenerateTrio}
952-
// disabled={!evidenceBundle}
953-
disabled={!evidenceBundle || generatingTrio} // ✅ Add || generatingTrio
849+
disabled={!evidenceBundle || generatingTrio}
954850
startIcon={
955851
generatingTrio ? <CircularProgress size={16} /> : null
956-
} // ✅ Add this
852+
}
957853
sx={{
958854
justifyContent: "flex-start",
959855
textTransform: "none",
@@ -969,7 +865,6 @@ const LLMPanel: React.FC<LLMPanelProps> = ({
969865
},
970866
}}
971867
>
972-
{/* {trioGenerated ? "✓" : "2."} Generate BIDS Trio */}
973868
{generatingTrio
974869
? "Generating..."
975870
: trioGenerated
@@ -996,8 +891,7 @@ const LLMPanel: React.FC<LLMPanelProps> = ({
996891
loading ? <CircularProgress size={20} /> : <AutoAwesome />
997892
}
998893
onClick={handleGenerate}
999-
// disabled={loading}
1000-
disabled={loading || !baseDirectoryPath.trim() || !trioGenerated} // Add
894+
disabled={loading || !baseDirectoryPath.trim() || !trioGenerated}
1001895
sx={{
1002896
background: `linear-gradient(135deg, ${Colors.purple} 0%, ${Colors.secondaryPurple} 100%)`,
1003897
"&:hover": {

0 commit comments

Comments
 (0)