0% found this document useful (0 votes)
32 views22 pages

Session 14 Generative AI - For Software Engineering

The document discusses leveraging Generative AI in software engineering to enhance quality and productivity through automated code generation, testing, and security reviews. It outlines key areas of impact, including research and design, code generation, and bug detection, while also highlighting considerations for developers when integrating AI into the software development lifecycle. Additionally, it presents various AI models and tools that assist developers in code generation and optimization tasks.

Uploaded by

Nameless Wonder
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views22 pages

Session 14 Generative AI - For Software Engineering

The document discusses leveraging Generative AI in software engineering to enhance quality and productivity through automated code generation, testing, and security reviews. It outlines key areas of impact, including research and design, code generation, and bug detection, while also highlighting considerations for developers when integrating AI into the software development lifecycle. Additionally, it presents various AI models and tools that assist developers in code generation and optimization tasks.

Uploaded by

Nameless Wonder
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 22

Generative AI - for Software Engineering

• Leveraging Gen AI to Improve Quality and Productivity


• Prompts for Code Generation
Ram N Sangwan • Prompts for Test Case Generation
• Model(s) for Developers
How to Leverage Generative AI to Improve Quality,
Productivity in software engineering
Main Areas of Impact

Research and Design

AI facilitates faster prototyping and iteration in the


research and design phases, aiding in the
development of innovative software solutions.

Code generation

Generative AI accelerates the coding process by


automating repetitive tasks, leading to increased
productivity and faster development cycles.

Security review and bug detection

By automating security checks and bug detection, AI helps fortify


software against vulnerabilities and enhances overall quality.
Generative AI Can Assist With

Automated Code Optimization.

Code Review.

Automated Refactoring.

Style Consistency.

Vulnerability Detection.
Leverage Gen AI to Improve Quality and Productivity

Specifically, generative AI can help software developers with


• Automated Code Analysis: GenAI can automatically analyze code to identify
potential errors, bugs, or vulnerabilities.
• Predictive Analytics: By analyzing past data and patterns, generative AI can
predict where bugs are most likely to occur and help developers proactively
address them.
• Real-time Monitoring: Generative AI can monitor software applications in real-
time, identifying and alerting developers to potential bugs or issues as they
occur.
Considerations for Software Developers
Software development teams must consider:
• Where generative AI best fits into the SDLC – a clear roadmap for implementing AI
is key.
• How to train software developers – It’s important to educate your team on best
practices for generating the desired results.
• IP protection and security – Sensitive data and proprietary information must be
regulated internally.
Despite these considerations, the benefits of using generative AI in software
development are numerous.
LLMs for Developers
Several Gen AI models can support code generation tasks:
1. Command from Cohere, have been used for code generation tasks.
2. Seq2Seq Models: Often built with RNNs or LSTMs, are used for tasks that involve
converting one sequence into another.
3. CTRL (Conditional Transformer Language Model): CTRL is a conditional language
model that uses transformers to generate text conditioned on a given prompt or input.
4. CodeBERT: This is a variant of BERT that has been pre-trained on code from GitHub. It
can be used for various tasks related to code, including code generation.
5. TransCoder: This model by Meta AI is specifically designed for translating between
programming languages, which is a form of code generation.
TransCoder
• Clone the git repository for transcoder in local environment
git clone https://github.com/facebookresearch/TransCoder transcoder/

• Download the model files


wget https://dl.fbaipublicfiles.com/transcoder/model_1.pth /

• Since transcoder is implemented in pytorch, we need to install pytorch first


yum install clang
pip install torch torchvision

• Now install other required documentations


pip install numpy fastBPE Moses Apex libclang submitit six sacrebleu==1.2.11 clang fastBPE

