Skip to content

Commit 9c41a3d

Browse files
committed
handle sage images
1 parent 51532b4 commit 9c41a3d

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/service/sageExecution.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,14 @@ const executeSage = async function(interaction){
3030

3131
return client.askSage(code)
3232
.then(res => {
33-
embed.description = "Input:\n```py\n" + code + "\n```\nOutput:\n```\n" + (res?.result?.["text/plain"]?.trim() || res?.stdout?.trim() || "No Output") + "\n```";
33+
embed.description = "Input:\n```py\n" + code + "\n```\nOutput:\n```\n" + (
34+
res?.result?.["text/plain"]?.trim() || res?.stdout?.trim() || (res.result?.image ? "Image Below" : "No Output")
35+
) + "\n```";
36+
37+
if (res?.result?.image){ // @ts-ignore
38+
embed.image = { url: res.result.image };
39+
}
40+
3441
return interaction.editReply({ embeds: [embed]});
3542
})
3643
.catch(() => {

src/util/SageCell.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,11 @@ export default class SageCell {
187187
result = msg.content?.data ?? null;
188188
}
189189

190+
if (msgType === "display_data"){
191+
const filename = msg.content?.data?.["text/image-filename"];
192+
result = filename ? { image: `${this.baseUrl}/kernel/${kernelId}/files/${filename}` } : msg.content?.data ?? null;
193+
}
194+
190195
if (msgType === "status" &&
191196
msg.content?.execution_state === "idle"){
192197
finish({ stdout, stderr, result });

0 commit comments

Comments
 (0)