Skip to content

Commit ae09bec

Browse files
committed
debug
1 parent fd7439f commit ae09bec

2 files changed

Lines changed: 25 additions & 9 deletions

File tree

internal/services/toolkit/client/completion_v2.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"paperdebugger/internal/models"
77
"paperdebugger/internal/services/toolkit/handler"
88
chatv2 "paperdebugger/pkg/gen/api/chat/v2"
9+
"time"
910

1011
"github.com/openai/openai-go/v3"
1112
)
@@ -70,18 +71,26 @@ func (a *AIClientV2) ChatCompletionStreamV2(ctx context.Context, callbackStream
7071
for {
7172
params.Messages = openaiChatHistory
7273
// var openaiOutput OpenAIChatHistory
74+
a.logger.Info("[Stream Debug] Starting new streaming request", "model", modelSlug)
75+
streamStartTime := time.Now()
7376
stream := oaiClient.Chat.Completions.NewStreaming(context.Background(), params)
7477

7578
reasoning_content := ""
7679
answer_content := ""
7780
answer_content_id := ""
7881
has_sent_part_begin := false
82+
firstChunkReceived := false
7983
tool_info := map[int]map[string]string{}
8084
toolCalls := []openai.FinishedChatCompletionToolCall{}
8185
for stream.Next() {
8286
// time.Sleep(5000 * time.Millisecond) // DEBUG POINT: change this to test in a slow mode
8387
chunk := stream.Current()
8488

89+
if !firstChunkReceived {
90+
firstChunkReceived = true
91+
a.logger.Info("[Stream Debug] First chunk received", "elapsed_ms", time.Since(streamStartTime).Milliseconds())
92+
}
93+
8594
if len(chunk.Choices) == 0 {
8695
// Handle usage information
8796
// fmt.Printf("Usage: %+v\n", chunk.Usage)
@@ -99,25 +108,35 @@ func (a *AIClientV2) ChatCompletionStreamV2(ctx context.Context, callbackStream
99108
_, hasReasoning := delta.JSON.ExtraFields["reasoning"]
100109
if !has_sent_part_begin && (delta.Role == "assistant" || delta.Content != "" || hasReasoningContent || hasReasoning) {
101110
has_sent_part_begin = true
111+
a.logger.Info("[Stream Debug] Sending StreamPartBegin", "elapsed_ms", time.Since(streamStartTime).Milliseconds(), "role", delta.Role, "hasReasoningContent", hasReasoningContent, "hasReasoning", hasReasoning)
102112
streamHandler.HandleAssistantPartBegin(chunk.ID)
103113
}
104114

105115
if field, ok := delta.JSON.ExtraFields["reasoning_content"]; ok && field.Raw() != "null" {
106116
var s string
107117
err := json.Unmarshal([]byte(field.Raw()), &s)
108118
if err == nil {
119+
if reasoning_content == "" {
120+
a.logger.Info("[Stream Debug] First reasoning chunk", "elapsed_ms", time.Since(streamStartTime).Milliseconds(), "length", len(s))
121+
}
109122
reasoning_content += s
110123
streamHandler.HandleReasoningDelta(chunk.ID, s)
111124
}
112125
} else if field, ok := delta.JSON.ExtraFields["reasoning"]; ok && field.Raw() != "null" {
113126
var s string
114127
err := json.Unmarshal([]byte(field.Raw()), &s)
115128
if err == nil {
129+
if reasoning_content == "" {
130+
a.logger.Info("[Stream Debug] First reasoning chunk", "elapsed_ms", time.Since(streamStartTime).Milliseconds(), "length", len(s))
131+
}
116132
reasoning_content += s
117133
streamHandler.HandleReasoningDelta(chunk.ID, s)
118134
}
119135
} else {
120136
if delta.Content != "" {
137+
if answer_content == "" {
138+
a.logger.Info("[Stream Debug] First content chunk", "elapsed_ms", time.Since(streamStartTime).Milliseconds(), "length", len(delta.Content))
139+
}
121140
answer_content += delta.Content
122141
answer_content_id = chunk.ID
123142
streamHandler.HandleTextDelta(chunk)

webapp/_webapp/src/index.css

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ body {
249249
}
250250

251251
.pd-chat-item-container-messages {
252-
@apply px-2;
252+
@apply flex flex-col px-2 gap-4;
253253
}
254254

255255
.pd-app-tab-content {
@@ -340,7 +340,6 @@ body {
340340
.chat-message-entry .message-box-user-wrapper {
341341
display: flex;
342342
flex-direction: row;
343-
align-items: center;
344343
justify-content: flex-end;
345344
gap: 4px;
346345
width: 100%;
@@ -353,7 +352,7 @@ body {
353352
word-wrap: break-word;
354353
@apply text-sm text-default-800 px-3 py-2 border border-transparent rounded-xl;
355354
@apply transition-all duration-500 ease-in-out;
356-
@apply bg-gray-200 my-2;
355+
@apply bg-gray-200;
357356
}
358357

359358
.chat-message-entry .message-box-assistant {
@@ -373,11 +372,9 @@ body {
373372
.chat-message-entry .actions {
374373
display: flex;
375374
flex-direction: row;
376-
@apply gap-2 text-gray-400 mt-2 -ml-2 opacity-0 transition-all duration-100;
377-
}
378-
379-
.chat-message-entry .actions.actions-left {
380-
@apply mt-0 ml-0 mr-0;
375+
justify-content: flex-start;
376+
align-items: flex-end;
377+
@apply text-gray-400 opacity-0 transition-all duration-100;
381378
}
382379

383380
.chat-message-entry:hover .actions {
@@ -388,7 +385,7 @@ body {
388385
.chat-message-entry .actions .icon {
389386
cursor: pointer;
390387
font-size: 24px;
391-
@apply hover:text-gray-500 hover:bg-gray-200 rounded-md p-1 transition-all duration-100 ml-2;
388+
@apply hover:text-gray-500 hover:bg-gray-200 rounded-md p-1 transition-all duration-100;
392389
}
393390

394391
.message-box-stale {

0 commit comments

Comments
 (0)