Skip to content

Commit

Permalink
conversation metrics simplified
Browse files Browse the repository at this point in the history
  • Loading branch information
petemill committed Oct 30, 2024
1 parent 6c5c036 commit 6677620
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions components/ai_chat/core/browser/ai_chat_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -500,18 +500,8 @@ void AIChatService::OnConversationEntryAdded(
CHECK(conversation_it != conversations_.end());
mojom::ConversationPtr& conversation = conversation_it->second;

auto& history = handler->GetConversationHistory();

if (!conversation->has_content && history.size() > 0) {
if (!conversation->has_content) {
HandleFirstEntry(handler, entry, associated_content_value, conversation);
if (ai_chat_metrics_ != nullptr) {
if (handler->GetConversationHistory().size() == 1) {
ai_chat_metrics_->RecordNewChat();
}
if (entry->character_type == mojom::CharacterType::HUMAN) {
ai_chat_metrics_->RecordNewPrompt();
}
}
} else {
HandleNewEntry(handler, entry, associated_content_value, conversation);
}
Expand Down Expand Up @@ -546,6 +536,12 @@ void AIChatService::HandleFirstEntry(
entry->Clone())
.Then(std::move(on_conversation_added));
}
// Record metrics
if (ai_chat_metrics_ != nullptr) {
if (handler->GetConversationHistory().size() == 1) {
ai_chat_metrics_->RecordNewChat();
}
}
}

void AIChatService::HandleNewEntry(
Expand Down Expand Up @@ -586,6 +582,12 @@ void AIChatService::HandleNewEntry(
.Then(std::move(on_content_updated));
}
}

// Record metrics
if (ai_chat_metrics_ != nullptr &&
entry->character_type == mojom::CharacterType::HUMAN) {
ai_chat_metrics_->RecordNewPrompt();
}
}

void AIChatService::OnConversationEntryRemoved(ConversationHandler* handler,
Expand Down

0 comments on commit 6677620

Please sign in to comment.