Skip to content

Commit

Permalink
Inline AI Improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
rob-gordon committed Jan 12, 2024
1 parent 5564627 commit ee9aa14
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
4 changes: 4 additions & 0 deletions api/_lib/_llm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ export async function llmMany<T extends Record<string, ZodObject<any>>>(

const completion = await openai.chat.completions.create({
messages: [
{
role: "system",
content: `You are a helpful AI flowchart wizard. Create or update a flowchart for the user according the given message. Always respond with a complete and correct flowchart. If the user requests an entirely new flowchart, ignore the curren state and start from scratch.`,
},
{
role: "user",
content,
Expand Down
8 changes: 4 additions & 4 deletions api/prompt/edit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ const handler: VercelApiHandler = async (req, res) => {
}

const result = await llmMany(
`You are a one-shot AI flowchart assistant. Help the user with a flowchart or diagram. Here is the current state of the flowchart:
`${prompt}
Here is the current state of the flowchart:
${JSON.stringify(graph, null, 2)}
Here is the user's message:
${prompt}`,
`,
{
updateGraph: graphSchema,
}
Expand Down
18 changes: 16 additions & 2 deletions app/src/components/EditWithAI.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ export function EditWithAI() {
[edit, isProUser]
);

const [txtPrompt, setTxtPrompt] = useState("");
const handleSubmit = useCallback(
(e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault();
Expand Down Expand Up @@ -177,7 +178,7 @@ export function EditWithAI() {
color="purple"
size="sm"
rounded
className="aria-[expanded=true]:bg-purple-700 !pt-2 !pb-[9px] !pl-3 !pr-4"
className="aria-[expanded=true]:bg-purple-700 !pt-2 !pb-[9px] !pl-3 !pr-4 disabled:!opacity-100"
isLoading={isLoading}
>
<span className="text-[15px]">
Expand All @@ -191,6 +192,17 @@ export function EditWithAI() {
sideOffset={10}
align="end"
className="w-[300px] bg-white rounded shadow border border-purple-300 p-2 !z-[100] animate-slideDownAndFade dark:bg-neutral-300 dark:text-neutral-800 dark:border-neutral-300"
onOpenAutoFocus={(e) => {
e.preventDefault();
if (!formRef.current) return;

// highlight the contexts of the textarea inside the form
const textarea = formRef.current.querySelector("textarea");
if (!textarea) return;

textarea.focus();
textarea.select();
}}
>
<form className="grid gap-2" onSubmit={handleSubmit} ref={formRef}>
<div className="relative">
Expand All @@ -199,6 +211,8 @@ export function EditWithAI() {
className="text-xs w-full resize-none h-24 p-2 leading-normal dark:bg-neutral-300"
name="prompt"
required
value={txtPrompt}
onChange={(e) => setTxtPrompt(e.target.value)}
onKeyDown={(e) => {
if (!formRef.current) return;

Expand Down Expand Up @@ -232,7 +246,7 @@ export function EditWithAI() {
>
<Toast.Description>
<div className="flex text-xs items-center gap-3">
<Robot size={24} />
<Robot size={24} className="shrink-0" />
<p className="leading-normal">{message}</p>
</div>
</Toast.Description>
Expand Down

0 comments on commit ee9aa14

Please sign in to comment.