From 008c4d269671812eda7590b44e00e963388c3782 Mon Sep 17 00:00:00 2001 From: Ahmed Khaleel Date: Fri, 14 Feb 2025 19:01:41 -0500 Subject: [PATCH] debugging chunk speed --- backend/app/routers/generate.py | 6 +----- src/hooks/useDiagram.ts | 7 +------ 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/backend/app/routers/generate.py b/backend/app/routers/generate.py index 109bdce..646bca7 100644 --- a/backend/app/routers/generate.py +++ b/backend/app/routers/generate.py @@ -277,7 +277,6 @@ def replace_path(match): @router.post("/stream") async def generate_stream(request: Request, body: ApiRequest): try: - print("generate_stream called!") # Initial validation checks if len(body.instructions) > 1000: return {"error": "Instructions exceed maximum length of 1000 characters"} @@ -291,12 +290,9 @@ async def generate_stream(request: Request, body: ApiRequest): ]: return {"error": "Example repos cannot be regenerated"} - print("initial validation checks passed") - async def event_generator(): try: # Get cached github data - print("backend should be processing if you see this") github_data = get_cached_github_data( body.username, body.repo, body.github_pat ) @@ -350,6 +346,7 @@ async def event_generator(): reasoning_effort="medium", ): explanation += chunk + print("sending explanation chunk", chunk) yield f"data: {json.dumps({'status': 'explanation_chunk', 'chunk': chunk})}\n\n" if "BAD_INSTRUCTIONS" in explanation: @@ -419,7 +416,6 @@ async def event_generator(): except Exception as e: yield f"data: {json.dumps({'error': str(e)})}\n\n" - print("returning streaming response") return StreamingResponse(event_generator(), media_type="text/event-stream") except Exception as e: return {"error": str(e)} diff --git a/src/hooks/useDiagram.ts b/src/hooks/useDiagram.ts index 1f1e9ad..c2e0a1d 100644 --- a/src/hooks/useDiagram.ts +++ b/src/hooks/useDiagram.ts @@ -51,15 +51,12 @@ export function useDiagram(username: string, repo: string) { const generateDiagram = useCallback( async (instructions = "", apiKey?: string, githubPat?: string) => { - console.log("generateDiagram called"); setState({ status: "started", message: "Starting generation process...", }); - console.log("started state set"); try { - console.log("fetching stream api"); const baseUrl = process.env.NEXT_PUBLIC_API_DEV_URL ?? "https://api.gitdiagram.com"; // keeping this here since its easier for streaming const response = await fetch(`${baseUrl}/generate/stream`, { @@ -75,13 +72,10 @@ export function useDiagram(username: string, repo: string) { github_pat: githubPat, }), }); - console.log("response", response); if (!response.ok) { throw new Error("Failed to start streaming"); } - console.log("accessing reader"); const reader = response.body?.getReader(); - console.log("accessed reader"); if (!reader) { throw new Error("No reader available"); } @@ -131,6 +125,7 @@ export function useDiagram(username: string, repo: string) { })); break; case "explanation_chunk": + console.log("received explanation chunk:", data.chunk); if (data.chunk) { explanation += data.chunk; setState((prev) => ({ ...prev, explanation }));