Skip to content

Commit

Permalink
move is_all_text
Browse files Browse the repository at this point in the history
  • Loading branch information
hannahblair committed Jan 8, 2025
1 parent 02eefbc commit fc993c4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
13 changes: 1 addition & 12 deletions js/chatbot/shared/ButtonPanel.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import type { NormalisedMessage, TextMessage, ThoughtNode } from "../types";
import { Retry, Undo, Edit, Check, Clear } from "@gradio/icons";
import { IconButtonWrapper, IconButton } from "@gradio/atoms";
import { all_text } from "./utils";
import { all_text, is_all_text } from "./utils";
export let likeable: boolean;
export let feedback_options: string[];
Expand All @@ -24,18 +24,7 @@
export let layout: "bubble" | "panel";
export let dispatch: any;
function is_all_text(
message: NormalisedMessage[] | NormalisedMessage
): message is TextMessage[] | TextMessage {
return (
(Array.isArray(message) &&
message.every((m) => typeof m.content === "string")) ||
(!Array.isArray(message) && typeof message.content === "string")
);
}
$: message_text = is_all_text(message) ? all_text(message) : "";
$: show_copy = show_copy_button && message && is_all_text(message);
</script>

Expand Down
10 changes: 10 additions & 0 deletions js/chatbot/shared/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,3 +319,13 @@ export function all_text(message: TextMessage[] | TextMessage): string {
}
return message.content;
}

export function is_all_text(
message: NormalisedMessage[] | NormalisedMessage
): message is TextMessage[] | TextMessage {
return (
(Array.isArray(message) &&
message.every((m) => typeof m.content === "string")) ||
(!Array.isArray(message) && typeof message.content === "string")
);
}

0 comments on commit fc993c4

Please # to comment.