{"id":26304445,"url":"https://github.com/luismisanve/geminipostsql_api","last_synced_at":"2025-10-17T21:55:02.670Z","repository":{"id":278786853,"uuid":"874742327","full_name":"LuisMiSanVe/GeminiPostSQL_API","owner":"LuisMiSanVe","description":"REST API that uses AI to translate natural language to PostgreSQL queries","archived":false,"fork":false,"pushed_at":"2025-04-08T17:23:47.000Z","size":2316,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-07T22:35:25.851Z","etag":null,"topics":["ai","asp-net-core","database","gemini","gemini-api","newtonsoft-json","npgsql","pgadmin4","postgresql","rest-api","restsharp","visual-studio"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/LuisMiSanVe.png","metadata":{"files":{"readme":"README.es.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,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-10-18T11:35:01.000Z","updated_at":"2025-04-08T17:23:50.000Z","dependencies_parsed_at":"2025-02-21T17:50:15.085Z","dependency_job_id":"f1b3600c-4c52-4cb5-9eb4-f8a1ff18e80d","html_url":"https://github.com/LuisMiSanVe/GeminiPostSQL_API","commit_stats":null,"previous_names":["luismisanve/aipostgreassistant_api","luismisanve/geminipostsql_api"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LuisMiSanVe%2FGeminiPostSQL_API","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LuisMiSanVe%2FGeminiPostSQL_API/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LuisMiSanVe%2FGeminiPostSQL_API/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LuisMiSanVe%2FGeminiPostSQL_API/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LuisMiSanVe","download_url":"https://codeload.github.com/LuisMiSanVe/GeminiPostSQL_API/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253800711,"owners_count":21966528,"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","asp-net-core","database","gemini","gemini-api","newtonsoft-json","npgsql","pgadmin4","postgresql","rest-api","restsharp","visual-studio"],"created_at":"2025-03-15T08:16:33.097Z","updated_at":"2025-10-17T21:55:02.661Z","avatar_url":"https://github.com/LuisMiSanVe.png","language":"C#","readme":"\u003e [Ver en inglés/See in english](https://github.com/LuisMiSanVe/GeminiPostSQL_API/tree/main)\n\n\u003cimg src=\"https://github.com/LuisMiSanVe/LuisMiSanVe/blob/main/Resources/GeminiPostSQL/GeminiPostSQLAPI_banner.png\" style=\"width: 100%; height: auto;\" alt=\"GeminiPostSQL Banner\"\u003e\n\n# \u003cimg src=\"https://github.com/LuisMiSanVe/GeminiPostSQL_API/blob/main/AIAPI/wwwroot/Img/favicon.png\" width=\"40\" alt=\"GeminiPostSQL Logo\"\u003e GeminiPostSQL API | REST API para PostgreSQL Asistida por IA\n[![image](https://img.shields.io/badge/C%23-239120?style=for-the-badge\u0026logo=csharp\u0026logoColor=white)](https://dotnet.microsoft.com/en-us/languages/csharp)\n[![image](https://img.shields.io/badge/.NET-5C2D91?style=for-the-badge\u0026logo=.net\u0026logoColor=white)](https://dotnet.microsoft.com/en-us/learn/dotnet/what-is-dotnet)\n[![image](https://img.shields.io/badge/postgres-%23316192.svg?style=for-the-badge\u0026logo=postgresql\u0026logoColor=white)](https://www.postgresql.org/)\n[![image](https://img.shields.io/badge/json-5E5C5C?style=for-the-badge\u0026logo=json\u0026logoColor=white)](https://www.newtonsoft.com/json)\n[![image](https://img.shields.io/badge/Swagger-85EA2D?style=for-the-badge\u0026logo=Swagger\u0026logoColor=white)](https://github.com/domaindrivendev/Swashbuckle.AspNetCore)\n[![image](https://img.shields.io/badge/Google%20Gemini-8E75B2?style=for-the-badge\u0026logo=googlegemini\u0026logoColor=white)](https://aistudio.google.com/app/apikey)\n[![image](https://img.shields.io/badge/Visual_Studio-5C2D91?style=for-the-badge\u0026logo=visual%20studio\u0026logoColor=white)](https://visualstudio.microsoft.com/)\n\n\u003e[!NOTE]\n\u003e Dale un vistazo a las otras versiones del programa:\n\u003e- [WinForms](https://github.com/LuisMiSanVe/GeminiPostSQL/tree/main)\n\u003e- [ChatBot](https://github.com/LuisMiSanVe/GeminiPostSQL_ChatBot/tree/main)\n\u003e- [NuGet](https://github.com/LuisMiSanVe/GeminiPostSQL_NuGet/tree/main)\n\u003e- [Android](https://github.com/LuisMiSanVe/GeminiLiteSQL/tree/main)\n\nEsta REST API usa la IA de Google 'Gemini 2.0 Flash' para generar consultas a bases de datos PostgreSQL.  \nLa IA convierte lenguaje natural a consultas SQL usando dos métodos diferentes, cada uno con sus ventajas y desventajas.\n\n## 📋 Prerequisitos\n\nPara que la API funcione, necesiatarás un servidor PostgreSQL y una clave de la API de Gemini.\n\n\u003e [!NOTE]  \n\u003e Yo usaré pgAdmin para montar el servidor PostgreSQL.\n\n## 🛠️ Instalación\n\nSi no lo tienes, descarga [pgAdmin 4 desde su página ofical](https://www.pgadmin.org/download/).  \nAhora, crea el servidor y monta la base de datos con algunas tablas y valores.\n\nDespués, obten tu clave de la API de Gemini yendo aqui: [Google AI Studio](https://aistudio.google.com/app/apikey). Asegurate de tener tu sesión de Google abierta, y encontes dale al botón que dice 'Crear clave de API' y sigue los pasos para crear tu proyecto de Google Cloud y conseguir tu clave de API. **Guardala en algún sitio seguro**.  \nGoogle permite el uso gratuito de esta API sin añadir ninguna forma de pago, pero con algunas limitaciones.\n\nEn Google AI Studio, puedes monitorizar el uso de la IA haciendo clic en 'Ver datos de uso' en la columna de 'Plan' en la tabla con todos tus proyectos. Recomiendo monitorizarla desde la pestaña de 'Cuota y límites del sistema' y ordenando por 'Porcentaje de uso actual', ya que es donde más información obtienes.\n\nYa tienes todo para hacer funcionar la REST API.  \nSimpemente reemplaza los valores por defecto del string 'database' en [AIAPI/Controllers/AIController.cs](https://github.com/LuisMiSanVe/AI_DB_REST_API/blob/main/AIAPI/Controllers/AIController.cs) con la información de tu base de datos, y poner la clave de API en el string 'apiKey'.\n\n## 📖 Sobre la REST API\n\nLa API tiene un Controlador con dos endpoints:\n\n- **[AIDatabaseMapping](https://gist.github.com/LuisMiSanVe/2da8e2d932a06ef408b3ee8468d0d820)**  \n  Mapea la base de datos entera en un JSON la cual Gemini analiza para devolver la tabla que correspondría la solicitud enviada.  \n  Debido a la naturaleza del método, bases de datos muy grandes puedes sobrepasar los recursos del sistema. Para prevenir esto, hay parametros para limitar que tantas filas aprende Gemini.  \n  Toda la información recogida está generada directamente por la IA, por lo que es posible que haya información inventada. Para verificarlo, hay un parametro que hace que la IA genere la SQL necesaria para que devuelva esa tabla, la cual puedes correr en tu servidor PostgreSQL para comprobarla vericidad de los datos.\n\n- **AIDatabaseSQL**  \n  Este método mapea la estructura de la base de datos en un JSON que Gemini analiza para crear una consulta SQL, la cual es ejecutada por el servidor PostgreSQL directamente.  \n  Ya que este método no mapea los valores de la base de datos el uso de tokens es menor, y los datos que devuelve son mas fiables pues es el mismo Servidor el que los devuelve. Sin embargo, no evita completamente los errores que cometa la IA. A veces, la consulta SQL fallará debido a que la IA se inventa columnas que no existen, en ese caso el endpoint devolverá la consulta generada para que identifiques el fallo.\n\n## 💻 Tecnologías usadas\n\n- Lenguaje de programación: [C#](https://dotnet.microsoft.com/es-es/languages/csharp)\n- Framework: [ASP.NET Core](https://dotnet.microsoft.com/es-es/apps/aspnet) (creado con el Framework [.Net](https://dotnet.microsoft.com/es-es/learn/dotnet/what-is-dotnet) 8.0)\n- Paquetes NuGet:\n  - [Swashbuckle.AspNetCore](https://github.com/domaindrivendev/Swashbuckle.AspNetCore) (6.4.0)\n  - [Swashbuckle.AspNetCore.Annotations](https://github.com/domaindrivendev/Swashbuckle.AspNetCore?tab=readme-ov-file#swashbuckleaspnetcoreannotations) (6.6.2)\n  - [Npgsql](https://www.npgsql.org/) (8.0.5)\n  - [RestSharp](https://restsharp.dev/) (112.1.0)\n  - [Newtonsoft.Json](https://www.newtonsoft.com/json) (13.0.3)\n- Otras herramientas:\n  - [PostgreSQL](https://www.postgresql.org/) (16.3)\n  - [pgAdmin 4](https://www.pgadmin.org/) (8.9)\n  - Gemini API Key (2.0 Flash)\n- IDE Recomendado: [Visual Studio](https://visualstudio.microsoft.com/) 2022\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fluismisanve%2Fgeminipostsql_api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fluismisanve%2Fgeminipostsql_api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fluismisanve%2Fgeminipostsql_api/lists"}