Github Co-Pilot -- Part 3
Image by VectorPortal.com ( https://vectorportal.com/ )

Github Co-Pilot -- Part 3

This is a continuation to my earlier article

I am just starting from the place I left off. Its time for some complex inputs or detailed inputs to the Co-Pilot

Scenario based code generation 5 - bunch of CSV files as a reference and mongodb as the destination

  • 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.

Scenario 6 - Simple Error Fixing

  • 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.

Scenario 7 - Code Recommendations based on the current code base

  • 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.


Abhishek Sarma, CSM?

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.

Anindita Desarkar, PhD

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?

要查看或添加评论,请登录

Vishwanathan Raman的更多文章

  • Generating Assessments using Gen AI -- Part 2

    Generating Assessments using Gen AI -- Part 2

    This is in continuation to the article https://www.linkedin.

    3 条评论
  • Generating Assessments using Gen AI

    Generating Assessments using Gen AI

    Assessment Generation has always been a task of a SME. It is a complex and time consuming task of both Development &…

    5 条评论
  • Flutter/Dart, Gemini API

    Flutter/Dart, Gemini API

    #ignAIte, #AI, #GenAI The past few weeks have been crazy, relearning a lost knowledge and then creating something fun…

    7 条评论
  • Github Co-Pilot -- Part 2

    Github Co-Pilot -- Part 2

    This is a continuation to my earlier article Scenario based code generation 3 - CSV file as a reference and mongodb as…

    2 条评论
  • Github Co-Pilot -- Part 1

    Github Co-Pilot -- Part 1

    Co-Pilot is an interesting topic within the Gen AI landscape and one of the most widely adopted areas. A report by…

    2 条评论
  • Gen AI -- Quantised Models -- llama.cpp -- Long Weekend Project Part 3

    Gen AI -- Quantised Models -- llama.cpp -- Long Weekend Project Part 3

    Here are the links to the my earlier articles first article, second article on building a Gen AI solution on the…

    3 条评论
  • Gen AI -- Long Weekend Project Part 2

    Gen AI -- Long Weekend Project Part 2

    Here is the followup to my first article I remember the phrase "When the GOING gets tough the TOUGH gets going" and…

    2 条评论
  • Gen AI Weekend Project

    Gen AI Weekend Project

    The World Cup is on. The match against PAK on 14-Oct was anti-climax, maybe our Indian team was too good for the other…

    8 条评论
  • Lessons learnt using Golang and MongoDB

    Lessons learnt using Golang and MongoDB

    This past quarter I have been experimenting with Golang and this past week in particular, my downtime from work, I have…

  • Golang Quirkiness

    Golang Quirkiness

    Over last few days I have been fiddling with Golang and was quick to realize that it was not for faint heart…

社区洞察

其他会员也浏览了