Harden conversation replies and prioritize newest candidates
This commit is contained in:
1 parent
f98c5c732d
commit
b8e4a1bb88
23 files changed
+598
-113
No files matched your search
@@ -1,6 +1,7 @@
|
||||
import type { Logger } from '../../utils/logger.js';
|
||||
import type {
|
||||
ConversationOutcomesRepository,
|
||||
ConversationStateRepository,
|
||||
MessagesRepository,
|
||||
RedditUsersRepository,
|
||||
SentMessageRecord,
|
||||
@@ -21,6 +22,7 @@ import type { ActiveChat, ChatMessage, ScrapedChatMessage, InvitationCooldown }
|
||||
export type { InvitationCooldown } from './types.js';
|
||||
import { fetchWithTimeout } from '../../utils/fetch-with-timeout.js';
|
||||
import type { AccountAuthGate } from '../account-auth-context.js';
|
||||
import { containsMediaRequest } from '../conversation-boundaries.js';
|
||||
|
||||
const ACTIVE_WINDOW_MS = 96 * 60 * 60 * 1000;
|
||||
const ROOM_URL_PREFIX = 'https://chat.reddit.com/room/';
|
||||
@@ -159,6 +161,7 @@ export class ChatService {
|
||||
private redditUsersRepo?: RedditUsersRepository,
|
||||
private accountAuth?: AccountAuthGate,
|
||||
private outcomesRepo?: ConversationOutcomesRepository,
|
||||
private conversationStateRepo?: ConversationStateRepository,
|
||||
) {
|
||||
this.cache = cache ?? new ChatCache(logger);
|
||||
if (this.redditUsersRepo) {
|
||||
@@ -1104,17 +1107,25 @@ export class ChatService {
|
||||
|
||||
if (hasReply && this.successfulMessagesRepo && this.outcomesRepo) {
|
||||
const firstReply = incomingMessages[0];
|
||||
const latestReply = incomingMessages.at(-1);
|
||||
const cachedSelfCount = conversationMessages.filter((message) => message.isSelf).length;
|
||||
const selfCount = cachedSelfCount + (firstSelf ? 0 : 1);
|
||||
const otherCount = incomingMessages.length;
|
||||
const wasMissingOutcome = this.outcomesRepo.get(performanceMessage.id) === undefined;
|
||||
const conversationState = this.conversationStateRepo?.get(chat.roomId);
|
||||
try {
|
||||
recordConversationReply(
|
||||
performanceMessage,
|
||||
firstReply?.text.slice(0, 200) ?? '',
|
||||
latestReply?.text.slice(0, 200) ?? '',
|
||||
{
|
||||
messageCount: selfCount + otherCount,
|
||||
reciprocal: selfCount >= 2 && otherCount >= 2,
|
||||
responses: incomingMessages.map((message) => message.text),
|
||||
learningEligible: conversationState !== undefined && conversationState.automation.status !== 'active',
|
||||
receivedImage: hasReceivedImage,
|
||||
mediaWasRequested: conversationState?.askedForMedia
|
||||
?? conversationMessages.some((message) => message.isSelf && containsMediaRequest(message.text)),
|
||||
authoritativeTranscript: true,
|
||||
},
|
||||
{
|
||||
messages: this.messagesRepo,
|
||||
|
||||
Reference in new issue
Block a user