Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Builtin docs linter & utilities #108

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
dirty code for generating all defs
  • Loading branch information
marcinjangrzybowski committed Apr 23, 2024
commit 235a861760c285fbc89278b735a18168493fcab1
31 changes: 29 additions & 2 deletions docs-utils/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

module Main where

import System.Directory (listDirectory, doesFileExist)
import System.FilePath ((</>),(<.>), takeBaseName, takeExtension)
import System.Directory (listDirectory, doesFileExist, createDirectoryIfMissing)
import System.FilePath ((</>),(<.>), takeBaseName, takeExtension,takeDirectory)
import Data.List (sort, (\\),intersperse,sortOn)
import Control.Monad (filterM,forM,forM_, when, unless)
import Pact.Core.Builtin
Expand Down Expand Up @@ -427,3 +427,30 @@ makeReport = do
where
presentFirst :: [[Text]] -> [[Text]]
presentFirst = reverse . sortOn (Text.length . head . (drop 1))



genInFolder :: Bool -> (a -> FilePath) -> (a -> IO Text) -> [ a ] -> IO ()
genInFolder verbose pathGenerator contentGenerator list
= forM_ list $ \item -> do
let path = pathGenerator item
let directoryPath = takeDirectory path
createDirectoryIfMissing True directoryPath
content <- contentGenerator item
withFile path WriteMode $ \h -> do
T.hPutStr h content
if verbose
then putStrLn $ "File " ++ path ++ " created."
else return ()

genDocumentation :: Bool -> FilePath -> Maybe Int -> IO ()
genDocumentation verbose path limit = do
let limitedBuiltins = case limit of
Just n -> take n $ drop 40 allCoreBuiltins
Nothing -> allCoreBuiltins
genInFolder verbose fileName contentGen limitedBuiltins
where
fileName :: CoreBuiltin -> FilePath
fileName bi = path </> (Text.unpack (coreBuiltinToText bi)) ++ ".md"
contentGen :: CoreBuiltin -> IO Text
contentGen = generateDocumentationForBuiltin verbose
2 changes: 1 addition & 1 deletion docs-utils/Snippets.hs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ findSnippets phrases repos = do

findSnippetsInRepo :: [Text] -> Repo -> IO (Map Text [Snippet])
findSnippetsInRepo phrases repo@(url, relativePath) = do
let repoPath = "/tmp" </> Text.unpack url -- assuming '/tmp' as base path
let repoPath = "/tmp" </> "temprepo" ---Text.unpack url -- assuming '/tmp' as base path
cloneRepo repoPath repo
files <- getPactOrReplFiles (repoPath </> relativePath)
fileSnippetMaps <- mapM (\file -> createSnippets phrases file (drop (length (repoPath </> relativePath)) file) repo) files
Expand Down
3 changes: 2 additions & 1 deletion docs-utils/StubGen.hs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ generateSectionPrompt docOfCurrentFromLegacyDocs snippets exampleDocInNewFormat
, Message "user" $ "Additionally, consider the following snippets from our repositories which show examples or use-cases of the `" ++ builtInName ++ "` function:"
, Message "user" snippets
, Message "user" $ "Using the provided example, legacy documentation, and code snippets, please write the '" ++ Text.unpack sectionHeading ++ "' section of the documentation taking into account the following description and instruction, remember! Generate only requested section, nothing more! :"
, Message "user" "Most importantly, be extreamly carefull to not introduce anything what cannot be directly infered from code snippets and previous version of documentation! Generated content must be as brief as possible."
, Message "user" sectionDescription
]
where
Expand Down Expand Up @@ -133,7 +134,7 @@ generateDocumentationForBuiltin verbose builtin = do
-- Use the ChatGPT API to generate content for the section
maybeSectionContent <- GPT.makeChatGPTRequest' messages
case maybeSectionContent of
Just sectionContent -> return sectionContent
Just sectionContent -> return $ sectionContent ++ "\n"
Nothing -> do
-- Log or handle the error case here
when verbose $
Expand Down