Skip to content

Commit

Permalink
Updates prompts: pages fixing, operations fixing
Browse files Browse the repository at this point in the history
  • Loading branch information
infomiho committed Jun 29, 2023
1 parent 3e6e89d commit 88a8f6a
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 15 deletions.
5 changes: 1 addition & 4 deletions waspc/src/Wasp/AI/GenerateNewProject.hs
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,8 @@ generateNewProject newProjectDetails waspProjectSkeletonFiles = do

writeToLog "Fixing any mistakes in pages..."
forM_ (getPageComponentPath <$> pages) $ \pageFp -> do
fixPageComponent newProjectDetails waspFilePath pageFp
fixPageComponent newProjectDetails waspFilePath pageFp actions queries
writeToLog $ T.pack $ "Fixed '" <> pageFp <> "' page."
-- forM_ getPageComponentPath pages $ \pageFp -> do
-- fixPageComponent newProjectDetails waspFilePath pageFp
-- writeToLog $ T.pack $ "Fixed '" <> pageFp <> "' page."
writeToLog "Pages fixed."

(promptTokensUsed, completionTokensUsed) <- getTotalTokensUsage
Expand Down
5 changes: 5 additions & 0 deletions waspc/src/Wasp/AI/GenerateNewProject/OperationsJsFile.hs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ fixOperationsJsFile newProjectDetails waspFilePath opJsFilePath = do

- There might be some invalid JS syntax -> fix it if there is any.
- If there is some obvious refactoring that could improve code quality, go for it.
- Use the "arg" variable to get the arguments of the operation.
For example, if the operation is "createTask", then you can get the arguments like this:
```js
const { name, description } = arg;
```

With this in mind, generate a new, fixed NodeJS file with operations (${opJsFilePathText}).
Do actual fixes, don't leave comments with "TODO"!
Expand Down
1 change: 1 addition & 0 deletions waspc/src/Wasp/AI/GenerateNewProject/Page.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module Wasp.AI.GenerateNewProject.Page
( generateAndWritePage,
pageDocPrompt,
getPageComponentPath,
operationInfo,
Page (..),
)
where
Expand Down
27 changes: 18 additions & 9 deletions waspc/src/Wasp/AI/GenerateNewProject/PageComponentFile.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ import Wasp.AI.GenerateNewProject.Common
)
import Wasp.AI.GenerateNewProject.Common.Prompts (appDescriptionBlock)
import qualified Wasp.AI.GenerateNewProject.Common.Prompts as Prompts
import Wasp.AI.GenerateNewProject.Page (pageDocPrompt)
import Wasp.AI.GenerateNewProject.Operation (Operation)
import Wasp.AI.GenerateNewProject.Page (operationInfo, pageDocPrompt)
import Wasp.AI.OpenAI.ChatGPT (ChatMessage (..), ChatRole (..))

fixPageComponent :: NewProjectDetails -> FilePath -> FilePath -> CodeAgent ()
fixPageComponent newProjectDetails waspFilePath pageComponentPath = do
fixPageComponent :: NewProjectDetails -> FilePath -> FilePath -> [Operation] -> [Operation] -> CodeAgent ()
fixPageComponent newProjectDetails waspFilePath pageComponentPath actions queries = do
currentWaspFileContent <- fromMaybe (error "couldn't find wasp file") <$> getFile waspFilePath
currentPageComponentContent <- fromMaybe (error "couldn't find page file to fix") <$> getFile pageComponentPath
fixedPageComponent <-
Expand All @@ -34,6 +35,9 @@ fixPageComponent newProjectDetails waspFilePath pageComponentPath = do
]
writeToFile pageComponentPath (const $ pageComponentImpl fixedPageComponent)
where
actionsInfo = T.intercalate "\n" $ (" - " <>) . operationInfo <$> actions
queriesInfo = T.intercalate "\n" $ (" - " <>) . operationInfo <$> queries

fixPageComponentPrompt currentWaspFileContent currentPageContent =
[trimming|
${basicWaspLangInfoPrompt}
Expand All @@ -60,16 +64,21 @@ fixPageComponent newProjectDetails waspFilePath pageComponentPath = do
The NodeJS file with operations likely has some mistakes: let's fix it!

Some common mistakes to look for:
- "TODO" comments or "..." that should be replaced with actual implementation.
Fix these by replacing them with actual implementation.
- Duplicate imports. If there are any, make sure to remove them.
- There might be some invalid JS or JSX syntax -> fix it if there is any.
- If there is some obvious refactoring that could improve code quality, go for it.
- Make sure to use valid queries and actions that are defined in the Wasp file.
- Make sure to use only queries and actions that are defined in the Wasp file (listed below)
- You should import queries from "@wasp/queries/{queryName}" like import getTask from '@wasp/queries/getTasks';
- You should import actions from "@wasp/actions/{actionName}" like import createTask from '@wasp/actions/createTask';
- Use Tailwind CSS to style the page if you didn't.
- Use <Link /> component from "react-router-dom" to link to other pages where needed.
- "TODO" comments or "..." that should be replaced with actual implementation.
Fix these by replacing them with actual implementation.
- Duplicate imports. If there are any, make sure to remove them.
- There might be some invalid JS or JSX syntax -> fix it if there is any.

Actions:
${actionsInfo}

Queries:
${queriesInfo}

With this in mind, generate a new, fixed React component (${pageComponentPathText}).
Do actual fixes, don't leave comments with "TODO"!
Expand Down
22 changes: 20 additions & 2 deletions waspc/src/Wasp/AI/GenerateNewProject/WaspFile.hs
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,26 @@ fixWaspFile newProjectDetails waspFilePath = do
- Value of `fn:` field in `query` or `action` not having correct import syntax,
for example it might have invalid syntax, e.g. `fn: @server/actions.js`.
Fix these by replacing it with correct syntax, e.g. `fn: import { actionName } from "@server/actions.js"`.
- Entities having a reference to another entity but that entity doesn't have a reference back to it.
Fix these by adding a reference back to the entity that is referenced.
- If two entities are in a relation, make sure that they both have a field that references the other entity.
- If an entity has a field that references another entity (e.g. location), make sure to include @relation directive on that field.
- If an entity references another entity, make sure the ID field (e.g. locationId) of the referenced entity is also included.

```
entity Location {=psl
id Int @id @default(autoincrement())
latitude Float
longitude Float
weathers Weather[]
psl=}

entity Weather {=psl
id Int @id @default(autoincrement())
temperature Float
description String
location Location @relation(fields: [locationId], references: [id])
locationId Int
psl=}
```

With this in mind, generate a new, fixed wasp file.
Do actual fixes, don't leave comments with "TODO"!
Expand Down

0 comments on commit 88a8f6a

Please # to comment.