-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement new way of running prompts
- Loading branch information
1 parent
0418979
commit 52413e5
Showing
9 changed files
with
169 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,25 @@ | ||
import { spawnSync } from 'child_process'; | ||
import * as vscode from 'vscode'; | ||
import { showPromptPicker } from '../utils/promptPicker'; | ||
import { ctx } from '../extension'; | ||
|
||
|
||
|
||
export const savePrompt = async (prompt: string) => { | ||
if (!prompt) { | ||
prompt = (await showPromptPicker(true))?.id || ""; | ||
prompt = (await showPromptPicker())?.id || ""; | ||
} | ||
if (prompt === "") { | ||
return vscode.window.showErrorMessage("No prompt selected"); | ||
} | ||
|
||
const promptImage = vscode.workspace.getConfiguration('docker.labs-ai-tools-vscode').get('prompt-image') as string; | ||
const args = [ | ||
"run", | ||
"--rm", | ||
"-v", | ||
"/var/run/docker.sock:/var/run/docker.sock", | ||
"--mount", | ||
"type=volume,source=docker-prompts,target=/prompts", | ||
promptImage, | ||
"register", | ||
prompt | ||
]; | ||
const result = spawnSync('docker', args); | ||
if (result.error || result.status !== 0) { | ||
vscode.window.showErrorMessage(`Error saving prompt ${prompt}: ${result.error || result.stderr.toString()}`); | ||
} | ||
else { | ||
ctx.globalState.update('savedPrompts', [...ctx.globalState.get('savedPrompts', []), prompt]); | ||
vscode.window.showInformationMessage(`Saved ${prompt}`); | ||
vscode.commands.executeCommand("docker.labs-ai-tools-vscode.generate"); | ||
vscode.commands.executeCommand("docker.labs-ai-tools-vscode.run-prompt"); | ||
} | ||
}; | ||
|
||
export const deletePrompt = (prompt: string) => { | ||
const promptImage = vscode.workspace.getConfiguration('docker.labs-ai-tools-vscode').get('prompt-image') as string; | ||
const args = [ | ||
"run", | ||
"--rm", | ||
"-v", | ||
"/var/run/docker.sock:/var/run/docker.sock", | ||
"--mount", | ||
"type=volume,source=docker-prompts,target=/prompts", | ||
promptImage, | ||
"unregister", | ||
prompt | ||
]; | ||
const result = spawnSync('docker', args); | ||
if (result.error || result.status !== 0) { | ||
vscode.window.showErrorMessage(`Error deleting prompt ${prompt}: ${result.error || result.stderr.toString()}`); | ||
} | ||
else { | ||
vscode.window.showInformationMessage(`Deleted ${prompt}`); | ||
vscode.commands.executeCommand("docker.labs-ai-tools-vscode.generate"); | ||
} | ||
}; | ||
ctx.globalState.update('savedPrompts', ctx.globalState.get('savedPrompts', []).filter(p => p !== prompt)); | ||
vscode.window.showInformationMessage(`Deleted ${prompt}`); | ||
vscode.commands.executeCommand("docker.labs-ai-tools-vscode.run-prompt"); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.