-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add quick-tools schema, api, saving, etc.
- Loading branch information
Showing
9 changed files
with
119 additions
and
57 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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
const std = @import("std"); | ||
const fr = @import("fridge"); | ||
const schema = @import("../schema.zig"); | ||
|
||
pub fn @"GET /quick-tools"(db: *fr.Session) ![]const schema.QuickTool { | ||
return db.findAll(fr.query(schema.QuickTool).orderBy(.id, .asc)); | ||
} | ||
|
||
pub fn @"GET /quick-tools/:id"(db: *fr.Session, id: u32) !schema.QuickTool { | ||
return try db.find(schema.QuickTool, id) orelse error.NotFound; | ||
} | ||
|
||
pub fn @"POST /quick-tools"(db: *fr.Session, data: schema.QuickTool) !schema.QuickTool { | ||
return db.create(schema.QuickTool, data); | ||
} | ||
|
||
pub fn @"PUT /quick-tools/:id"(db: *fr.Session, id: u32, data: schema.QuickTool) !schema.QuickTool { | ||
return try db.update(schema.QuickTool, id, data) orelse error.NotFound; | ||
} | ||
|
||
pub fn @"DELETE /quick-tools/:id"(db: *fr.Session, id: u32) !void { | ||
try db.delete(schema.QuickTool, id); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,55 @@ | ||
import { SquarePen } from "lucide" | ||
import { AutoScroll, Button, Form, FormGrid, GenerationProgress, IconButton, Markdown, Page, Field } from "../_components" | ||
import { useGenerate } from "../_hooks" | ||
import { err, parseVars, template, humanize } from "../_util" | ||
import { examples } from "./_examples" | ||
import { useGenerate, useQuery } from "../_hooks" | ||
import { parseVars, template, humanize } from "../_util" | ||
import { api } from "../api" | ||
|
||
export const QuickTool = ({ params: { id } }) => { | ||
const { generate, result, ...progress } = useGenerate() | ||
|
||
const tool = examples.find(t => t.id === +id) ?? err("Tool not found") | ||
const variableNames = parseVars(tool.prompt) | ||
const { data: tool } = useQuery(id && api.getQuickTool(id)) | ||
|
||
const handleSubmit = data => generate({ prompt: template(tool.prompt, data) }) | ||
|
||
return ( | ||
<Page> | ||
<Page.Header title={tool.name}> | ||
<IconButton title="Edit" icon={SquarePen} href={`/quick-tools/${id}/edit`} /> | ||
</Page.Header> | ||
|
||
<Page.Content class="bg-neutral-2"> | ||
<Form class="vstack" onSubmit={handleSubmit}> | ||
<p class="py-4 text-neutral-11 text-center">{tool.description}</p> | ||
|
||
<FormGrid class="mt-4 w-full max-w-lg self-center"> | ||
{variableNames.map(name => ( | ||
<> | ||
<label>{humanize(name)}</label> | ||
{name.endsWith("text") ? <Field as="textarea" name={name} rows={10} /> : <Field name={name} />} | ||
</> | ||
))} | ||
|
||
<div /> | ||
<Button submit>Generate</Button> | ||
</FormGrid> | ||
</Form> | ||
</Page.Content> | ||
|
||
<Page.DetailsPane sizes={[400, 500, 800]}> | ||
<div class="vstack overflow-hidden"> | ||
<h3 class="px-4 py-2 uppercase font-medium text(sm neutral-11)">Result</h3> | ||
<div class="px-4 py-2 overflow-auto"> | ||
{/* TODO: This will trigger a re-render on every token */} | ||
{result.value === "" && <p class="text-neutral-11">Click generate to see the result</p>} | ||
|
||
<Markdown input={result} class="mb-2" /> | ||
<GenerationProgress {...progress} /> | ||
<AutoScroll /> | ||
tool && ( | ||
<Page> | ||
<Page.Header title={tool.name}> | ||
<IconButton title="Edit" icon={SquarePen} href={`/quick-tools/${id}/edit`} /> | ||
</Page.Header> | ||
|
||
<Page.Content class="bg-neutral-2"> | ||
<Form class="vstack" onSubmit={handleSubmit}> | ||
<p class="py-4 text-neutral-11 text-center">{tool.description}</p> | ||
|
||
<FormGrid class="mt-4 w-full max-w-lg self-center"> | ||
{parseVars(tool.prompt).map(name => ( | ||
<> | ||
<label>{humanize(name)}</label> | ||
{name.endsWith("text") ? <Field as="textarea" name={name} rows={10} /> : <Field name={name} />} | ||
</> | ||
))} | ||
|
||
<div /> | ||
<Button submit>Generate</Button> | ||
</FormGrid> | ||
</Form> | ||
</Page.Content> | ||
|
||
<Page.DetailsPane sizes={[400, 500, 800]}> | ||
<div class="vstack overflow-hidden"> | ||
<h3 class="px-4 py-2 uppercase font-medium text(sm neutral-11)">Result</h3> | ||
<div class="px-4 py-2 overflow-auto"> | ||
{/* TODO: This will trigger a re-render on every token */} | ||
{result.value === "" && <p class="text-neutral-11">Click generate to see the result</p>} | ||
|
||
<Markdown input={result} class="mb-2" /> | ||
<GenerationProgress {...progress} /> | ||
<AutoScroll /> | ||
</div> | ||
</div> | ||
</div> | ||
</Page.DetailsPane> | ||
</Page> | ||
</Page.DetailsPane> | ||
</Page> | ||
) | ||
) | ||
} |
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