-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
121 additions
and
320 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,12 @@ | ||
import type { Message as AiMessage } from "ai"; | ||
import { findLast } from "remeda"; | ||
|
||
import type { Message as AilaMessage } from "../../core/chat/types"; | ||
|
||
interface AssistantMessage extends AilaMessage { | ||
role: "assistant"; | ||
interface HasRole { | ||
role: string; | ||
id: string; | ||
} | ||
|
||
/** | ||
* This function takes an array of messages, and returns the last message from the assistant. | ||
*/ | ||
export function getLastAssistantMessage( | ||
messages: AiMessage[], | ||
): AssistantMessage | undefined { | ||
const lastAssistantMessage = findLast( | ||
messages, | ||
(m): m is AssistantMessage => m.role === "assistant", | ||
) as AssistantMessage | undefined; | ||
|
||
return lastAssistantMessage; | ||
export function getLastAssistantMessage<T extends HasRole>( | ||
messages: T[], | ||
): (T & { role: "assistant" }) | undefined { | ||
return messages.filter((m) => m.role === "assistant").pop() as | ||
| (T & { role: "assistant" }) | ||
| undefined; | ||
} |
Oops, something went wrong.