{"id":28245592,"url":"https://github.com/apilogicserver/genai_demo","last_synced_at":"2026-07-08T04:31:06.447Z","repository":{"id":259574671,"uuid":"878245755","full_name":"ApiLogicServer/genai_demo","owner":"ApiLogicServer","description":null,"archived":false,"fork":false,"pushed_at":"2025-09-30T02:19:01.000Z","size":6011,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-26T05:52:54.831Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ApiLogicServer.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"security/__init__.py","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-10-25T03:11:01.000Z","updated_at":"2025-09-30T02:18:59.000Z","dependencies_parsed_at":"2024-10-26T16:57:41.352Z","dependency_job_id":"4e454fb9-dbfa-4385-8ffd-7c24eef90755","html_url":"https://github.com/ApiLogicServer/genai_demo","commit_stats":null,"previous_names":["apilogicserver/genai_demo"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ApiLogicServer/genai_demo","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ApiLogicServer%2Fgenai_demo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ApiLogicServer%2Fgenai_demo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ApiLogicServer%2Fgenai_demo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ApiLogicServer%2Fgenai_demo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ApiLogicServer","download_url":"https://codeload.github.com/ApiLogicServer/genai_demo/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ApiLogicServer%2Fgenai_demo/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":35252324,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-07-08T02:00:06.796Z","response_time":61,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2025-05-19T09:12:52.373Z","updated_at":"2026-07-08T04:31:06.431Z","avatar_url":"https://github.com/ApiLogicServer.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n\u0026nbsp;\n**Key Takeways - TL;DR - GenAI leverages AI and Microservice Automation for project creation**\n\u0026nbsp;\n\n    To create projects (either the WebGenAI web app, or API Logic Server CLI), the system performs the following:\n    \n    1. Uses ChatGPT APIs to submit prompts and obtain data model class responses\n    \n    2. It then uses these to create a database and project\n\n    This document presumes you have already created the project, and are using VSCode or GitHub to explore it.  It illustrates how to run and customize the genai_demo project.\n\n    \u003e Note: if you have *not* already created the project, see the Appendix (\"Creating GenAI Demo\").\n    \n\n\u0026nbsp;\n\n## Setup Codespaces\n\nCodespaces enables you to run in the cloud: VSCode via your Browser, courtesy GitHub.  You can use codespaces on your GenAI project:\n\n1. Open your project on GitHub\n\n![API Logic Server Intro](https://github.com/ApiLogicServer/Docs/blob/main/docs/images/sample-ai/genai/open-github.png?raw=true)\n\n2. Open it in Codespaces (takes a minute or 2):\n\n![API Logic Server Intro](https://github.com/ApiLogicServer/Docs/blob/main/docs/images/sample-ai/genai/start-codespaces.png?raw=true)\n\n\u003e You will now see your project - running in VSCode, _in the Browser._  But that's just what you _see..._\n\n\u003e Behind the scenes, Codespaces has requisitioned a cloud machine, and loaded your project - with a _complete development environment_ - Python, your dependencies, git, etc.  \n\n\u003e You are attached to this machine in your Browser, running VSCode.\n\n\u003e :trophy: Pretty remarkable.\n\n__3. Start the Server and open the App in the Browser__\n\n* Use the pre-defined Launch Configuration\n\n![API Logic Server Intro](https://github.com/ApiLogicServer/Docs/blob/main/docs/images/git-codespaces/start-codespaces.png?raw=true)\n\n\nWe think you'll find Codespaces pretty amazing - check it out!\n\n\u0026nbsp;\n\n## How was the project created?\n\nYour prompt (whether provided in a file to the CLI, or the WebGenAI website) \nis sent to ChatGPT to create a schema.  This schema is then processed by als to create \nand run a project that provides a JSON:API, a Web App, a database, and\nbusiness logic that runs in the API.\n\nFor more information, Appendix (\"how does it work\").  For more information on the architecture,\nplease see: https://www.genai-logic.com/architecture.\n\nLet's have a look at the created project.\n\n\u0026nbsp;\n\n## 1. API/App Automation\n\nAPI/App Automation means the created project is executable.  To run:\n\n1. Press **F5** to run\n2. Start your Browser (use the codespaces button, or locally: http://localhost:5656/) to view:\n    * App Automation: the Admin App, and\n    * API Automation: JSON:API, with Swagger\n3. Stop the server when you are done (red box on VSCode Debugger panel)\n\n![Microservice Automation](https://github.com/ApiLogicServer/Docs/blob/main/docs/images/sample-ai/copilot/created-microservice.png?raw=true)\n\nIt's a modern, 3-tiered architecture, using standard Python libraries.  For more information, see slide 2: https://www.genai-logic.com/architecture.\n \n\u0026nbsp;\n\n## 2. Customize: Rules and Python\n\nThe development environment is also standard: your IDE, standard languages, standard libraries, standard source control, etc.  You customize API Logic Project in two ways, both performed in your IDE:\n\n* **Logic Automation:** declare spreadsheet-like rules to address multi-table derivations and constraints.  These constitute nearly half of a typical database-oriented system.   Declarative rules are 40X more concise than procedural code.\n\n* **Standard Python:** e.g, to create a new custom endpoint, and send a Kafka message\n\n\u003e Note: projects are model-driven, resulting in a very small amount of code.  This simplifies debugging and customizing your system.\n\nExplore rules and Python customization below.\n\n\u0026nbsp;\n\n### Logic Automation\n\nThe project creation provided natural language logic.  This is translated into ***rules*** (vs. lots of code) expressed in Python.  To explore rules created from your prompt:\n\n1. Open `logic/declare_logic.py`\n\n2. View the Python-based rules created by GenAI.  Observe you\n\n\u003e You can add more rules, with Python (code completion), and/or GenAI.\n\n![Add Rules](https://github.com/ApiLogicServer/Docs/blob/main/docs/images/sample-ai/genai/genai-rules.png?raw=true)\n\n\u0026nbsp;\n\n### Standard Python, Libraries\n\nTo save time, issue the follow command to simulate changes you might make in your IDE, e.g., to create a new custom endpoint, and send a Kafka message.  \n\n```bash title=\"Simulate IDE Customization\"\nals add-cust\n```\n\n![Customize](https://github.com/ApiLogicServer/Docs/blob/main/docs/images/sample-ai/copilot/genai_cust.png?raw=true)\n\nThe customization is this code in the diagram above:\n\n```python title=\"Send Kafka Message\"\n\n    # Sends the order to Kafka topic 'order_shipping' if the date shipped is not None.\n    Rule.after_flush_row_event(on_class=Order, calling=kafka_producer.send_row_to_kafka, if_condition=lambda row: row.date_shipped is not None, with_args={\"topic\": \"order_shipping\"})\n```\n\n### Try it out\n\nSet a breakpoint in the code above, and:\n\n1. Start the Server (**F5**)\n2. Use the Admin app to alter the first Customer, first Order, first Item, and change the quantity to 11111\n    * Observe the error message, from the rules.\n3. To test the new endpoint, use Swagger (**ServicesEndPoint \u003e POST /ServicesEndPoint/OrderB2B)**.\n    * Observe the swagger response - \"Sending Order to Shipping sends:\".\n\nNote: Kafka is not activated in this example.  To explore a running Tutorial for application integration with running Kafka, see: https://apilogicserver.github.io/Docs/Sample-Integration.\n\n\u0026nbsp;\n\n## 3. Deployment: Containers, Cloud\n\nOne of the best ways to de-risk projects is to verify the sponsors are in sync with what is happening.  This is best addressed with *working software*, which often occurs late in project development.  Surprises here can result in considerable rework... and frustrations.\n\nGenAI Automation produces *working software, now*, so you can find misunderstandings before investing serious effort (\"fail fast\").  To expose the working software, it's often desirable to deploy to the cloud so business users can run it.\n\nAPI Logic Server creates the `devops` directory, which scripts to containerize your project, and deploy it to Azure.  For more information, see DevOps Automation: https://apilogicserver.github.io/Docs/DevOps-Automation/.\n\n\u0026nbsp;\n\n## Appendices\n\n\u0026nbsp;\n\n### GenAI Restart Procedures\n\nAI results are not consistent, so the created model file may need corrections.  You can find it at `system/genai/temp/model.py`.  You can correct the model file, and then run:\n\n```bash\nals create --project-name=genai_demo --from-model=system/genai/temp/model.py --db-url=sqlite\n```\n\nOr, correct the chatgpt response, and\n\n```bash\nals genai --using=genai_demo.prompt --gen-using-file=system/genai/temp/chatgpt_retry.txt\n```\n\n\u0026nbsp;\n\nCLI Notes (effective as of release 11.00.22):\n\n* Projects are created in the your current working folder (typically the manager root directory).  They were formerly created adjacent to the `gen-using-file`.\n\n* The project name is the last node of `--using`.  This is a required argument, since it denotes the project directory name.\n\nWe have seen failures such as:\n\n* duplicate definition of `DECIMAL` (we hand-fix the response to fix this)\n* unclosed parentheses\n* data type errors in test data creation\n* wrong engine import: from logic_bank import Engine, constraint\n* bad test data creation: with Engine() as engine...\n* Bad load code (no session)\n* missing datetime import\n* relationship property errors (\"mapper has no property...\")\n\n\u0026nbsp;\n\n#### Diagnosis Tips\n\nThe system saves files used for creation: \n\n![Customize](https://github.com/ApiLogicServer/Docs/blob/main/docs/images/sample-ai/copilot/diagnostic_info.png?raw=true)\n\nNote there are multiple diagostic directories.  recall GenAI results are not always predictable, so we make 3 attempts to get a successful result.  This is often enough, but examining the failures can be useful.\n\nA good technique is to:\n\n1. **Open the response file in the Manager**, and\n2. Use your IDE to run the file \n\nIt's usage create the sqlite database, but running it in this mode can provide more insight into causes.\n\nIf you are using Web/GenAI (see: https://apilogicserver.github.io/Docs/WebGenAI/), project files are always under /projects/gen_$ID.\n\n\u0026nbsp;\n\n### Creating `genai_demo`\n\n#### Using WebGenAI\n\n![Creation from WebGenAI](https://github.com/ApiLogicServer/Docs/blob/main/docs/images/sample-ai/genai/genai-prompt.png?raw=true)\n\nView the process in this video: https://www.youtube.com/watch?v=7I33Fa9Ulos \n\n\u0026nbsp;\n\n#### Using the ALS CLI\n\nView: https://www.youtube.com/watch?v=LSh7mqGiT0k\u0026t=5s.\n\nTo create a microservice, identify an existing database, or provide a natural language \"prompt\" description.  \n\nYou can explore genai_demo using the Manager https://apilogicserver.github.io/Docs/Manager/.  Optionally, you can sign-up for ChatGPT API and Copilot, or simulate the process as described below.\n\n1. If you have signed up for ChatGPT API and Copilot, this command will create and open a project called `genai_demo` from `system/genai/examples/genai_demo/genai_demo.prompt`:\n\n```bash\nals genai --using=system/genai/examples/genai_demo/genai_demo.prompt\n```\n\n\n2. ***Or,*** if you have not signed up, you can simulate the process using a pre-installed response file:\n\n```bash\nals genai --using=genai_demo.prompt --gen-using-file=system/genai/temp/chatgpt_retry.txt\n```\n\nHere is the `system/genai/examples/genai_demo/genai_demo.prompt` file:\n\n\n\u0026nbsp;\n**Key Takeways - TL;DR - GenAI Prompt**\n\u0026nbsp;\n\n    Create a system with customers, orders, items and products.\n\n    Include a notes field for orders.\n\n    Use LogicBank to enforce business logic.\n\n    Use case: Check Credit\n        1. The Customer's balance is less than the credit limit\n        2. The Customer's balance is the sum of the Order amount_total where date_shipped is null\n        3. The Order's amount_total is the sum of the Item amount\n        4. The Item amount is the quantity * unit_price\n        5. The Item unit_price is copied from the Product unit_price\n\n    Ensure each customer has a unique name.\n\n    Ensure each Item quantity is not null.\n\n    Ensure each order has a valid customer_id that exists in the Customer table.\n\n\u0026nbsp;\n\n### How does it work\n\nWhen you use the WebGenAI website, it captures your prompt, and submits to the als system\nusing its provided CLI (`als genai').  `genai` processing is shown below (internal steps denoted in grey):\n\n1. You create your.prompt file, and invoke `als genai --using=your.prompt`.  genai then creates your database and project as follows:\n\n    a. Submits your prompt to the `ChatGPT API`\n\n    b. Writes the response to file (`system/genai/temp/response.json`), so you can correct and retry if anything goes wrong\n\n    c. Extracts `system/genai/temp/create_db_models.py` from the response\n\n    d. Invokes `als create-from-model`, which creates the database and your project\n\n2. Your created project is opened in your IDE, ready to execute and customize.\n\n![Microservice Automation](https://github.com/ApiLogicServer/Docs/blob/main/docs/images/sample-ai/copilot/genai.png?raw=true)\n\n\u0026nbsp;\n\n### GenAI Using Postgresql\n\nThe above examples use *sqlite,* since it requires no install.  The GenAI process works for other database, such as Postgresql.\n\nYou can test this as follows:\n\n1. Use our docker image: https://apilogicserver.github.io/Docs/Database-Docker/\n2. And:\n\n```bash\nals create --project-name=genai_demo_pg.prompt --db-url=postgresql://postgres:p@localhost/genai_demo\n```\n\nProvisos:\n\n* You have to create the database first\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapilogicserver%2Fgenai_demo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fapilogicserver%2Fgenai_demo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapilogicserver%2Fgenai_demo/lists"}