Skip to content

Commit

Permalink
Changes to indicate final response on DONE or http request completion
Browse files Browse the repository at this point in the history
  • Loading branch information
nnshah1 committed Jul 11, 2024
2 parents ade066d + 0c7f5a1 commit 1026361
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/c++/perf_analyzer/client_backend/openai/openai_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ namespace openai {
void
ChatCompletionRequest::SendResponse(bool is_final, bool is_null)
{
// if final response has already been sent
// due to detecting the [DONE]
// ignore final response due to request completion
if (final_response_sent_) {
return;
}

final_response_sent_ = is_final;
response_callback_(new ChatCompletionResult(
http_code_, std::move(response_buffer_), is_final, is_null, request_id_));
}
Expand Down Expand Up @@ -172,9 +180,11 @@ ChatCompletionClient::AsyncInfer(
request->timer_.CaptureTimestamp(
triton::client::RequestTimers::Kind::REQUEST_END);
UpdateInferStat(request->timer_);
if (!request->is_stream_) {
request->SendResponse(true /* is_final */, false /* is_null */);
}

// Send Response checks if a final
// response has already been sent
// (in the case of seeing [DONE] in streaming case)
request->SendResponse(true /* is_final */, false /* is_null */);
};
std::unique_ptr<HttpRequest> request(new ChatCompletionRequest(
std::move(completion_callback), std::move(callback), request_id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ class ChatCompletionRequest : public HttpRequest {
// The timers for infer request.
triton::client::RequestTimers timer_;
const std::string request_id_;
bool final_response_sent_{false};
};

class ChatCompletionClient : public HttpClient {
Expand Down

0 comments on commit 1026361

Please sign in to comment.