Skip to content

Commit

Permalink
get thought content in copied value
Browse files Browse the repository at this point in the history
  • Loading branch information
hannahblair committed Jan 8, 2025
1 parent 93972a8 commit 7de8b1d
Showing 1 changed file with 31 additions and 2 deletions.
33 changes: 31 additions & 2 deletions js/chatbot/shared/ButtonPanel.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import LikeDislike from "./LikeDislike.svelte";
import Copy from "./Copy.svelte";
import type { FileData } from "@gradio/client";
import type { NormalisedMessage, TextMessage } from "../types";
import type { NormalisedMessage, TextMessage, ThoughtNode } from "../types";
import { Retry, Undo, Edit, Check, Clear } from "@gradio/icons";
import { IconButtonWrapper, IconButton } from "@gradio/atoms";
export let likeable: boolean;
Expand Down Expand Up @@ -32,9 +32,38 @@
);
}
function get_thought_content(msg: NormalisedMessage, depth = 0): string {
let content = "";
const indent = " ".repeat(depth);
if (msg.metadata?.title) {
content += `${indent}${depth > 0 ? "- " : ""}${msg.metadata.title}\n`;
}
if (typeof msg.content === "string") {
content += `${indent} ${msg.content}\n`;
}
const thought = msg as ThoughtNode;
if (thought.children?.length > 0) {
content += thought.children
.map((child) => get_thought_content(child, depth + 1))
.join("");
}
return content;
}
function all_text(message: TextMessage[] | TextMessage): string {
if (Array.isArray(message)) {
return message.map((m) => m.content).join("\n");
return message
.map((m) => {
if (m.metadata?.title) {
return get_thought_content(m);
}
return m.content;
})
.join("\n");
}
if (message.metadata?.title) {
return get_thought_content(message);
}
return message.content;
}
Expand Down

0 comments on commit 7de8b1d

Please # to comment.