Skip to content

Commit 405ee06

Browse files
authored
Merge pull request #16 from docker/cm/prompts-method
Handle prompts method
2 parents d1c4e58 + 6e91480 commit 405ee06

File tree

4 files changed

+55
-22
lines changed

4 files changed

+55
-22
lines changed

src/extension/ui/src/App.tsx

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import OpenAIKey from './components/OpenAIKey';
66
import Projects from './components/Projects';
77
import Prompts from './components/Prompts';
88
import RunOutput from './components/RunOutput';
9+
import Runner from './components/Runner'; // Added this import
910

1011
const client = createDockerDesktopClient();
1112

@@ -168,31 +169,22 @@ export function App() {
168169
track('end-prompt');
169170
}
170171

172+
const renderPrompt = async () => {
173+
await client.docker.cli.exec("pull", ["vonwig/prompts"]);
174+
const args = getRunArgs(selectedPrompt!, selectedProject!, "", client.host.platform, true)
175+
const render = await client.docker.cli.exec("run", args);
176+
console.log(render);
177+
}
178+
171179
return (
172180
<div style={{ overflow: 'auto', maxHeight: '100vh' }} ref={scrollRef}>
173181
<Stack direction="column" spacing={1}>
174182
<OpenAIKey openAIKey={openAIKey || ''} setOpenAIKey={setOpenAIKey} />
175183
<Projects projects={projects} selectedProject={selectedProject} setProjects={setProjects} setSelectedProject={setSelectedProject} />
176184
<Prompts prompts={prompts} selectedPrompt={selectedPrompt} promptInput={promptInput} setPrompts={setPrompts} setSelectedPrompt={setSelectedPrompt} setPromptInput={setPromptInput} track={track} />
177-
{selectedProject && selectedPrompt && openAIKey ? (
178-
<Paper sx={{ padding: 1 }}>
179-
<Typography variant="h3">Ready</Typography>
180-
<pre>PROJECT={selectedProject}</pre>
181-
<pre>PROMPT={selectedPrompt}</pre>
182-
<Button sx={{ mt: 1, }} color='success' onClick={startPrompt}>
183-
Run
184-
</Button>
185-
</Paper>
186-
) : (
187-
<Paper sx={{ padding: 1 }}>
188-
<Typography variant='h3'>Missing:</Typography>
189-
{selectedProject?.length ? null : <Typography variant='body1'> - Project</Typography>}
190-
{selectedPrompt?.length ? null : <Typography variant='body1'> - Prompt</Typography>}
191-
{openAIKey?.length ? null : <Typography variant='body1'> - OpenAI Key</Typography>}
192-
</Paper>
193-
)}
185+
<Runner selectedProject={selectedProject} selectedPrompt={selectedPrompt} openAIKey={openAIKey} startPrompt={startPrompt} renderPrompt={renderPrompt} />
194186
<RunOutput runOut={runOut} showDebug={showDebug} setShowDebug={setShowDebug} />
195187
</Stack>
196188
</div>
197189
)
198-
}
190+
}

src/extension/ui/src/args.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export const getRunArgs = (promptRef: string, projectDir: string, username: string, platform: string) => {
1+
export const getRunArgs = (promptRef: string, projectDir: string, username: string, platform: string, render = false) => {
22
const isLocal = promptRef.startsWith('local://');
33
let promptArgs: string[] = ["--prompts", promptRef];
44
let mountArgs: string[] = [];
@@ -18,9 +18,9 @@ export const getRunArgs = (promptRef: string, projectDir: string, username: stri
1818
'--mount', 'type=volume,source=docker-prompts,target=/prompts'
1919
];
2020

21-
const runArgs: string[] = [
21+
const runArgs: string[] = render ? [] : [
2222
'vonwig/prompts:latest',
23-
'run',
23+
...(render ? [] : ['run']),
2424
"--host-dir", projectDir,
2525
"--user", username,
2626
"--platform", platform,
@@ -29,4 +29,4 @@ export const getRunArgs = (promptRef: string, projectDir: string, username: stri
2929
];
3030

3131
return [...baseArgs, ...mountArgs, ...runArgs];
32-
}
32+
}

src/extension/ui/src/components/RunOutput.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ const RunOutput: React.FC<RunOutputProps> = ({ runOut, showDebug, setShowDebug }
3131
if (line.method === 'functions-done') {
3232
return showDebug ? <Typography key={i} variant='body1' sx={{ whiteSpace: 'pre-wrap' }}>{JSON.stringify(line.params, null, 2)}</Typography> : null;
3333
}
34+
if (line.method === 'prompts') {
35+
return showDebug ? <Typography key={i} variant='body1' sx={{ whiteSpace: 'pre-wrap' }}>{JSON.stringify(line.params.messages, null, 2)}</Typography> : null;
36+
}
3437
return <Typography key={i} variant='body1'>{JSON.stringify(line)}</Typography>
3538
})}
3639
</div>
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { Paper, Typography, Button } from '@mui/material';
2+
import { useEffect } from 'react';
3+
4+
type RunnerProps = {
5+
selectedProject: string | null;
6+
selectedPrompt: string | null;
7+
openAIKey: string | null;
8+
startPrompt: () => void;
9+
renderPrompt: () => void;
10+
}
11+
12+
const Runner: React.FC<RunnerProps> = ({ selectedProject, selectedPrompt, openAIKey, startPrompt, renderPrompt }) => {
13+
useEffect(() => {
14+
if (selectedProject && selectedPrompt && openAIKey) {
15+
// renderPrompt();
16+
}
17+
}, [selectedProject, selectedPrompt, openAIKey]);
18+
19+
return selectedProject && selectedPrompt && openAIKey ? (
20+
<Paper sx={{ padding: 1 }}>
21+
<Typography variant="h3">Ready</Typography>
22+
<pre>PROJECT={selectedProject}</pre>
23+
<pre>PROMPT={selectedPrompt}</pre>
24+
<Button sx={{ mt: 1, }} color='success' onClick={startPrompt}>
25+
Run
26+
</Button>
27+
</Paper>
28+
) : (
29+
<Paper sx={{ padding: 1 }}>
30+
<Typography variant='h3'>Missing:</Typography>
31+
{selectedProject?.length ? null : <Typography variant='body1'> - Project</Typography>}
32+
{selectedPrompt?.length ? null : <Typography variant='body1'> - Prompt</Typography>}
33+
{openAIKey?.length ? null : <Typography variant='body1'> - OpenAI Key</Typography>}
34+
</Paper>
35+
)
36+
}
37+
38+
export default Runner;

0 commit comments

Comments
 (0)