Skip to content

Commit

Permalink
Merge pull request #16 from docker/cm/prompts-method
Browse files Browse the repository at this point in the history
Handle prompts method
  • Loading branch information
ColinMcNeil authored Aug 20, 2024
2 parents d1c4e58 + 6e91480 commit 405ee06
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 22 deletions.
28 changes: 10 additions & 18 deletions src/extension/ui/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import OpenAIKey from './components/OpenAIKey';
import Projects from './components/Projects';
import Prompts from './components/Prompts';
import RunOutput from './components/RunOutput';
import Runner from './components/Runner'; // Added this import

const client = createDockerDesktopClient();

Expand Down Expand Up @@ -168,31 +169,22 @@ export function App() {
track('end-prompt');
}

const renderPrompt = async () => {
await client.docker.cli.exec("pull", ["vonwig/prompts"]);
const args = getRunArgs(selectedPrompt!, selectedProject!, "", client.host.platform, true)
const render = await client.docker.cli.exec("run", args);
console.log(render);
}

return (
<div style={{ overflow: 'auto', maxHeight: '100vh' }} ref={scrollRef}>
<Stack direction="column" spacing={1}>
<OpenAIKey openAIKey={openAIKey || ''} setOpenAIKey={setOpenAIKey} />
<Projects projects={projects} selectedProject={selectedProject} setProjects={setProjects} setSelectedProject={setSelectedProject} />
<Prompts prompts={prompts} selectedPrompt={selectedPrompt} promptInput={promptInput} setPrompts={setPrompts} setSelectedPrompt={setSelectedPrompt} setPromptInput={setPromptInput} track={track} />
{selectedProject && selectedPrompt && openAIKey ? (
<Paper sx={{ padding: 1 }}>
<Typography variant="h3">Ready</Typography>
<pre>PROJECT={selectedProject}</pre>
<pre>PROMPT={selectedPrompt}</pre>
<Button sx={{ mt: 1, }} color='success' onClick={startPrompt}>
Run
</Button>
</Paper>
) : (
<Paper sx={{ padding: 1 }}>
<Typography variant='h3'>Missing:</Typography>
{selectedProject?.length ? null : <Typography variant='body1'> - Project</Typography>}
{selectedPrompt?.length ? null : <Typography variant='body1'> - Prompt</Typography>}
{openAIKey?.length ? null : <Typography variant='body1'> - OpenAI Key</Typography>}
</Paper>
)}
<Runner selectedProject={selectedProject} selectedPrompt={selectedPrompt} openAIKey={openAIKey} startPrompt={startPrompt} renderPrompt={renderPrompt} />
<RunOutput runOut={runOut} showDebug={showDebug} setShowDebug={setShowDebug} />
</Stack>
</div>
)
}
}
8 changes: 4 additions & 4 deletions src/extension/ui/src/args.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const getRunArgs = (promptRef: string, projectDir: string, username: string, platform: string) => {
export const getRunArgs = (promptRef: string, projectDir: string, username: string, platform: string, render = false) => {
const isLocal = promptRef.startsWith('local://');
let promptArgs: string[] = ["--prompts", promptRef];
let mountArgs: string[] = [];
Expand All @@ -18,9 +18,9 @@ export const getRunArgs = (promptRef: string, projectDir: string, username: stri
'--mount', 'type=volume,source=docker-prompts,target=/prompts'
];

const runArgs: string[] = [
const runArgs: string[] = render ? [] : [
'vonwig/prompts:latest',
'run',
...(render ? [] : ['run']),
"--host-dir", projectDir,
"--user", username,
"--platform", platform,
Expand All @@ -29,4 +29,4 @@ export const getRunArgs = (promptRef: string, projectDir: string, username: stri
];

return [...baseArgs, ...mountArgs, ...runArgs];
}
}
3 changes: 3 additions & 0 deletions src/extension/ui/src/components/RunOutput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ const RunOutput: React.FC<RunOutputProps> = ({ runOut, showDebug, setShowDebug }
if (line.method === 'functions-done') {
return showDebug ? <Typography key={i} variant='body1' sx={{ whiteSpace: 'pre-wrap' }}>{JSON.stringify(line.params, null, 2)}</Typography> : null;
}
if (line.method === 'prompts') {
return showDebug ? <Typography key={i} variant='body1' sx={{ whiteSpace: 'pre-wrap' }}>{JSON.stringify(line.params.messages, null, 2)}</Typography> : null;
}
return <Typography key={i} variant='body1'>{JSON.stringify(line)}</Typography>
})}
</div>
Expand Down
38 changes: 38 additions & 0 deletions src/extension/ui/src/components/Runner.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { Paper, Typography, Button } from '@mui/material';
import { useEffect } from 'react';

type RunnerProps = {
selectedProject: string | null;
selectedPrompt: string | null;
openAIKey: string | null;
startPrompt: () => void;
renderPrompt: () => void;
}

const Runner: React.FC<RunnerProps> = ({ selectedProject, selectedPrompt, openAIKey, startPrompt, renderPrompt }) => {
useEffect(() => {
if (selectedProject && selectedPrompt && openAIKey) {
// renderPrompt();
}
}, [selectedProject, selectedPrompt, openAIKey]);

return selectedProject && selectedPrompt && openAIKey ? (
<Paper sx={{ padding: 1 }}>
<Typography variant="h3">Ready</Typography>
<pre>PROJECT={selectedProject}</pre>
<pre>PROMPT={selectedPrompt}</pre>
<Button sx={{ mt: 1, }} color='success' onClick={startPrompt}>
Run
</Button>
</Paper>
) : (
<Paper sx={{ padding: 1 }}>
<Typography variant='h3'>Missing:</Typography>
{selectedProject?.length ? null : <Typography variant='body1'> - Project</Typography>}
{selectedPrompt?.length ? null : <Typography variant='body1'> - Prompt</Typography>}
{openAIKey?.length ? null : <Typography variant='body1'> - OpenAI Key</Typography>}
</Paper>
)
}

export default Runner;

0 comments on commit 405ee06

Please sign in to comment.