Skip to content

Commit 008c4d2

Browse files
debugging chunk speed
1 parent 6736191 commit 008c4d2

File tree

2 files changed

+2
-11
lines changed

2 files changed

+2
-11
lines changed

backend/app/routers/generate.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,6 @@ def replace_path(match):
277277
@router.post("/stream")
278278
async def generate_stream(request: Request, body: ApiRequest):
279279
try:
280-
print("generate_stream called!")
281280
# Initial validation checks
282281
if len(body.instructions) > 1000:
283282
return {"error": "Instructions exceed maximum length of 1000 characters"}
@@ -291,12 +290,9 @@ async def generate_stream(request: Request, body: ApiRequest):
291290
]:
292291
return {"error": "Example repos cannot be regenerated"}
293292

294-
print("initial validation checks passed")
295-
296293
async def event_generator():
297294
try:
298295
# Get cached github data
299-
print("backend should be processing if you see this")
300296
github_data = get_cached_github_data(
301297
body.username, body.repo, body.github_pat
302298
)
@@ -350,6 +346,7 @@ async def event_generator():
350346
reasoning_effort="medium",
351347
):
352348
explanation += chunk
349+
print("sending explanation chunk", chunk)
353350
yield f"data: {json.dumps({'status': 'explanation_chunk', 'chunk': chunk})}\n\n"
354351

355352
if "BAD_INSTRUCTIONS" in explanation:
@@ -419,7 +416,6 @@ async def event_generator():
419416
except Exception as e:
420417
yield f"data: {json.dumps({'error': str(e)})}\n\n"
421418

422-
print("returning streaming response")
423419
return StreamingResponse(event_generator(), media_type="text/event-stream")
424420
except Exception as e:
425421
return {"error": str(e)}

src/hooks/useDiagram.ts

+1-6
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,12 @@ export function useDiagram(username: string, repo: string) {
5151

5252
const generateDiagram = useCallback(
5353
async (instructions = "", apiKey?: string, githubPat?: string) => {
54-
console.log("generateDiagram called");
5554
setState({
5655
status: "started",
5756
message: "Starting generation process...",
5857
});
59-
console.log("started state set");
6058

6159
try {
62-
console.log("fetching stream api");
6360
const baseUrl =
6461
process.env.NEXT_PUBLIC_API_DEV_URL ?? "https://api.gitdiagram.com"; // keeping this here since its easier for streaming
6562
const response = await fetch(`${baseUrl}/generate/stream`, {
@@ -75,13 +72,10 @@ export function useDiagram(username: string, repo: string) {
7572
github_pat: githubPat,
7673
}),
7774
});
78-
console.log("response", response);
7975
if (!response.ok) {
8076
throw new Error("Failed to start streaming");
8177
}
82-
console.log("accessing reader");
8378
const reader = response.body?.getReader();
84-
console.log("accessed reader");
8579
if (!reader) {
8680
throw new Error("No reader available");
8781
}
@@ -131,6 +125,7 @@ export function useDiagram(username: string, repo: string) {
131125
}));
132126
break;
133127
case "explanation_chunk":
128+
console.log("received explanation chunk:", data.chunk);
134129
if (data.chunk) {
135130
explanation += data.chunk;
136131
setState((prev) => ({ ...prev, explanation }));

0 commit comments

Comments
 (0)