Skip to content

Commit

Permalink
Update prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
Zhiming Zhang committed May 30, 2024
1 parent a0c9d27 commit 7505fdd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
6 changes: 3 additions & 3 deletions src/file_analysis_extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ async function analyzeFileByOpenAI(csvFile: File) {
{
role: 'user',
content:
'Make sure you 100% stick to the following instruction:\
'Make sure you stick to the following instruction:\
1. A file(dataset) is attached along with this instruction. At the beginning, as a code interpreter, write python code to analyze the attached dataset and execute the code in your sandbox to get the domain knowledge of the dataset. DO NOT output the code you write at this step.\
2. Output Python code to read the dataset. For example, use pd.read_csv(). \
3. Followed with Python code which performs data visualization based on the domain knowledge you required in step 1. Three different diagrams are recommended. \
2. Output Python code to read the dataset. For example, use pd.read_csv(). Replace the file path in read_csv() with the actual file name. \
3. Followed with Python code which performs data visualization based on the domain knowledge you required at step 1. Three different diagrams are recommended. \
4. Your output should be TEXT ONLY, which contains 100% Python code ONLY without any descriptive text instruction. DO NOT output any file or image.',
attachments: [
{
Expand Down
10 changes: 3 additions & 7 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,10 @@ export function extractPythonCode(
while ((match = regex.exec(input)) !== null) {
result += match[1] + '\n'; // Add a newline for separation between blocks
}
result = replaceFilePathInPythonCode(result, filePath);
result = replaceContentInReadCsv(result, filePath);
return result.trim(); // Remove the last newline
}

function replaceFilePathInPythonCode(
input: string,
targetFilePath: string
): string {
const regex = /pd\.read_csv\(['"]([^'"]*)['"]\)/g;
return input.replace(regex, `pd.read_csv('${targetFilePath}')`);
function replaceContentInReadCsv(input: string, target: string): string {
return input.replace(/pd\.read_csv\((.*?)\)/, `pd.read_csv('${target}')`);
}

0 comments on commit 7505fdd

Please sign in to comment.