Skip to content

Commit

Permalink
120 add token limit (#127)
Browse files Browse the repository at this point in the history
* fix: add content length validation and improve error handling

* fix: add file size limit validation for uploads

* Update src/routes/api/session/[id]/group/[group_number]/conversations/[conv_id]/chat/+server.ts

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* fix: update session ID in createTestStudent script

* fix: simplify error handling in chat server response

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
  • Loading branch information
TakalaWang and Copilot authored Dec 26, 2024
1 parent f2ecfe9 commit 6445ab7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion scripts/createTestStudent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { GroupSchema } from '../src/lib/schema/group';
import { ProfileSchema } from '../src/lib/schema/profile';
import { adminDb } from '../src/lib/server/firebase'; // 假設有一個 Firebase store 模組

const sessionId = 'tWwNvzhumqTFS4YMF6Cu';
const sessionId = 'QMTXcFCAIQu3EeDRv8kD';
const numberOfStudents = 40;
const numberOfGroups = 8;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ export const POST: RequestHandler = async ({ request, params, locals }) => {

const { content, audio } = await getRequestData(request);
console.log('Parsed request data', { contentLength: content.length, hasAudio: !!audio });
if (content.length > 500) {
console.log('Content too long:', content.length);
throw error(400, 'Content too long');
}

await conversation_ref.update({
history: [
Expand Down
3 changes: 3 additions & 0 deletions src/routes/api/template/[id]/resource/+server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ export const POST: RequestHandler = async ({ params, request, locals }) => {
if (type === 'file') {
const fileProcessingStart = Date.now();
const file = content as File;
if (file.size > 10 * 1024 * 1024) {
return json({ error: 'File size limit exceeded' }, { status: 400 });
}
const buffer = await file.arrayBuffer();
const text = await pdf2Text(buffer, env.LLAMA_CLOUD_API_KEY!);
console.log(`PDF text extraction took ${Date.now() - fileProcessingStart}ms`);
Expand Down

0 comments on commit 6445ab7

Please sign in to comment.