Skip to content

Commit

Permalink
feat: add ability to process multiple code and or text file types and…
Browse files Browse the repository at this point in the history
… send to model
  • Loading branch information
anirudTT committed Feb 24, 2025
1 parent 4a5d99b commit 42a1771
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
42 changes: 42 additions & 0 deletions app/frontend/src/components/chatui/processUploadedFiles.tsx
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
}
*/
4 changes: 3 additions & 1 deletion app/frontend/src/components/chatui/runInference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { getRagContext } from "./getRagContext";
import { generatePrompt } from "./templateRenderer";
import { v4 as uuidv4 } from "uuid";
import type React from "react";
import { processUploadedFiles } from "./processUploadedFiles";

export const runInference = async (
request: InferenceRequest,
Expand All @@ -34,7 +35,8 @@ export const runInference = async (

let messages;
if (request.files && request.files.length > 0) {
const file = request.files[0];
const file = processUploadedFiles(request.files);
console.log("Processed file:", file);

if (file.type === "text" && file.text) {
// Handle text file by treating its content as RAG context
Expand Down

0 comments on commit 42a1771

Please sign in to comment.