This repository contains an application designed to enhance a provided C# file from your local computer.
To achieve these functionalities, we will leverage the capabilities of the Azure OpenAI GPT-4 model and Streamlit (for the user interface).
Keep in mind that it is a simple app that I put together in just a couple of hours, I'm sure that the prompts that we're sending to OpenAI GPT-4 can be further improved.
This app has the following capabilities when working with a csharp file:
- It can add or enhance existing XML comments.
- It can offer detailed code explanations.
- It provides valuable suggestions for code improvements.
- It can create Unit Tests that uses xUnit and Moq.
OpenAI GPT-4 is an incredibly valuable tool, but it's important not to blindly rely on its results. Before using any output generated by this application in a real-world scenario, review it throughly. Ensure that the generated XML comments are well-defined, check if the unit tests are actually valuable or not, and critically evaluate whether the suggestions it provides for your C# code actually make sense or not.
The app uses the following technologies:
Before trying to execute the app, you must have the following services running:
- A running
Azure OpenAI
instance with agpt-4
orgpt-4-32k
deployed on it.
Before trying to run the app, read the Prerequisites section.
The repository has a .env
file that contains the environment variables that the app requires to run successfully:
AZURE_OPENAI_APIKEY=<azure-openai-apikey>
AZURE_OPENAI_BASE_URI=<azure-openai-url>
AZURE_OPENAI_GPT4_MODEL_NAME=<azure-openai-gpt4-deployment-name>
Change the values accordingly.
pip install -r requirements.txt
When you install Streamlit
, a command-line (CLI) tool gets installed as well. The purpose of this tool is to run Streamlit
apps.
To execute the app, just run the following command:
streamlit run app.py
This repository has a
Dockerfile
in case you prefer to execute the app on a container.
docker build -t csharp-enhancing-app .
docker run -p 5050:5050 \
-e AZURE_OPENAI_APIKEY="<azure-openai-apikey>" \
-e AZURE_OPENAI_BASE_URI="<azure-openai-url>" \
-e AZURE_OPENAI_GPT4_MODEL_NAME="<azure-openai-gpt4-deployment-name>" \
csharp-enhancing-app
This is what you'll see once you start interacting with app.
- When you upload a csharp file, the file source code can be viewed in a code block.
- When you run the "Add XML comments" functionality, the result is displayed in another code block.
- Here's the explanation given by GPT-4 when you run the "Explain code" functionality.
- Here's an example of the suggestions given by GPT-4 when you run the "Suggest code improvements" functionality.
- When you run the "Generate unit tests" functionality, the result is displayed in a code block.
- If you try to generate unit tests from a file which makes no sense (e.g.
Program.cs
), the response will be that no tests are available.