{"id":13560287,"url":"https://github.com/anthonypuppo/sk-nl2ef-plugin","last_synced_at":"2025-04-03T15:31:56.733Z","repository":{"id":183629799,"uuid":"670456402","full_name":"anthonypuppo/sk-nl2ef-plugin","owner":"anthonypuppo","description":"A ChatGPT plugin built with Semantic Kernel that queries a database via natural language. Winner of Microsoft's first Semantic Kernel hackathon in the \"Most Useful for the Enterprise\" category.","archived":false,"fork":false,"pushed_at":"2023-09-13T02:05:13.000Z","size":1281,"stargazers_count":48,"open_issues_count":0,"forks_count":11,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-11-04T11:38:54.584Z","etag":null,"topics":["ai","artificial-intelligence","chatgpt","entity-framework","llm","netcore","openai","openai-plugin","semantic-kernel"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/anthonypuppo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2023-07-25T05:17:39.000Z","updated_at":"2024-11-01T22:29:02.000Z","dependencies_parsed_at":null,"dependency_job_id":"c8410e5d-7b63-4c0f-b6c6-2ce032a1e1cf","html_url":"https://github.com/anthonypuppo/sk-nl2ef-plugin","commit_stats":null,"previous_names":["anthonypuppo/sk-nl2ef-plugin"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anthonypuppo%2Fsk-nl2ef-plugin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anthonypuppo%2Fsk-nl2ef-plugin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anthonypuppo%2Fsk-nl2ef-plugin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anthonypuppo%2Fsk-nl2ef-plugin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/anthonypuppo","download_url":"https://codeload.github.com/anthonypuppo/sk-nl2ef-plugin/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247028049,"owners_count":20871641,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ai","artificial-intelligence","chatgpt","entity-framework","llm","netcore","openai","openai-plugin","semantic-kernel"],"created_at":"2024-08-01T13:00:41.111Z","updated_at":"2025-04-03T15:31:51.712Z","avatar_url":"https://github.com/anthonypuppo.png","language":"C#","funding_links":[],"categories":["Plugins","Browser-extensions","chatgpt","ai"],"sub_categories":[],"readme":"# NL2EF\n\n#### Plugin which translates a question into SQL, fetches relevant data from the database, and formulates a response based on the retrieved data\n\n#### ⭐ Winner of Microsoft's first Semantic Kernel hackathon in the \"Most Useful for the Enterprise\" category.\n\n## Semantic Kernel Plugin Hackathon Entry\n\nThis project is my entry to the Semantic Kernel Plugin Hackathon. It's designed to be a drop-in plugin service that can expose an existing database to be queried via natural language. It accomplishes this by leveraging the power of Entity Framework Core and OpenAI's embedding/GPT models to generate and construct SQL queries that retrieve relevant information for RAG based responses.\n\nThe demo connects to a modified version of the SQLite movies database available [here](https://www.kaggle.com/datasets/luizpaulodeoliveira/imdb-project-sql).\n\nVia Chat Copilot:\n\n![Screenshot 2023-07-25 at 1 15 38 AM](/screenshots/chat.png)\n\nVia Swagger:\n\n![Screenshot 2023-07-25 at 8 24 43 AM](/screenshots/swagger.png)\n\n## Built With\n\n- [Semantic Kernel](https://github.com/microsoft/semantic-kernel)\n- .NET 7 Minimal Web APIs\n- Visual Studio Code (C# and C# Dev Kit Extensions)\n\n## How It Works\n\n1. **Database Creation Script Generation**: Use Entity Framework Core to generate the database creation script.\n2. **Embedding Creation**: Create embeddings for each part of the database creation script.\n3. **User Input Processing**: Take a user's input and get the most relevant parts of the database creation script that will help build a SQL query.\n4. **SQL Query Construction**: Build the SQL query using a GPT model.\n5. **Query Execution**: Run the query and attempt to retry and have the model fix its query if it fails.\n6. **Response Formatting**: Format the response data as a CSV which the model can easily parse.\n7. **Answer Generation**: Answer the user's question using the retrieved data for grounding (RAG).\n\n## Future Enhancements\n\n- Code cleanup\n- Modifying the prompts to produce better results\n- Moving hardcoded options to be environment configurable\n\n## Pitfalls Before Moving to Production\n\n- Ensure the user connecting to the database has the appropriate permissions (or lack thereof) to prevent SQL injection or users viewing data they shouldn't.\n- Seed the kernel database schema memories as part of a preprocessing pipeline instead of every run.\n- Be aware of responses overloading the model token window.\n\n## Getting Started\n\nTo get a local copy up and running follow the below steps.\n\n### Prerequisites\n\n- .NET 7\n- Visual Studio Code\n- C# and C# Dev Kit Extensions\n\n### Installation\n\n1. Clone the repo\n   ```sh\n   git clone https://github.com/anthonypuppo/sk-nl2ef-plugin.git\n   ```\n2. Install .NET packages\n   ```sh\n   dotnet restore\n   ```\n3. Open `appsettings.json`\n   - Update the `SemanticKernel:AIService` configuration section:\n     - Update `Type` to the AI service you will be using (i.e., `AzureOpenAI` or `OpenAI`).\n     - If your are using Azure OpenAI, add/update `Endpoint` to your Azure OpenAI resource Endpoint address.\n       \u003e If you are using OpenAI, this property will be ignored.\n     - Set your Azure OpenAI or OpenAI key by opening a terminal in the project directory and using `dotnet user-secrets`\n       ```bash\n       dotnet user-secrets set \"SemanticKernel:AIService:Key\" \"MY_AZUREOPENAI_OR_OPENAI_KEY\"\n       ```\n4. Run the project\n   ```sh\n   dotnet run\n   ```\n\n## Usage\n\nConfigure the DB context to expose the relevant parts of the database to the model. The service will automatically seed the database creation script embeddings at startup.\n\n## Plugin Manifest\n\nWhen running locally the plugin will be exposed at https://localhost:7012/.well-known/ai-plugin.json. CORS defaults to allowing ChatGPT as well as https://localhost:7012.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanthonypuppo%2Fsk-nl2ef-plugin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fanthonypuppo%2Fsk-nl2ef-plugin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanthonypuppo%2Fsk-nl2ef-plugin/lists"}