I am just starting from the place I left off. Its time for some complex inputs or detailed inputs to the Co-Pilot
- Here is a detailed set of instruction for loading all the files.
- Prompt : "Generate a golang program to read the following files and load the contents onto a local mongodb host having a database called bot. Please use the library go.mongodb.org/mongo-driver/mongo for mongodb connections1)curatedContent.csv is a file having rowNumber,contentSubjectArea,contentSubjectAreaSubArea,learningContentId,learningStep,contentType,contentDescription,contentURL,smenotes,transcript,pycodeSnippet. Here rowNumber,learningContentId,learningStep are of type integer. The collection name should be curatedContent.2)userDataset.csv is a file having userName, userPassword and userRole. The sensitive data must be encrypted using bcrypt before loading into the database. The collection name should be users.3)knowledgeBase.csv is a file having rowNumber,kbNumber,query,response. Here rowNumber,kbNumber are of type integer. The collection name should be knowledgeBase.4)learningModules.csv is a file having rowNumber,learningModuleName,learningModuleFriendlyName,learningModuleDetailedDescription. Here rowNumber is of type integer. The collection name should be learningModules.5)Queries.csv is a file having rowNumber,contentSubjectAreaSubArea,learningContentId,querynumber,queryGroup,queryType,query,answer,Option1,Option2,Option3,Option4,Option5,correctSolution,relevantKnowledgebase. Here rowNumber,kbNumber,learningContentId,querynumber,queryGroup are of type integer. The collection name should be queries."
- If you observe I gave some very specific instructions to the Co-Pilot, the mongodb library I want to use and also specified the collection names that needs to be created. I observed that for some reason Co-Pilot was using another mongodb library which was throwing an error on unable to connect, so I resorted to using something which has been tested and used before. Co-Pilot did follow my instructions on the library as well as the collection names.
- Here is a snapshot of the collections I was able to create by running the program and each of the collections was loaded the data from the CSV file.
-
- This time around the prompt was longer, more contextual instructions were embedded in the prompt as well.
- Did it generate the right code, yes it indeed generate a functional code. Yes probably there are better ways to write it.
- I tried to introduce an error in the struct that has been defined for the data. Typically the first letter of the field in the struct has to be capital else it will not work. I have described this quirkiness in one my blogs and this can be an error which one will never realise. After I knowingly changed the field name I ran "Fix this" through the Co-Pilot menu option and it fixed the issue.
-
- I have this 1600 line code in golang which functions as a middleware. This was written back in 2020 for a bot that I had developed.
- I selected the code base and tried this prompt "Is there a better way to code this, share your recommendations with specific libraries or packages as bulleted points.?"
-
- The recommendations were on dot. I have used the default http package and Gorilla Mux is one of the most popular routing package to handle requests.
- Let's try asking the Co-Pilot to change my code to reflect Gorilla Mux, I used the following prompt "Can you change the selected code to use Gorilla Mux instead of default http package". The following is the recommended changes.
-
- The changes seem fine but there is a problem the with the new additions. Co-Pilot is creating a new import somewhere in the middle of the code base as can be seen here. The actual import starts at line 1 however Co-Pilot makes a copy of the entire import sequence and introduces it at line 149, kind of weird, not sure how to tell the Co-Pilot NOT to introduce a duplicate import section.
-
- However I made the changes manually and installed gorilla mux using "go get -u github.com/gorilla/mux" and added it to the import section.
- I revised the main code as recommended, Co-Pilot determined it was a POST but I wanted to execute only GET so additional changed the same to GET only
func main() {
//handleRequests()
r := mux.NewRouter()
r.HandleFunc("/", homePage)
r.HandleFunc("/getCuratedContentCount", getCuratedContentCount).Methods("GET")
log.Fatal(http.ListenAndServe(":10000", r))
}
- I reran the code to check if it works. Well it worked just fine.
- I also followed the recommendation to use the viper package. I found the same behaviour in terms of right recommended code changes but the placement of the revised code goes for a toss so it cannot be accepted by default
- It's definitely interesting to note that Co-Pilot does give the recommendations which are inline with the current code base. It's smart enough to understand which libraries are in use and suggest alternate robust libraries. The Co-Pilot also looks at the hard coded strings within the code base and suggests the right approach and library to refactor it.
- It's important to vet the recommended code changes before accepting it and also test the recommended code in its entirety before adoption.
In the next article I will try out a few more recommendations and explore how Co-Pilot responds and also additionally want to understand the reason the Co-Pilot is misplacing the recommended code onto a different pathway.
Senior Manager - Data & Analytics | Intelligent Industry | Capgemini Invent
1 年Interesting Vishwa ! This aligns with Gartner's report on Gen AI where they mentioned that around 43% of the early movers have started leveraging Gen AI for code generation and I see no reasons why it won't shoot up above 70% very quickly as forecasted.
PhD in CSE (JU) || Product Owner || Gen AI Practitioner || Director @LTIMindtree|| Dedicated Researcher in Data Science, Gen AI || Mentor || Patents on AI/DS/Gen AI
1 年Great one Vishwa! Specially the Scenario 7 where it's providing the recommendation considering the whole existing codebase. Just want to understand what is the metric it's following to measure the better code? Is it time and space complexity? or something else?