Skip to content

Commit

Permalink
Add option to specify Plan GPT model from CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
jankovidakovic committed Dec 11, 2023
1 parent 745a02e commit 2559d30
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
16 changes: 16 additions & 0 deletions waspc/src/Wasp/AI/GenerateNewProject/Common.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ module Wasp.AI.GenerateNewProject.Common
queryChatGPTForJSON,
defaultChatGPTParams,
defaultChatGPTParamsForFixing,
defaultChatGPTParamsForPlan,
defaultChatGPTParamsForPlanFixing,
writeToWaspFileEnd,
)
where
Expand All @@ -34,6 +36,7 @@ data NewProjectConfig = NewProjectConfig
-- One of the Tailwind color names: https://tailwindcss.com/docs/customizing-colors
projectPrimaryColor :: !(Maybe String),
projectDefaultGptModel :: !(Maybe GPT.Model),
projectPlanGptModel :: !(Maybe GPT.Model),
projectDefaultGptTemperature :: !(Maybe Float)
}
deriving (Show)
Expand All @@ -43,12 +46,14 @@ instance Aeson.FromJSON NewProjectConfig where
auth <- obj .:? "auth"
primaryColor <- obj .:? "primaryColor"
defaultGptModel <- obj .:? "defaultGptModel"
planGptModel <- obj .:? "defaultGptModel"
defaultGptTemperature <- obj .:? "defaultGptTemperature"
return
( NewProjectConfig
{ projectAuth = auth,
projectPrimaryColor = primaryColor,
projectDefaultGptModel = defaultGptModel,
projectPlanGptModel = planGptModel,
projectDefaultGptTemperature = defaultGptTemperature
}
)
Expand All @@ -59,6 +64,7 @@ emptyNewProjectConfig =
{ projectAuth = Nothing,
projectPrimaryColor = Nothing,
projectDefaultGptModel = Nothing,
projectPlanGptModel = Nothing,
projectDefaultGptTemperature = Nothing
}

Expand Down Expand Up @@ -145,6 +151,16 @@ defaultChatGPTParamsForFixing projectDetails =
let params = defaultChatGPTParams projectDetails
in params {GPT._temperature = subtract 0.2 <$> GPT._temperature params}

defaultChatGPTParamsForPlan :: NewProjectDetails -> ChatGPTParams
defaultChatGPTParamsForPlan projectDetails =
let params = defaultChatGPTParams projectDetails
in params {GPT._model = fromMaybe GPT.GPT_4 (projectPlanGptModel $ _projectConfig projectDetails)}

defaultChatGPTParamsForPlanFixing :: NewProjectDetails -> ChatGPTParams
defaultChatGPTParamsForPlanFixing projectDetails =
let params = defaultChatGPTParamsForPlan projectDetails
in params {GPT._temperature = subtract 0.2 <$> GPT._temperature params}

writeToWaspFileEnd :: FilePath -> Text -> CodeAgent ()
writeToWaspFileEnd waspFilePath text = do
writeToFile waspFilePath $
Expand Down
12 changes: 5 additions & 7 deletions waspc/src/Wasp/AI/GenerateNewProject/Plan.hs
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ import qualified Text.Parsec as Parsec
import Wasp.AI.CodeAgent (CodeAgent, writeToLog)
import Wasp.AI.GenerateNewProject.Common
( NewProjectDetails (..),
defaultChatGPTParams,
defaultChatGPTParamsForFixing,
defaultChatGPTParamsForPlan,
defaultChatGPTParamsForPlanFixing,
queryChatGPTForJSON,
)
import Wasp.AI.GenerateNewProject.Common.Prompts (appDescriptionBlock)
import qualified Wasp.AI.GenerateNewProject.Common.Prompts as Prompts
import Wasp.AI.OpenAI.ChatGPT (ChatGPTParams (_model), ChatMessage (..), ChatRole (..), Model (GPT_4))
import Wasp.AI.OpenAI.ChatGPT (ChatMessage (..), ChatRole (..))
import qualified Wasp.Psl.Format as Prisma
import qualified Wasp.Psl.Parser.Model as Psl.Parser
import qualified Wasp.Util.Aeson as Util.Aeson
Expand All @@ -42,7 +42,7 @@ type PlanRule = String
generatePlan :: NewProjectDetails -> [PlanRule] -> CodeAgent Plan
generatePlan newProjectDetails planRules = do
writeToLog "Generating plan (slowest step, usually takes 30 to 90 seconds)..."
initialPlan <- queryChatGPTForJSON ((defaultChatGPTParams newProjectDetails) {_model = planGptModel}) chatMessages
initialPlan <- queryChatGPTForJSON (defaultChatGPTParamsForPlan newProjectDetails) chatMessages
writeToLog $ "Initial plan generated!\n" <> summarizePlan initialPlan
writeToLog "Fixing initial plan..."
fixedPlan <- fixPlanRepeatedly 3 initialPlan
Expand Down Expand Up @@ -170,7 +170,7 @@ generatePlan newProjectDetails planRules = do
|]
writeToLog "Sending plan to GPT for fixing..."
fixedPlan <-
queryChatGPTForJSON ((defaultChatGPTParamsForFixing newProjectDetails) {_model = planGptModel}) $
queryChatGPTForJSON (defaultChatGPTParamsForPlanFixing newProjectDetails) $
chatMessages
<> [ ChatMessage {role = Assistant, content = Util.Aeson.encodeToText plan'},
ChatMessage
Expand All @@ -190,8 +190,6 @@ generatePlan newProjectDetails planRules = do
]
return (False, fixedPlan)

planGptModel = GPT_4

checkPlanForEntityIssues :: Plan -> [String]
checkPlanForEntityIssues plan =
checkNumEntities
Expand Down

0 comments on commit 2559d30

Please sign in to comment.