-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add ability to process multiple code and or text file types and…
… send to model
- Loading branch information
Showing
2 changed files
with
45 additions
and
1 deletion.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
app/frontend/src/components/chatui/processUploadedFiles.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// SPDX-FileCopyrightText: © 2025 Tenstorrent AI ULC | ||
|
||
import type { FileData } from "./types"; | ||
|
||
export function processUploadedFiles(files: FileData[]): FileData { | ||
if (!files || files.length === 0) { | ||
return {} as FileData; | ||
} | ||
|
||
if (files.length === 1 || files[0].type !== "text") { | ||
return files[0]; | ||
} | ||
const textFiles = files.filter((file) => file.type === "text" && file.text); | ||
|
||
if (textFiles.length === 0) { | ||
return files[0]; | ||
} | ||
|
||
const combinedText = textFiles.map((file) => file.text).join("\n\n"); | ||
console.log(`Processed ${textFiles.length} text files into single content`); | ||
|
||
return { | ||
type: "text", | ||
text: combinedText, | ||
name: `combined_${textFiles.length}_files.txt`, | ||
} as FileData; | ||
} | ||
|
||
// Usage example: | ||
/* | ||
const files = request.files | ||
console.log("Uploaded files:", files) | ||
const file = processUploadedFiles(files) | ||
// Now you can use 'file' as before | ||
if (file.type === "text" && file.text) { | ||
// Handle text content | ||
} else if (file.image_url?.url || file) { | ||
// Handle image | ||
} | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters