GithubHelp home page GithubHelp logo

obrocki / commectmycode Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 384 KB

Console app that explains and comments existing source code using Semantic Kernel and Azure OpenAI Services

C# 73.65% Bicep 26.35%

commectmycode's Introduction

CommectMyCode

Console app that explains and comments existing source code using Semantic Kernel and Azure OpenAI Services

Prerequisites

Configuring the sample

The sample can be configured by using the command line with .NET Secret Manager to avoid the risk of leaking secrets into the repository, branches and pull requests. This sample has been tested with the following models:

Service Model type Model
Azure OpenAI Chat Completion gpt-3.5-turbo
Azure OpenAI Embedding text-embedding-ada

Using .NET Secret Manager

Configure an Azure OpenAI

Supporting Azure infrastructure can be deployed manually in Azure Portal or using Azure Developer CLI:

azd auth login

azd provision

azd down

Created infrastructure resources are used for Azure OpenAI Services in code:

cd CommentMyCode

dotnet user-secrets set "AzureOpenAI:Endpoint" ">>>YOUR ENDPOINT<<<.openai.azure.com/"
dotnet user-secrets set "AzureOpenAI:ModelType" "gpt-35-turbo"
dotnet user-secrets set "AzureOpenAI:ChatCompletionModel" "gpt-3.5-turbo"
dotnet user-secrets set "AzureOpenAI:EmbeddingModel" "text-embedding-ada"
dotnet user-secrets set "AzureOpenAI:ApiKey" ">>>YOUR API KEY<<<"

Key concepts

This example uses Semantic Kernel, text memory with a logger, a volatile memory store, and Azure OpenAI Text Embedding Generation Service. It imports a native function from the CodeFileFinderPlugin that finds all C# code files in the directory. Main interaction is through a chat with the AI, where the AI's role as an expert in explaining programming languages and providing valuable comments to the code.

To comment and explain source code other than C# update the CodeFileFinderPlugin line 16 with extension of the files you want to comment.

Running the sample

After configuring the sample, to build and run the console application just hit F5.

To build and run the console application from the terminal use the following commands:

dotnet build
dotnet run

When the application runs, it will prompt the user to enter a directory path. The application will then search for all C# code files in the directory and subdirectories.

Warning

There is cost associated with using Azure OpenAI Services. Please review the pricing and limits before running this sample.

For each code file, it prompts the user to either skip (s) the file or comment (c) and explain the file.

Specify directory with code to comment:
C:\Code\Demo\dotnet-podcast

Sample output shwos console output with code comments on the left and input source file on the right

Console output with code comments on the left and input file on the right.

Sources

commectmycode's People

Contributors

obrocki avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.