Skip to content

Commit

Permalink
Merge pull request #63 from microsoft/ntoebookAttachments
Browse files Browse the repository at this point in the history
Fix embedding images in exported notebook
  • Loading branch information
DonJayamanne authored Oct 23, 2024
2 parents fa86274 + efe4626 commit 2074c0e
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 5 deletions.
3 changes: 3 additions & 0 deletions build/clean.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ if (fs.existsSync(path.join(__dirname, '..', 'out'))) {
if (fs.existsSync(path.join(__dirname, '..', 'pyodide'))) {
fs.rmSync(path.join(__dirname, '..', 'pyodide'), { recursive: true });
}
if (fs.existsSync(path.join(__dirname, '..', 'resources', 'pyodide.zip'))) {
fs.rmSync(path.join(__dirname, '..', 'resources', 'pyodide.zip'), { recursive: true });
}
if (fs.existsSync(path.join(__dirname, '..', 'temp'))) {
fs.rmSync(path.join(__dirname, '..', 'temp'), { recursive: true });
}
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 22 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"author": "Microsoft Corporation",
"homepage": "https://github.com/microsoft/Advanced-Data-Analysis-for-Copilot",
"icon": "images/icon.png",
"version": "0.1.7",
"version": "0.1.8",
"engines": {
"vscode": "^1.95.0"
},
Expand Down Expand Up @@ -87,6 +87,27 @@
"description": "I can help you with data analytics",
"sampleRequest": "Help me analyze the csv file",
"isSticky": true,
"disambiguation": [
{
"category": "analysis",
"description": "Performs analysis on some data provided by user either as a file or content",
"examples": [
"Analyze the contents of sample.csv",
"What is the correlation between house price and income in sample.csv",
"What is the median house price in sample.csv"
]
},
{
"category": "visualize",
"description": "Display visualizations based on some analysis or data provided by user either as a file or content",
"examples": [
"Visualize the contents of sample.csv",
"Generate a plot of average house prices by state",
"Display the correlation between house price and income in sample.csv",
"Display a chart with the median house price in sample.csv"
]
}
],
"commands": [
{
"description": "Export the result of the analysis along with the Python code into multiple formats",
Expand Down
5 changes: 3 additions & 2 deletions src/exportCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import * as fs from 'fs';
import { EOL } from 'os';
import { unescape } from 'querystring';
import { promisify } from 'util';
import { CancellationToken, ChatContext, ChatRequest, ChatResponseMarkdownPart, ChatResponseStream, ChatResponseTurn, ExtensionContext, l10n, NotebookCellData, NotebookCellKind, NotebookCellOutput, NotebookData, ThemeIcon, window, workspace } from "vscode";
import { CancellationToken, ChatContext, ChatRequest, ChatResponseMarkdownPart, ChatResponseStream, ChatResponseTurn, ExtensionContext, l10n, NotebookCellData, NotebookCellKind, NotebookCellOutput, NotebookData, ThemeIcon, Uri, window, workspace } from "vscode";
import { getToolResultValue, isErrorMessageResponse, TsxToolUserMetadata } from "./base";
import { logger } from "./logger";
import { uint8ArrayToBase64 } from "./platform/common/string";
Expand Down Expand Up @@ -264,7 +264,8 @@ export async function createAttachments(markdown: string): Promise<{ markdown: s
const attachments: Record<string, { 'image/png': string }> = {};
await Promise.all(images.map(async ({ name, link }) => {
try {
const bytes = await promisify(fs.readFile)(unescape(link));
const file = link.startsWith('file://') ? Uri.parse(link).fsPath : unescape(link);
const bytes = await promisify(fs.readFile)(file);
const base64 = uint8ArrayToBase64(bytes);
name = `${sanitize(name).replace(/ /g, '')}.png`;
attachments[name] = { 'image/png': base64 };
Expand Down

0 comments on commit 2074c0e

Please sign in to comment.