• Now we run the translate.py file with src_lang file and tgt_lang file. The command below may take some
time to run
python transcoder/translate.py --src_lang java \
--tgt_lang python \
--model_path model_1.pth > code2.java
Code Generation Prompts
Code Generation Prompts
Generate a Docker script
• The following prompt generates a Docker script to create a Linux machine with specific libraries
installed:
Generate a Docker script to create a simple linux machine that has python 3.10
installed with following libraries: pandas, tensorflow, numpy
Code Generation Prompts
Generate a function
• The following prompt generates a function that inputs a year and determines if it's a
leap year or not:

Write a function in c language


that checks if a year is a leap
year.
Generate a unit test
You can use the code generation model to generate a unit test.
• The following prompt generates a unit test for a function that determines if a year is a
leap year or not.

Write a unit test for this function:


def is_leap_year(year):
if year % 4 == 0:
if year % 100 == 0:
if year % 400 == 0:
return True
else:
return False
else:
return True
else:
return False
Generate a unit test - Responce
Generating Code in Playground
• The Cohere Playground (Chat Mode) and the command model are used in these examples
• As with all command models from Cohere, you can use a Preamble to define the behaviour and format
of the responses.
• We will use the following Preamble:

You are a helpful code assistant that can teach a junior developer
how to code. Your language of choice is Python. Don't explain the
code, just generate the code block itself.

• The User Message will then be the prompt itself with the instruction of the specific code you want the
model to generate.
Basic Example
Here is the prompt if you want to try it yourself:
Write code that asks the user for their name and say "Hello"
Turn Comments Into Code
• You can also use the code generation capabilities of these LLMs to generate code from comments alone.
Prompt:
"""1. Create a list of movies
2. Create a list of ratings for these movies
3. Combine them to make a json object of 10 movies with their ratings."""
MySQL Query Generation
• Let's say you have a dataset with some information which you can include
as part of the prompt and then instruct it to generate a specific query.
For example:
"""Table departments,columns = [DepartmentId, DepartmentName]
Table students, columns = [DepartmentId, StudentId, StudentName]
Create a MySQL query for all students in the Computer Science department""”
Example 2: Enum
Let's do some more parsing with it
• If you are testing this example, it could be useful to have this database created.
• One approach is using a modified version of the prompt above with slightly different instructions to
generate a database schema:
Table departments, columns = [DepartmentId, DepartmentName]
Table students, columns = [DepartmentId, StudentId, StudentName]
Create a valid database schema with the above tables and columns
Add Dummy Data..
You will also need dummy data to test if the original generated query was valid. :

CREATE TABLE departments ( DepartmentId INT PRIMARY KEY, DepartmentName VARCHAR(50));

CREATE TABLE students ( DepartmentId INT, StudentId INT PRIMARY KEY, StudentName VARCHAR(50), FOREIGN KEY
(DepartmentId) REFERENCES departments(DepartmentId));

Given the database schema above, generate valid insert statements include 4 rows for each table.
Explain Code
• If you are learning to program in a certain language, it might be useful to prompt the model to explain
certain bits of code.
• Let's reuse the query generated above and ask the model to explain it.
• If you are using the same PREAMBLE from before, be careful of how you are instructing the model.
• E.g. if we use the following example, the model may complain that it is a code assistant in Python but it
still provides an explanation.

SELECT students.StudentId, students.StudentName


FROM students
INNER JOIN departments
ON students.DepartmentId = departments.DepartmentId
WHERE departments.DepartmentName = 'Computer Science’;
Explain the above SQL statement.
More Tools for Developers
• Understanding existing code: AI2SQL can automatically write complex SQL queries,
and SEEK can search and pull code from numerous data sources.
• Code Generation: Writing boilerplate code, repetitive functions, or tests will be massively
accelerated by contextual tools.
• Github Copilot is popular with >1M paying users, improving developer productivity by 10–50%.
• UI Design: Galileo AI translates natural language design prompts into design suggestions.
• Documentation: Mintlify can automatically document code within seconds in a standardized
way.
• Bug detection & vulnerability management: Metabob lets you find and fix code faster than
human software developers are able to do today.
Thank You

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy