Skip to content

Commit

Permalink
Ensure the last section is displayed during streaming
Browse files Browse the repository at this point in the history
  • Loading branch information
stefl committed Nov 8, 2024
1 parent ad14dc0 commit d5fb335
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ function findStreamingSections(message: Message | undefined): {
content: undefined,
};
}
log.info("Parsing message content", message.content);
const { content } = message;
const regex = /"path":"\/([^/"]*)/g;
const pathMatches =
Expand Down Expand Up @@ -94,5 +93,10 @@ export const useAilaStreamingStatus = ({
log.info("ailaStreamingStatus set:", status);
}, [status]);

return { status, streamingSection, streamingSections };
return {
status,
streamingSection:
status === "StreamingLessonPlan" ? streamingSection : undefined,
streamingSections,
};
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useEffect, useMemo, useRef } from "react";

import {
import type {
LessonPlanKeys,
LessonPlanSectionWhileStreaming,
} from "@oakai/aila/src/protocol/schema";
Expand All @@ -12,7 +12,7 @@ import { Icon } from "@/components/Icon";
import LoadingWheel from "@/components/LoadingWheel";

import Skeleton from "../../common/Skeleton";
import { AilaStreamingStatus } from "../Chat/hooks/useAilaStreamingStatus";
import type { AilaStreamingStatus } from "../Chat/hooks/useAilaStreamingStatus";
import ChatSection from "./chat-section";

const DropDownSection = ({
Expand Down Expand Up @@ -42,8 +42,7 @@ const DropDownSection = ({
const sectionTitleMemo = useMemo(() => sectionTitle(section), [section]);

const isStreaming =
ailaStreamingStatus === "StreamingLessonPlan" &&
streamingSection === section;
ailaStreamingStatus !== "Idle" && streamingSection === section;

const isLoaded = !isStreaming && value !== undefined;

Expand Down
2 changes: 1 addition & 1 deletion apps/nextjs/src/hooks/useLessonPlanScrollManagement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export const useLessonPlanScrollManagement = (

// Trigger processing the scroll queue
useEffect(() => {
if (streamingStatus === "StreamingLessonPlan") {
if (streamingStatus !== "Idle") {
const intervalId = setInterval(() => {
processScrollQueue();
}, 200);
Expand Down
11 changes: 5 additions & 6 deletions apps/nextjs/src/lib/lessonPlan/LessonPlanManager.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import {
PatchDocument,
applyLessonPlanPatch,
} from "@oakai/aila/src/protocol/jsonPatchProtocol";
import {
import type { PatchDocument } from "@oakai/aila/src/protocol/jsonPatchProtocol";
import { applyLessonPlanPatch } from "@oakai/aila/src/protocol/jsonPatchProtocol";
import type {
LessonPlanKeys,
LooseLessonPlan,
} from "@oakai/aila/src/protocol/schema";
import { aiLogger } from "@oakai/logger";
import { Message } from "ai";
import type { Message } from "ai";
import { createHash } from "crypto";
import { EventEmitter } from "events";
import { deepClone } from "fast-json-patch";
Expand Down Expand Up @@ -99,6 +97,7 @@ export class LessonPlanManager {
}

public onMessageUpdated(message: Message): void {
log.info("LessonPlanManager: onMessageUpdated");
if (message.role === "assistant") {
this.applyPatches(message);
}
Expand Down

0 comments on commit d5fb335

Please sign in to comment.