Skip to content

karlospn/building-a-csharp-enhancing-app-with-openai-and-streamlit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Building a C# enhancing app using OpenAI GPT-4 and Streamlit

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.

Content

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.

app-screenshot

External dependencies

The app uses the following technologies:

Prerequisites

Before trying to execute the app, you must have the following services running:

  • A running Azure OpenAI instance with a gpt-4 or gpt-4-32k deployed on it.

How to run the app

Before trying to run the app, read the Prerequisites section.

Run the app locally

Set the required environment variables

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.

Restore dependencies

pip install -r requirements.txt

Run the app

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

Run the app using Docker

This repository has a Dockerfile in case you prefer to execute the app on a container.

Build the image

docker build -t csharp-enhancing-app .

Run it

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

Result

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.

app-upload

  • When you run the "Add XML comments" functionality, the result is displayed in another code block.

app-xml-comments-result

  • Here's the explanation given by GPT-4 when you run the "Explain code" functionality.

app-explain-code

  • Here's an example of the suggestions given by GPT-4 when you run the "Suggest code improvements" functionality.

app-suggestions

  • When you run the "Generate unit tests" functionality, the result is displayed in a code block.

app-unit-test

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

app-no-unit-test

About

Building an app capable of enhancing a given csharp file from your local computer using Azure OpenAI GPT-4 and Streamlit

Topics

Resources

Stars

Watchers

Forks