-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3464 from quantified-uncertainty/publish-ai-model
"Publish" in Squiggle AI
- Loading branch information
Showing
16 changed files
with
313 additions
and
273 deletions.
There are no files selected for viewing
70 changes: 70 additions & 0 deletions
70
apps/hub/src/app/ai/WorkflowViewer/PublishWorkflowButton.tsx
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,70 @@ | ||
import { useRouter } from "next/navigation"; | ||
import { FC, useState } from "react"; | ||
|
||
import { ClientWorkflow } from "@quri/squiggle-ai"; | ||
import { Button } from "@quri/ui"; | ||
|
||
import { NewModelFormBody, NewModelFormShape } from "@/app/new/model/NewModel"; | ||
import { SafeActionFormModal } from "@/components/ui/SafeActionFormModal"; | ||
import { createModelAction } from "@/models/actions/createModelAction"; | ||
|
||
type Props = { | ||
workflow: Extract<ClientWorkflow, { status: "finished" }>; | ||
}; | ||
|
||
const PublishWorkflowModal: FC<Props & { close: () => void }> = ({ | ||
workflow, | ||
close, | ||
}) => { | ||
const router = useRouter(); | ||
|
||
const code = `/* | ||
Generated by Squiggle AI. Workflow ID: ${workflow.id} | ||
*/ | ||
${workflow.result.code}`; | ||
|
||
return ( | ||
<SafeActionFormModal<NewModelFormShape, typeof createModelAction> | ||
title="Publish Model" | ||
action={createModelAction} | ||
close={close} | ||
defaultValues={{ | ||
// TODO - LLM-generated slug | ||
isPrivate: false, | ||
}} | ||
formDataToInput={(data) => ({ | ||
code, | ||
slug: data.slug ?? "", | ||
groupSlug: data.group?.slug, | ||
isPrivate: data.isPrivate, | ||
})} | ||
submitText="Save" | ||
onSuccess={(data) => { | ||
// Note: redirect in server action would be incompatible with https://github.com/TheEdoRan/next-safe-action/issues/303 | ||
// (and might a bad idea anyway, returning a url is more verbose but more flexible for reuse) | ||
router.push(data.url); | ||
}} | ||
closeOnSuccess={false} | ||
> | ||
<NewModelFormBody /> | ||
</SafeActionFormModal> | ||
); | ||
}; | ||
|
||
export const PublishWorkflowButton: FC<Props> = ({ workflow }) => { | ||
const [isOpen, setIsOpen] = useState(false); | ||
|
||
return ( | ||
<> | ||
<Button theme="primary" size="small" onClick={() => setIsOpen(true)}> | ||
Save Model | ||
</Button> | ||
{isOpen && ( | ||
<PublishWorkflowModal | ||
workflow={workflow} | ||
close={() => setIsOpen(false)} | ||
/> | ||
)} | ||
</> | ||
); | ||
}; |
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
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.