Skip to content

Commit

Permalink
Address review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
planger committed Oct 1, 2024
1 parent c5d9334 commit 8dd098d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
8 changes: 3 additions & 5 deletions packages/ai-chat/src/common/chat-agents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ import {
MarkdownChatResponseContentImpl,
ToolCallChatResponseContentImpl
} from './chat-model';
import { findEarliestMatch, parseContents } from './parse-contents';
import { findFirstMatch, parseContents } from './parse-contents';
import { DefaultResponseContentFactory, ResponseContentMatcher, ResponseContentMatcherProvider } from './response-content-matcher';

/**
Expand Down Expand Up @@ -356,11 +356,9 @@ export abstract class AbstractStreamParsingChatAgent extends AbstractChatAgent {
return;
}

const result: ChatResponseContent[] = findEarliestMatch(this.contentMatchers, text) ? this.parseContents(text) : [];
const result: ChatResponseContent[] = findFirstMatch(this.contentMatchers, text) ? this.parseContents(text) : [];
if (result.length > 0) {
result.forEach(r => {
request.response.response.addContent(r);
});
request.response.response.addContents(result);
} else {
request.response.response.addContent(lastContent);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/ai-chat/src/common/parse-contents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export function parseContents(
let currentIndex = 0;
while (currentIndex < text.length) {
const remainingText = text.substring(currentIndex);
const match = findEarliestMatch(contentMatchers, remainingText);
const match = findFirstMatch(contentMatchers, remainingText);
if (!match) {
// Add the remaining text as default content
if (remainingText.length > 0) {
Expand All @@ -58,7 +58,7 @@ export function parseContents(
return result;
}

export function findEarliestMatch(contentMatchers: ResponseContentMatcher[], text: string): Match | undefined {
export function findFirstMatch(contentMatchers: ResponseContentMatcher[], text: string): Match | undefined {
let earliestMatch: { matcher: ResponseContentMatcher, index: number, content: string } | undefined;
for (const matcher of contentMatchers) {
const startMatch = matcher.start.exec(text);
Expand Down

0 comments on commit 8dd098d

Please sign in to comment.