diff --git a/website/cypress/e2e/create/initial_prompt.cy.ts b/website/cypress/e2e/create/initial_prompt.cy.ts new file mode 100644 index 00000000..b17f2dd9 --- /dev/null +++ b/website/cypress/e2e/create/initial_prompt.cy.ts @@ -0,0 +1,26 @@ +import { faker } from "@faker-js/faker"; + +describe("creating initial prompts", () => { + it("completes the current task on submit and on request shows a new task", () => { + cy.signInWithEmail("cypress@example.com"); + cy.visit("/create/initial_prompt"); + + cy.get('[data-cy="task-id"').then((taskIdElement) => { + const taskId = taskIdElement.text(); + + const prompt = faker.lorem.sentence(); + cy.log("prompt", prompt); + cy.get('[data-cy="reply"').type(prompt); + + cy.get('[data-cy="submit"]').click(); + + cy.get('[data-cy="next-task"]').click(); + + cy.get('[data-cy="task-id"').should((taskIdElement) => { + expect(taskIdElement.text()).not.to.eq(taskId); + }); + }); + }); +}); + +export {}; diff --git a/website/src/components/TaskSelection/TaskSelection.tsx b/website/src/components/TaskSelection/TaskSelection.tsx index f258a90b..683c80e9 100644 --- a/website/src/components/TaskSelection/TaskSelection.tsx +++ b/website/src/components/TaskSelection/TaskSelection.tsx @@ -26,6 +26,12 @@ export const TaskSelection = () => { title="Summarize stories" link="/create/summarize_story" /> */} + { + const [tasks, setTasks] = useState([]); + + const inputRef = useRef(null); + + const { isLoading, mutate } = useSWRImmutable("/api/new_task/initial_prompt ", fetcher, { + onSuccess: (data) => { + setTasks([data]); + }, + }); + + const { trigger } = useSWRMutation("/api/update_task", poster, { + onSuccess: async (data) => { + const newTask = await data.json(); + setTasks((oldTasks) => [...oldTasks, newTask]); + }, + }); + + const submitResponse = (task: { id: string }) => { + const text = inputRef.current.value.trim(); + trigger({ + id: task.id, + update_type: "text_reply_to_message", + content: { + text, + }, + }); + }; + + const fetchNextTask = () => { + inputRef.current.value = ""; + mutate(); + }; + + const { colorMode } = useColorMode(); + const mainBgClasses = colorMode === "light" ? "bg-slate-300 text-gray-800" : "bg-slate-900 text-white"; + + if (isLoading) { + return ; + } + + if (tasks.length == 0) { + return No tasks found...; + } + + const task = tasks[0].task; + + return ( + + + <> + Start a conversation + Create an initial message to send to the assistant + > + + + + + + ); +}; + +export default InitialPrompt;
Create an initial message to send to the assistant