Skip to content

Commit 8275872

Browse files
authored
fix: prevent extra prompts from being logged (#14)
We create a new stream when a tool call occurs, but the prompt remains the same from the previous request; let's only record it once Signed-off-by: Danny Kopping <[email protected]>
1 parent 9c0fd0c commit 8275872

5 files changed

+10
-0
lines changed

bridge_integration_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,9 @@ func TestAnthropicInjectedTools(t *testing.T) {
651651
// Ensure tokens used during injected tool invocation are accounted for.
652652
assert.EqualValues(t, 15308, calculateTotalInputTokens(recorderClient.tokenUsages))
653653
assert.EqualValues(t, 204, calculateTotalOutputTokens(recorderClient.tokenUsages))
654+
655+
// Ensure we received exactly one prompt.
656+
require.Len(t, recorderClient.userPrompts, 1)
654657
})
655658
}
656659
}
@@ -744,6 +747,9 @@ func TestOpenAIInjectedTools(t *testing.T) {
744747
// Ensure tokens used during injected tool invocation are accounted for.
745748
require.EqualValues(t, 5047, calculateTotalInputTokens(recorderClient.tokenUsages))
746749
require.EqualValues(t, 105, calculateTotalOutputTokens(recorderClient.tokenUsages))
750+
751+
// Ensure we received exactly one prompt.
752+
require.Len(t, recorderClient.userPrompts, 1)
747753
})
748754
}
749755
}

intercept_anthropic_messages_blocking.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ func (i *AnthropicMessagesBlockingInterception) ProcessRequest(w http.ResponseWr
9191
MsgID: resp.ID,
9292
Prompt: *prompt,
9393
})
94+
prompt = nil
9495
}
9596

9697
_ = i.recorder.RecordTokenUsage(ctx, &TokenUsageRecord{

intercept_anthropic_messages_streaming.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,7 @@ newStream:
405405
MsgID: message.ID,
406406
Prompt: *prompt,
407407
})
408+
prompt = nil
408409
}
409410

410411
// Check if the stream encountered any errors.

intercept_openai_chat_blocking.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ func (i *OpenAIBlockingChatInterception) ProcessRequest(w http.ResponseWriter, r
7373
MsgID: completion.ID,
7474
Prompt: *prompt,
7575
})
76+
prompt = nil
7677
}
7778

7879
lastUsage := completion.Usage

intercept_openai_chat_streaming.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ func (i *OpenAIStreamingChatInterception) ProcessRequest(w http.ResponseWriter,
157157
MsgID: processor.getMsgID(),
158158
Prompt: *prompt,
159159
})
160+
prompt = nil
160161
}
161162

162163
if lastUsage := processor.getLastUsage(); lastUsage.CompletionTokens > 0 {

0 commit comments

Comments
 (0)