ApiLogicServer 14.5.3__py3-none-any.whl → 14.5.14__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- api_logic_server_cli/api_logic_server.py +4 -122
- api_logic_server_cli/api_logic_server_info.yaml +3 -3
- api_logic_server_cli/create_from_model/__pycache__/api_logic_server_utils.cpython-312.pyc +0 -0
- api_logic_server_cli/create_from_model/__pycache__/dbml.cpython-312.pyc +0 -0
- api_logic_server_cli/create_from_model/api_logic_server_utils.py +29 -10
- api_logic_server_cli/create_from_model/dbml.py +16 -9
- api_logic_server_cli/database/basic_demo.sqlite +0 -0
- api_logic_server_cli/genai/genai.py +4 -0
- api_logic_server_cli/genai/genai_svcs.py +10 -2
- api_logic_server_cli/manager.py +3 -1
- api_logic_server_cli/prototypes/base/.vscode/launch.json +40 -0
- api_logic_server_cli/prototypes/base/api/api_discovery/mcp_discovery.py +58 -0
- api_logic_server_cli/prototypes/base/database/system/SAFRSBaseX.py +68 -2
- api_logic_server_cli/prototypes/base/database/system/SAFRSBaseX.pyZ +73 -0
- api_logic_server_cli/prototypes/{basic_demo/customizations/integration → base/integration/mcp}/.DS_Store +0 -0
- api_logic_server_cli/prototypes/base/integration/mcp/README_mcp.md +15 -0
- api_logic_server_cli/prototypes/base/integration/mcp/mcp_client_executor.py +296 -0
- api_logic_server_cli/prototypes/base/integration/mcp/mcp_schema.txt +47 -0
- api_logic_server_cli/prototypes/base/integration/mcp/mcp_server_discovery.json +9 -0
- api_logic_server_cli/prototypes/base/integration/mcp/test_notes.txt +37 -0
- api_logic_server_cli/prototypes/basic_demo/README.md +251 -91
- api_logic_server_cli/prototypes/basic_demo/customizations/api/api_discovery/mcp_discovery.py +1 -44
- api_logic_server_cli/prototypes/basic_demo/customizations/database/db.sqlite +0 -0
- api_logic_server_cli/prototypes/basic_demo/customizations/database/models.py +27 -12
- api_logic_server_cli/prototypes/basic_demo/customizations/database/system/SAFRSBaseX.py +5 -2
- api_logic_server_cli/prototypes/basic_demo/customizations/integration/mcp/Zmcp_client_executor.py +294 -0
- api_logic_server_cli/prototypes/basic_demo/customizations/integration/mcp/mcp_tool_context.json +25 -0
- api_logic_server_cli/prototypes/basic_demo/customizations/integration/mcp/test_notes.txt +37 -0
- api_logic_server_cli/prototypes/basic_demo/customizations/logic/declare_logic.py +1 -20
- api_logic_server_cli/prototypes/basic_demo/customizations/logic/logic_discovery/email_request.py +47 -0
- api_logic_server_cli/prototypes/basic_demo/customizations/logic/logic_discovery/mcp_client_executor_request.py +320 -0
- api_logic_server_cli/prototypes/basic_demo/customizations/logic/logic_discovery/simple_constraints.py +25 -0
- api_logic_server_cli/prototypes/basic_demo/customizations/ui/admin/admin.yaml +39 -32
- api_logic_server_cli/prototypes/basic_demo/iteration/database/db.sqlite +0 -0
- api_logic_server_cli/prototypes/basic_demo/iteration/ui/admin/admin.yaml +39 -44
- api_logic_server_cli/prototypes/manager/.vscode/launch.json +21 -0
- api_logic_server_cli/prototypes/manager/{README.md → READMEz.md} +4 -4
- api_logic_server_cli/prototypes/manager/REAMDE.md +1057 -0
- api_logic_server_cli/prototypes/manager/system/genai/mcp_learning/mcp.prompt +27 -0
- api_logic_server_cli/prototypes/manager/system/install-ApiLogicServer-dev/install-ApiLogicServer-dev.sh +2 -1
- {apilogicserver-14.5.3.dist-info → apilogicserver-14.5.14.dist-info}/METADATA +1 -1
- {apilogicserver-14.5.3.dist-info → apilogicserver-14.5.14.dist-info}/RECORD +46 -42
- {apilogicserver-14.5.3.dist-info → apilogicserver-14.5.14.dist-info}/WHEEL +1 -1
- api_logic_server_cli/prototypes/basic_demo/customizations/integration/mcp/mcp_client_executor.py +0 -350
- api_logic_server_cli/prototypes/basic_demo/customizations/integration/openai_function/3_executor_test_agent.py +0 -52
- api_logic_server_cli/prototypes/basic_demo/customizations/integration/openai_function/README_functon.md +0 -201
- api_logic_server_cli/prototypes/basic_demo/customizations/integration/openai_function/ai_plugin.json +0 -17
- api_logic_server_cli/prototypes/basic_demo/customizations/integration/openai_function/nw-swagger_3.json +0 -1731
- api_logic_server_cli/prototypes/basic_demo/customizations/integration/openai_function/snippets.txt +0 -5
- api_logic_server_cli/prototypes/basic_demo/customizations/integration/openai_function/swagger_3 genai_demo_with_get.json +0 -1731
- api_logic_server_cli/prototypes/basic_demo/customizations/integration/openai_function/swagger_3.json +0 -1782
- api_logic_server_cli/prototypes/basic_demo/customizations/integration/openai_function/swagger_3_genai_demo.json +0 -264
- api_logic_server_cli/prototypes/basic_demo/customizations/integration/openai_function/swagger_3_genai_demo_with_update.json +0 -1782
- api_logic_server_cli/prototypes/genai_demo/logic/logic_discovery/auto_discovery.py +0 -52
- {apilogicserver-14.5.3.dist-info → apilogicserver-14.5.14.dist-info}/entry_points.txt +0 -0
- {apilogicserver-14.5.3.dist-info → apilogicserver-14.5.14.dist-info}/licenses/LICENSE +0 -0
- {apilogicserver-14.5.3.dist-info → apilogicserver-14.5.14.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,1057 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Welcome
|
|
3
|
+
Description: Instant mcp-enabled microservices, standard projects, declarative business logic
|
|
4
|
+
version info: 2.0 (05/24/2025)
|
|
5
|
+
---
|
|
6
|
+
<style>
|
|
7
|
+
.md-typeset h1,
|
|
8
|
+
.md-content__button {
|
|
9
|
+
display: none;
|
|
10
|
+
}
|
|
11
|
+
</style>
|
|
12
|
+
|
|
13
|
+
## Welcome to GenAI-Logic
|
|
14
|
+
|
|
15
|
+
1. ***Instant mcp-enabled microservices*** (APIs and Admin Apps), from a database or **GenAI prompt** -- one command and you are ready for MCP, Vibe and Business User Collaboration.
|
|
16
|
+
|
|
17
|
+
2. ***Customize*** with **Declarative Rules** and Python in your IDE, standard container deployment
|
|
18
|
+
|
|
19
|
+
You are in the [API Logic Server Manager](Manager.md). This is a good place to manage projects, create notes and resources, etc.
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
## Explore Creating Projects
|
|
24
|
+
|
|
25
|
+
**Evaluation Guide:** click on the disclosure buttons, below.
|
|
26
|
+
</br>
|
|
27
|
+
|
|
28
|
+
<details markdown>
|
|
29
|
+
|
|
30
|
+
<summary> 1. Product Tour - Start here</summary>
|
|
31
|
+
|
|
32
|
+
<br>We'll illustrate [API Logic Server](https://www.genai-logic.com/product/key-features){:target="_blank" rel="noopener"} basic GenAI-Logic operation: creating projects from new or existing databases, adding logic and security, and customizing your project using your IDE and Python.
|
|
33
|
+
|
|
34
|
+
The entire process takes 20 minutes; usage notes:
|
|
35
|
+
|
|
36
|
+
* Important: look for **readme files** in created projects.
|
|
37
|
+
* You may find it more convenient to view this [in your Browser](Sample-Basic-Tour.md).
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
## 1. Automation: Project Creation
|
|
42
|
+
|
|
43
|
+
API Logic Server can create projects from existing databases, or use GenAI to create projects with new databases. Let's see how.
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
### From Existing Database
|
|
47
|
+
|
|
48
|
+
Create the project - use the CLI (**Terminal > New Terminal**), :
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
$ ApiLogicServer create --project_name=basic_demo --db_url=basic_demo
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
> Note: the `db_url` value is [an abbreviation](https://apilogicserver.github.io/Docs/Data-Model-Examples/){:target="_blank" rel="noopener"} for a test database provided as part of the installation. You would normally supply a SQLAlchemy URI to your existing database.
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
<details markdown>
|
|
58
|
+
|
|
59
|
+
<summary> The database is Customer, Orders, Items and Product</summary>
|
|
60
|
+
|
|
61
|
+

|
|
62
|
+
|
|
63
|
+
</details>
|
|
64
|
+
<br>
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
### GenAI: New Database
|
|
68
|
+
|
|
69
|
+
You can create a project *and a new database* from a prompt using GenAI, either by:
|
|
70
|
+
|
|
71
|
+
* [WebGenAI - in the Browser](WebGenAI.md){:target="_blank" rel="noopener"}, or
|
|
72
|
+
* [GenAI - docker](WebGenAI-install.md){:target="_blank" rel="noopener"}, or
|
|
73
|
+
* [GenAI CLI](WebGenAI-CLI.md){:target="_blank" rel="noopener"}
|
|
74
|
+
|
|
75
|
+
Here we use the GenAI CLI:
|
|
76
|
+
|
|
77
|
+
1. If you have signed up (see *Get an OpenAI Key*, below), this will create and open a project called `genai_demo` from `genai_demo.prompt` (available in left Explorer pane):
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
als genai --using=system/genai/examples/genai_demo/genai_demo.prompt --project-name=genai_demo
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
2. ***Or,*** you can simulate the process (no signup) using:
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
|
|
87
|
+
als genai --repaired-response=system/genai/examples/genai_demo/genai_demo.response_example --project-name=genai_demo
|
|
88
|
+
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
For background on how it works, [click here](Sample-Genai.md#how-does-it-work){:target="_blank" rel="noopener"}.
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
## 2. Working Software Now
|
|
96
|
+
|
|
97
|
+
### Open in your IDE and Run
|
|
98
|
+
|
|
99
|
+
You can open with VSCode, and run it as follows:
|
|
100
|
+
|
|
101
|
+
1. **Create Virtual Environment:** automated in most cases; see the Appendix (Procedures / Detail Procedures) for details.
|
|
102
|
+
|
|
103
|
+
2. **Start the Server:** F5 (also described in the Appendix).
|
|
104
|
+
|
|
105
|
+
3. **Start the Admin App:** either use the links provided in the IDE console, or click [http://localhost:5656/](http://localhost:5656/). The screen shown below should appear in your Browser.
|
|
106
|
+
|
|
107
|
+
The sections below explore the system that has been created (which would be similar for your own database).
|
|
108
|
+
<br><br>
|
|
109
|
+
|
|
110
|
+
### API with Swagger
|
|
111
|
+
|
|
112
|
+
The system creates an API with end points for each table, with filtering, sorting, pagination, optimistic locking and related data access -- **[self-serve](https://apilogicserver.github.io/Docs/API-Self-Serve/), ready for custom app dev.**
|
|
113
|
+
|
|
114
|
+
<details markdown>
|
|
115
|
+
|
|
116
|
+
<summary>See the Swagger </summary>
|
|
117
|
+
|
|
118
|
+

|
|
119
|
+
</details>
|
|
120
|
+
<br>
|
|
121
|
+
|
|
122
|
+
### Admin App
|
|
123
|
+
|
|
124
|
+
It also creates an Admin App: multi-page, multi-table -- ready for **[business user agile collaboration](https://apilogicserver.github.io/Docs/Tech-AI/),** and back office data maintenance. This complements custom UIs created with the API.
|
|
125
|
+
|
|
126
|
+
You can click Customer Alice, and see their Orders, and Items.
|
|
127
|
+
|
|
128
|
+
<details markdown>
|
|
129
|
+
|
|
130
|
+
<summary>See the Admin App </summary>
|
|
131
|
+

|
|
132
|
+
</details>
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
### MCP, Vibe, Collaboration
|
|
137
|
+
|
|
138
|
+
In little more than a minute, you've used either
|
|
139
|
+
|
|
140
|
+
* **GenAI** to create a database and project using Natural Language, or
|
|
141
|
+
* 1 CLI command to create a project from an existing database
|
|
142
|
+
|
|
143
|
+
The project is standard Python, which you can customize in a standard IDE.
|
|
144
|
+
|
|
145
|
+
This means you are ready for:
|
|
146
|
+
|
|
147
|
+
* **Vibe:**
|
|
148
|
+
|
|
149
|
+
* Instead of creating data mockups, use GenAI to create real data.
|
|
150
|
+
* Use you favorite Vibe tools with your running API
|
|
151
|
+
* And, you'll have projects that are architecurally correct: shared logic enforced in the server,
|
|
152
|
+
available for both User Interfaces and services.
|
|
153
|
+
|
|
154
|
+
* **MCP:** your project is MCP-ready: `python integration/mcp/mcp_client_executor.py`.
|
|
155
|
+
We'll explore more interesting examples below.
|
|
156
|
+
|
|
157
|
+
* **Collaboration to Get Requirements Right:** Business Users can use GenAI to create systems, and the Admin app to verify their business idea. And iterate.
|
|
158
|
+
|
|
159
|
+
> But automated direct access to the database is a terrible architecture. A key feature of GenAI-Logic is logic automation using declarative, spreadsheet-like business rules. Let's now explore those.
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
## 3. Declare Logic And Security
|
|
165
|
+
|
|
166
|
+
While API/UI automation is a great start, it's critical to enforce logic and security. You do this in your IDE. Here's how.
|
|
167
|
+
|
|
168
|
+
The following `add_customizations` process simulates:
|
|
169
|
+
|
|
170
|
+
* Adding security to your project, and
|
|
171
|
+
* Using your IDE to declare logic and security in `logic/declare_logic.sh` and `security/declare_security.py`.
|
|
172
|
+
|
|
173
|
+
> Declared security and logic are shown in the screenshots below.<br>It's quite short - 5 rules, 7 security settings.
|
|
174
|
+
|
|
175
|
+
To add customizations, in a terminal window for your project:
|
|
176
|
+
|
|
177
|
+
**1. Stop the Server** (Red Stop button, or Shift-F5 -- see Appendix)
|
|
178
|
+
|
|
179
|
+
**2. Add Customizations**
|
|
180
|
+
|
|
181
|
+
```bash
|
|
182
|
+
als add-cust
|
|
183
|
+
als add-auth --db_url=auth
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
### Security: Role Based Access
|
|
188
|
+
|
|
189
|
+
The `add_customizations` process above has simulated using your IDE to declare security in `logic/declare_logic.sh`.
|
|
190
|
+
|
|
191
|
+
To see security in action:
|
|
192
|
+
|
|
193
|
+
**1. Start the Server** F5
|
|
194
|
+
|
|
195
|
+
**2. Start the Admin App:** [http://localhost:5656/](http://localhost:5656/)
|
|
196
|
+
|
|
197
|
+
**3. Login** as `s1`, password `p`
|
|
198
|
+
|
|
199
|
+
**4. Click Customers**
|
|
200
|
+
|
|
201
|
+
<br>
|
|
202
|
+
Observe:
|
|
203
|
+
|
|
204
|
+
**1. Login now required**
|
|
205
|
+
|
|
206
|
+
**2. Role-Based Filtering**
|
|
207
|
+
|
|
208
|
+
Observe you now see fewer customers, since user `s1` has role `sales`. This role has a declared filter, as shown in the screenshot below.
|
|
209
|
+
|
|
210
|
+
**3. Transparent Logging**
|
|
211
|
+
|
|
212
|
+
<details markdown>
|
|
213
|
+
|
|
214
|
+
<summary>See Security Declarations </summary>
|
|
215
|
+
|
|
216
|
+
<br>The screenshot below illustrates security declaration and operation:
|
|
217
|
+
|
|
218
|
+
* The declarative Grants in the upper code panel, and
|
|
219
|
+
|
|
220
|
+
* The logging in the lower panel, to assist in debugging by showing which Grants (`+ Grant:`) are applied:
|
|
221
|
+
|
|
222
|
+

|
|
223
|
+
|
|
224
|
+
</details>
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
### Logic: Derivations, Constraints
|
|
229
|
+
|
|
230
|
+
Logic (multi-table derivations and constraints) is a significant portion of a system, typically nearly half. API Logic server provides **spreadsheet-like rules** that dramatically simplify and accelerate logic development.
|
|
231
|
+
|
|
232
|
+
Rules are declared in Python, simplified with IDE code completion. The screen below shows the 5 rules for **Check Credit Logic.**
|
|
233
|
+
|
|
234
|
+
The `add_customizations` process above has simulated the process of using your IDE to declare logic in `logic/declare_logic.sh`.
|
|
235
|
+
|
|
236
|
+
To see logic in action:
|
|
237
|
+
|
|
238
|
+
**1. In the admin app, Logout (upper right), and login as admin, p**
|
|
239
|
+
|
|
240
|
+
**2. Use the Admin App to add an Order and Item for `Customer Alice`** (see Appendix)
|
|
241
|
+
|
|
242
|
+
Observe the rules firing in the console log - see Logic In Action, below.
|
|
243
|
+
|
|
244
|
+
<br>
|
|
245
|
+
> 💡 Logic: Multi-table Derivations and Constraint Declarative Rules.<br>  Declarative Rules are 40X More Concise than procedural code.<br>  For more information, [click here](Logic-Why.md){:target="_blank" rel="noopener"}.
|
|
246
|
+
|
|
247
|
+
<br>
|
|
248
|
+
|
|
249
|
+
<details markdown>
|
|
250
|
+
|
|
251
|
+
<summary>See Logic In Action </summary>
|
|
252
|
+
|
|
253
|
+
<br>
|
|
254
|
+
|
|
255
|
+
**a. Chaining**
|
|
256
|
+
|
|
257
|
+
The screenshot below shows our logic declarations, and the logging for inserting an `Item`. Each line represents a rule firing, and shows the complete state of the row.
|
|
258
|
+
|
|
259
|
+
Note that it's a `Multi-Table Transaction`, as indicated by the indentation. This is because - like a spreadsheet - **rules automatically chain, *including across tables.***
|
|
260
|
+
|
|
261
|
+

|
|
262
|
+
|
|
263
|
+
**b. 40X More Concise**
|
|
264
|
+
|
|
265
|
+
The 5 spreadsheet-like rules represent the same logic as 200 lines of code, [shown here](https://github.com/valhuber/LogicBank/wiki/by-code). That's a remarkable 40X decrease in the backend half of the system.
|
|
266
|
+
<br><br>
|
|
267
|
+
|
|
268
|
+
**c. Automatic Re-use**
|
|
269
|
+
|
|
270
|
+
The logic above, perhaps conceived for Place order, applies automatically to all transactions: deleting an order, changing items, moving an order to a new customer, etc. This reduces code, and promotes quality (no missed corner cases).
|
|
271
|
+
<br><br>
|
|
272
|
+
|
|
273
|
+
**d. Automatic Optimizations**
|
|
274
|
+
|
|
275
|
+
SQL overhead is minimized by pruning, and by elimination of expensive aggregate queries. These can result in orders of magnitude impact.
|
|
276
|
+
<br><br>
|
|
277
|
+
|
|
278
|
+
**e. Transparent**
|
|
279
|
+
|
|
280
|
+
Rules are an executable design. Note they map exactly to our natural language design (shown in comments) - readable by business users.
|
|
281
|
+
|
|
282
|
+
Optionally, you can use the Behave TDD approach to define tests, and the Rules Report will show the rules that execute for each test. For more information, [click here](https://apilogicserver.github.io/Docs/Behave-Logic-Report/).
|
|
283
|
+
|
|
284
|
+
</details>
|
|
285
|
+
|
|
286
|
+
|
|
287
|
+
|
|
288
|
+
## 4. Iterate with Rules and Python
|
|
289
|
+
|
|
290
|
+
Not only are spreadsheet-like rules 40X more concise, they meaningfully simplify maintenance. Let's take an example:
|
|
291
|
+
|
|
292
|
+
>> Give a 10% discount for carbon-neutral products for 10 items or more.
|
|
293
|
+
<br>
|
|
294
|
+
|
|
295
|
+
The following `add-cust` process simulates an iteration:
|
|
296
|
+
|
|
297
|
+
* acquires a new database with `Product.CarbonNeutral`
|
|
298
|
+
|
|
299
|
+
* issues the `ApiLogicServer rebuild-from-database` command that rebuilds your project (the database models, the api), while preserving the customizations we made above.
|
|
300
|
+
|
|
301
|
+
* acquires a revised `ui/admin/admin.yaml` that shows this new column in the admin app
|
|
302
|
+
|
|
303
|
+
* acquires this revised logic - in `logic/declare_logic.py`, we replaced the 2 lines for the `models.Item.Amount` formula with this (next screenshot shows revised logic executing with breakpoint):
|
|
304
|
+
|
|
305
|
+
```python
|
|
306
|
+
def derive_amount(row: models.Item, old_row: models.Item, logic_row: LogicRow):
|
|
307
|
+
amount = row.Quantity * row.UnitPrice
|
|
308
|
+
if row.Product.CarbonNeutral and row.Quantity >= 10:
|
|
309
|
+
amount = amount * Decimal(0.9) # breakpoint here
|
|
310
|
+
return amount
|
|
311
|
+
|
|
312
|
+
Rule.formula(derive=models.Item.Amount, calling=derive_amount)
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
|
|
316
|
+
|
|
317
|
+
To add this iteration, repeat the process above - in a terminal window for your project:
|
|
318
|
+
|
|
319
|
+
**1. Stop the Server** (Red Stop button, or Shift-F5 -- see Appendix)
|
|
320
|
+
|
|
321
|
+
**2. Add Iteration**
|
|
322
|
+
|
|
323
|
+
```bash
|
|
324
|
+
als add-cust
|
|
325
|
+
als rebuild-from-database --db_url=sqlite:///database/db.sqlite
|
|
326
|
+
```
|
|
327
|
+
|
|
328
|
+
**3. Set the breakpoint as shown in the screenshot below**
|
|
329
|
+
|
|
330
|
+
**4. Test: Start the Server, login as Admin**
|
|
331
|
+
|
|
332
|
+
**5. Use the Admin App to update your Order by adding 12 `Green` Items**
|
|
333
|
+
|
|
334
|
+
At the breakpoint, observe you can use standard debugger services to debug your logic (examine `Item` attributes, step, etc).
|
|
335
|
+
|
|
336
|
+

|
|
337
|
+
|
|
338
|
+
|
|
339
|
+
|
|
340
|
+
This simple example illustrates some significant aspects of iteration, described in the sub-sections below.
|
|
341
|
+
|
|
342
|
+
<br>
|
|
343
|
+
> 💡 Iteration: Automatic Invocation/Ordering, Extensible, Rebuild Preserves Customizations
|
|
344
|
+
<br>
|
|
345
|
+
|
|
346
|
+
**a. Dependency Automation**
|
|
347
|
+
|
|
348
|
+
Along with perhaps documentation, one of the tasks programmers most loathe is maintenance. That's because it's not about writing code, but it's mainly archaeology - deciphering code someone else wrote, just so you can add 4 or 5 lines that will hopefully be called and function correctly.
|
|
349
|
+
|
|
350
|
+
Rules change that, since they **self-order their execution** (and pruning) based on system-discovered dependencies. So, to alter logic, you just "drop a new rule in the bucket", and the system will ensure it's called in the proper order, and re-used over all the Use Cases to which it applies. Maintenance is **faster, and higher quality.**
|
|
351
|
+
<br><br>
|
|
352
|
+
|
|
353
|
+
**b. Extensibile with Python**
|
|
354
|
+
|
|
355
|
+
In this case, we needed to do some if/else testing, and it was convenient to add a pinch of Python. Using "Python as a 4GL" is remarkably simple, even if you are new to Python.
|
|
356
|
+
|
|
357
|
+
Of course, you have the full object-oriented power of Python and its many libraries, so there are *no automation penalty* restrictions.
|
|
358
|
+
<br>
|
|
359
|
+
|
|
360
|
+
**c. Debugging: IDE, Logging**
|
|
361
|
+
|
|
362
|
+
The screenshot above illustrates that debugging logic is what you'd expect: use your IDE's debugger. This "standard-based" approach applies to other development activities, such as source code management, and container-based deployment.
|
|
363
|
+
<br><br>
|
|
364
|
+
|
|
365
|
+
**d. Customizations Retained**
|
|
366
|
+
|
|
367
|
+
Note we rebuilt the project from our altered database, illustrating we can **iterate, while *preserving customizations.***
|
|
368
|
+
|
|
369
|
+
|
|
370
|
+
|
|
371
|
+
### API Customization: Standard
|
|
372
|
+
|
|
373
|
+
Of course, we all know that all businesses the world over depend on the `hello world` app. This is provided in `api/customize_api`. Observe that it's:
|
|
374
|
+
|
|
375
|
+
* standard Python
|
|
376
|
+
|
|
377
|
+
* using Flask
|
|
378
|
+
|
|
379
|
+
* and, for database access, SQLAlchemy. Note all updates from custom APIs also enforce your logic.
|
|
380
|
+
|
|
381
|
+
|
|
382
|
+
|
|
383
|
+
### Messaging With Kafka
|
|
384
|
+
|
|
385
|
+
Along with APIs, messaging is another technology commonly employed for application integration. See the screenshot below; for more information, see [Sample Integration](Sample-Integration.md#produce-ordershipping-message){:target="_blank" rel="noopener"}.
|
|
386
|
+
|
|
387
|
+

|
|
388
|
+
|
|
389
|
+
|
|
390
|
+
## 5. Deploy Containers: No Fees
|
|
391
|
+
|
|
392
|
+
API Logic Server also creates scripts for deployment. While these are ***not required at this demo,*** this means you can enable collaboration with Business Users:
|
|
393
|
+
|
|
394
|
+
1. Create a container from your project -- see `devops/docker-image/build_image.sh`
|
|
395
|
+
2. Upload to Docker Hub, and
|
|
396
|
+
3. Deploy for agile collaboration.
|
|
397
|
+
|
|
398
|
+
|
|
399
|
+
|
|
400
|
+
</details>
|
|
401
|
+
<br>
|
|
402
|
+
|
|
403
|
+
<details markdown>
|
|
404
|
+
|
|
405
|
+
<summary> 2. New Database - using GenAI Microservice Automation (Experiment with AI - Signup optional)</summary>
|
|
406
|
+
|
|
407
|
+
<br>You can do this with or without signup:
|
|
408
|
+
|
|
409
|
+
1. If you have signed up (see *Get an OpenAI Key*, below), this will create a new database and project called `genai_demo`, and open the project. It's created using `genai_demo.prompt`, visible in left Explorer pane:
|
|
410
|
+
|
|
411
|
+
```bash
|
|
412
|
+
als genai --using=system/genai/examples/genai_demo/genai_demo.prompt --project-name=genai_demo
|
|
413
|
+
```
|
|
414
|
+
|
|
415
|
+
|
|
416
|
+
2. ***Or,*** you can simulate the process (no signup) using:
|
|
417
|
+
|
|
418
|
+
|
|
419
|
+
```bash
|
|
420
|
+
als genai --repaired-response=system/genai/examples/genai_demo/genai_demo.response_example --project-name=genai_demo
|
|
421
|
+
```
|
|
422
|
+
|
|
423
|
+
Verify it's operating properly:
|
|
424
|
+
|
|
425
|
+
1. Run Configurations are provided to start the server
|
|
426
|
+
2. Verify the logic by navigating to a Customer with an unshipped order, and altering one of the items to have a very large quantity
|
|
427
|
+
3. Observe the constraint operating on the rollup of order amount_totals.
|
|
428
|
+
* View the logic in `logic/declare_logic.py`
|
|
429
|
+
* Put a breakpoint on the `as_condition`. Observe the console log to see rule execution for this multi-table transaction.
|
|
430
|
+
|
|
431
|
+
</br>
|
|
432
|
+
|
|
433
|
+
<details markdown>
|
|
434
|
+
|
|
435
|
+
<summary> What Just Happened? Next Steps...</summary>
|
|
436
|
+
|
|
437
|
+
<br>`genai` processing is shown below (internal steps denoted in grey):
|
|
438
|
+
|
|
439
|
+
1. You create your.prompt file, and invoke `als genai --using=your.prompt`. genai then creates your project as follows:
|
|
440
|
+
|
|
441
|
+
a. Submits your prompt to the `ChatGPT API`
|
|
442
|
+
|
|
443
|
+
b. Writes the response to file, so you can correct and retry if anything goes wrong
|
|
444
|
+
|
|
445
|
+
c. Extracts model.py from the response
|
|
446
|
+
|
|
447
|
+
d. Invokes `als create-from-model`, which creates the database and your project
|
|
448
|
+
|
|
449
|
+
2. Your created project is opened in your IDE, ready to execute and customize.
|
|
450
|
+
|
|
451
|
+
a. Review `Tutorial.md`, Explore Customizations.
|
|
452
|
+
|
|
453
|
+

|
|
454
|
+
|
|
455
|
+
</details>
|
|
456
|
+
</br>
|
|
457
|
+
|
|
458
|
+
<details markdown>
|
|
459
|
+
|
|
460
|
+
<summary> You can iterate the logic and data model</summary>
|
|
461
|
+
|
|
462
|
+
<br>The approach for an iteration is to create a new project from an existing one:
|
|
463
|
+
|
|
464
|
+
1. add another prompt to an existing projects `docs` directory, specifying your changes
|
|
465
|
+
2. use `als genai`, specifying
|
|
466
|
+
* `--using` existing projects `docs` directory, and
|
|
467
|
+
* `--project-name` as the output project
|
|
468
|
+
|
|
469
|
+
**Logic iterations** are particuarly useful. For example, here we take the basic check-credit logic, and add:
|
|
470
|
+
|
|
471
|
+
> Provide a 10% discount when buying more than 10 carbon neutral products.<br><br>The Item carbon neutral is copied from the Product carbon neutral
|
|
472
|
+
|
|
473
|
+
Explore [genai_demo_iteration_discount](system/genai/examples/genai_demo/genai_demo_iteration_discount). It's an iteration of basic_demo (see system/genai/examples/genai_demo/genai_demo_iteration_discount/002_create_db_models.prompt). This will add carbon_neutral to the data model, and update the logic to provide the discount:
|
|
474
|
+
|
|
475
|
+
```bash title='Iterate Business Logic'
|
|
476
|
+
# Iterate with data model and logic
|
|
477
|
+
als genai --project-name='genai_demo_with_discount' --using=system/genai/examples/genai_demo/genai_demo_iteration_discount
|
|
478
|
+
# open Docs/db.dbml
|
|
479
|
+
```
|
|
480
|
+
|
|
481
|
+
<br>
|
|
482
|
+
|
|
483
|
+
You can perform **model iterations:** add new columns/tables, while keeping the prior model intact. First, we create a project with no logic, perhaps just to see the screens (this step is optional, provided just to illustrate that iterations create new projects from existing ones):
|
|
484
|
+
|
|
485
|
+
```bash title='Iterate Without Logic'
|
|
486
|
+
# Step 1 - create without logic
|
|
487
|
+
als genai --project-name='genai_demo_no_logic' --using=system/genai/examples/genai_demo/genai_demo_no_logic.prompt
|
|
488
|
+
# open Docs/db.dbml
|
|
489
|
+
```
|
|
490
|
+
|
|
491
|
+
Then, we would create another prompt in the docs directory with our model changes. We've already created these for you in `system/genai/examples/genai_demo/genai_demo_iteration` - we use that to alter the data model (see `system/genai/examples/genai_demo/genai_demo_iteration/004_iteration_renames_logic.prompt`):
|
|
492
|
+
|
|
493
|
+
```bash title='Iterate With Logic'
|
|
494
|
+
# Iterate with data model and logic
|
|
495
|
+
als genai --project-name='genai_demo_with_logic' --using=system/genai/examples/genai_demo/genai_demo_iteration
|
|
496
|
+
# open Docs/db.dbml
|
|
497
|
+
```
|
|
498
|
+
|
|
499
|
+
Explore [genai_demo_iteration](system/genai/examples/genai_demo/genai_demo_iteration) - observe the `--using` is a *directory* of prompts. These include the prompts from the first example, plus an *iteration prompt* (`004_iteration_renames_logic.prompt`) to rename tables and add logic.
|
|
500
|
+
|
|
501
|
+
|
|
502
|
+
</details>
|
|
503
|
+
</br>
|
|
504
|
+
|
|
505
|
+
<details markdown>
|
|
506
|
+
|
|
507
|
+
<summary> You can declare informal logic</summary>
|
|
508
|
+
|
|
509
|
+
<br>You can declare rules using dot notation, or more informally:
|
|
510
|
+
|
|
511
|
+
```bash title="Informal Logic (no dot notation)"
|
|
512
|
+
als genai --using=system/genai/examples/genai_demo/genai_demo_informal.prompt --project-name=genai_demo_informal
|
|
513
|
+
```
|
|
514
|
+
</details>
|
|
515
|
+
</br>
|
|
516
|
+
|
|
517
|
+
|
|
518
|
+
<details markdown>
|
|
519
|
+
|
|
520
|
+
<summary> Multi-Rule Logic</summary>
|
|
521
|
+
|
|
522
|
+
<br>You can add new columns/tables, while keeping the prior model intact:
|
|
523
|
+
|
|
524
|
+
```bash title="Multi-Rule Logic"
|
|
525
|
+
als genai --using=system/genai/examples/emp_depts/emp_dept.prompt
|
|
526
|
+
```
|
|
527
|
+
</details>
|
|
528
|
+
</br>
|
|
529
|
+
|
|
530
|
+
<details markdown>
|
|
531
|
+
|
|
532
|
+
<summary> You can ask AI to suggest logic (great way to learn!)</summary>
|
|
533
|
+
|
|
534
|
+
<br>You can create a project, and ask GenAI for logic suggestions:
|
|
535
|
+
|
|
536
|
+
```bash title='1. Create Project, without Rules'
|
|
537
|
+
# 1. Create Project, without Rules
|
|
538
|
+
als genai --project-name='genai_demo_no_logic' --using=system/genai/examples/genai_demo/genai_demo_no_logic.prompt
|
|
539
|
+
```
|
|
540
|
+
|
|
541
|
+
```bash title="2. Request Rule Suggestions"
|
|
542
|
+
# 2. Request Rule Suggestions
|
|
543
|
+
cd genai_demo_no_logic
|
|
544
|
+
als genai-logic --suggest
|
|
545
|
+
```
|
|
546
|
+
|
|
547
|
+
You can review the [resultant logic suggestions](genai_demo_no_logic/docs/logic_suggestions) in the `genai_demo_no_logic` project:
|
|
548
|
+
|
|
549
|
+
* See and edit: `docs/logic_suggestions/002_logic_suggestions.prompt` (used in step 3, below)
|
|
550
|
+
* This corresponds to the Logic Editor - Logic View in the WebGenAI web app
|
|
551
|
+
|
|
552
|
+
```bash title="3. See the rules for the logic"
|
|
553
|
+
# 3. See the rule code for the logic
|
|
554
|
+
als genai-logic --suggest --logic='*'
|
|
555
|
+
```
|
|
556
|
+
|
|
557
|
+
Important notes about suggestions and generated code:
|
|
558
|
+
* `--suggest --logic='*'` is intended to enable you to identify logic that does not translate into proper code
|
|
559
|
+
* The example above was pretty good, but sometimes the results are downright silly:
|
|
560
|
+
* Just run suggest again, or
|
|
561
|
+
* Repair `docs/logic_suggestions/002_logic_suggestions.prompt`
|
|
562
|
+
|
|
563
|
+
Also...
|
|
564
|
+
* It is not advised to paste the code into `logic/declare_logic.py`
|
|
565
|
+
* The suggested logic may result in new data model attributes
|
|
566
|
+
* These are created automatically by running `als genai` (next step)
|
|
567
|
+
|
|
568
|
+
The [logic suggestions directory](genai_demo_no_logic/docs/logic_suggestions) now contains the prompts to create a new project with the suggested logic.
|
|
569
|
+
When you are ready to proceed:
|
|
570
|
+
1. Execute the following to create a *new project* (iteration), with suggested logic:
|
|
571
|
+
|
|
572
|
+
```bash title="4. Create a new project with the Rule Suggestions"
|
|
573
|
+
# 4. Create a new project with the Rule Suggestions
|
|
574
|
+
cd .. # important - back to manager root dir
|
|
575
|
+
als genai --project-name='genai_demo_with_logic' --using=genai_demo_no_logic/docs/logic_suggestions
|
|
576
|
+
```
|
|
577
|
+
|
|
578
|
+
Observe:
|
|
579
|
+
1. The created project has the rule suggestions in `logic/declare_logic.py`
|
|
580
|
+
2. A revised Data Model in `database/models.py` that includes attributes introduced by the logic suggestions
|
|
581
|
+
3. Revised test database, initialized to reflect the derivations in the suggested logic
|
|
582
|
+
|
|
583
|
+
Internal Note: this sequence available in the run configs (s1/s4).
|
|
584
|
+
|
|
585
|
+
</details>
|
|
586
|
+
|
|
587
|
+
</br>
|
|
588
|
+
|
|
589
|
+
<details markdown>
|
|
590
|
+
|
|
591
|
+
<summary>Fixup - update data model with new attributes from rules</summary>
|
|
592
|
+
|
|
593
|
+
<br>Fixes project issues by updating the Data Model and Test Data:
|
|
594
|
+
when adding rules, such as using suggestions, you may introduce new attributes.
|
|
595
|
+
If these are missing, you will see exceptions when you start your project.
|
|
596
|
+
|
|
597
|
+
The `genai-utils --fixup` fixes such project issues by updating the Data Model and Test Data:
|
|
598
|
+
|
|
599
|
+
1. Collects the latest model, rules, and test data from the project.
|
|
600
|
+
2. Calls ChatGPT (or similar) to resolve missing columns or data in the project.
|
|
601
|
+
3. Saves the fixup request/response under a 'fixup' folder.
|
|
602
|
+
4. You then use this to create a new project
|
|
603
|
+
|
|
604
|
+
***Setup***
|
|
605
|
+
|
|
606
|
+
After starting the [Manager](https://apilogicserver.github.io/Docs/Manager):
|
|
607
|
+
|
|
608
|
+
```bash title="0. Create Project Requiring Fixup"
|
|
609
|
+
# 0. Create a project requiring fixup
|
|
610
|
+
als genai --repaired-response=system/genai/examples/genai_demo/genai_demo_fixup_required.json --project-name=genai_demo_fixup_required
|
|
611
|
+
```
|
|
612
|
+
|
|
613
|
+
If you run this project, you will observe that it fails with:
|
|
614
|
+
```bash
|
|
615
|
+
Logic Bank Activation Error -- see https://apilogicserver.github.io/Docs/WebGenAI-CLI/#recovery-options
|
|
616
|
+
Invalid Rules: [AttributeError("type object 'Customer' has no attribute 'balance'")]
|
|
617
|
+
Missing Attrs (try als genai-utils --fixup): ['Customer.balance: constraint']
|
|
618
|
+
```
|
|
619
|
+
|
|
620
|
+
|
|
621
|
+
***Fixup***
|
|
622
|
+
|
|
623
|
+
To Fix it:
|
|
624
|
+
```bash title="1. Run FixUp to add missing attributes to the fixup response data model"
|
|
625
|
+
# 1. Run FixUp to add missing attributes to the data model
|
|
626
|
+
cd genai_demo_fixup_required
|
|
627
|
+
als genai-utils --fixup
|
|
628
|
+
```
|
|
629
|
+
|
|
630
|
+
Finally, use the created [fixup files](genai_demo_fixup_required/docs/fixup/) to rebuild the project:
|
|
631
|
+
```bash title="2. Rebuild the project from the fixup response data model"
|
|
632
|
+
# 2. Rebuild the project from the fixup response data model
|
|
633
|
+
cd ../
|
|
634
|
+
als genai --repaired-response=genai_demo_fixup_required/docs/fixup/response_fixup.json --project-name=fixed_project
|
|
635
|
+
```
|
|
636
|
+
|
|
637
|
+
|
|
638
|
+
The created project may still report some attributes as missing.
|
|
639
|
+
(ChatGPT seems to often miss attributes mentioned in sum/count where clauses.) To fix:
|
|
640
|
+
|
|
641
|
+
1. Note the missing attributes(s) from the log
|
|
642
|
+
2. Add them to `docs/003_suggest.prompt`
|
|
643
|
+
3. Rebuild the project: `als genai --project-name='genai_demo_with_logic' --using=genai_demo_no_logic/docs`
|
|
644
|
+
|
|
645
|
+
|
|
646
|
+
Internal Note: this sequence available in the run configs (f1/f2).
|
|
647
|
+
|
|
648
|
+
</details>
|
|
649
|
+
|
|
650
|
+
|
|
651
|
+
</br>
|
|
652
|
+
|
|
653
|
+
<details markdown>
|
|
654
|
+
|
|
655
|
+
<summary>Create from WebGenAI, and import (merge) subsequent changes</summary>
|
|
656
|
+
|
|
657
|
+
<br>You can use [WebGenAI](https://apilogicserver.github.io/Docs/WebGenAI/) to create a project, and export it.
|
|
658
|
+
|
|
659
|
+
You (or colleagues) can make changes to both the WebGenAI project (on the web), and your downloaded project. You can import the WebGenAI project, and the system will merge changes to the data model and rules automatically.
|
|
660
|
+
|
|
661
|
+
This is possible since the logic is declarative, so ordering is automatic. This eliminates the troublesome merge issues so prevalent in procedural code. For more on import, [click here](https://apilogicserver.github.io/Docs/IDE-Import-WebGenAI/).
|
|
662
|
+
|
|
663
|
+
The Manager pre-installs a sample project you can use to explore import:
|
|
664
|
+
|
|
665
|
+
```bash
|
|
666
|
+
cd system/genai/examples/genai_demo/wg_dev_merge/dev_demo_no_logic_fixed
|
|
667
|
+
als genai-utils --import-genai --using=../wg_demo_no_logic_fixed
|
|
668
|
+
```
|
|
669
|
+
Observe:
|
|
670
|
+
1. The [data model](system/genai/examples/genai_demo/wg_dev_merge/dev_demo_no_logic_fixed/database) contains `Customer.balance` and `Product.carbon_neutral`
|
|
671
|
+
2. The test data has been updated to include these attributes, with proper values
|
|
672
|
+
|
|
673
|
+
</details>
|
|
674
|
+
|
|
675
|
+
</br>
|
|
676
|
+
|
|
677
|
+
<details markdown>
|
|
678
|
+
|
|
679
|
+
<summary>Rebuild the test data</summary>
|
|
680
|
+
|
|
681
|
+
<br>Fixes project issues by rebuilding the database to conform to the derivation rules:
|
|
682
|
+
|
|
683
|
+
1. Create genai_demo:
|
|
684
|
+
```
|
|
685
|
+
als genai --using=system/genai/examples/genai_demo/genai_demo.prompt --project-name=genai_demo
|
|
686
|
+
```
|
|
687
|
+
2. Rebuild:
|
|
688
|
+
```
|
|
689
|
+
cd genai_demo
|
|
690
|
+
als genai-utils --rebuild-test-data
|
|
691
|
+
```
|
|
692
|
+
|
|
693
|
+
</details>
|
|
694
|
+
</br>
|
|
695
|
+
|
|
696
|
+
<details markdown>
|
|
697
|
+
|
|
698
|
+
<summary> You can also execute directly, and iterate</summary>
|
|
699
|
+
|
|
700
|
+
<br>You can add new columns/tables, while keeping the prior model intact:
|
|
701
|
+
|
|
702
|
+
```bash title="Iterate"
|
|
703
|
+
# create project without creating a file...
|
|
704
|
+
als genai-create --project-name='customer_orders' --using='customer orders'
|
|
705
|
+
|
|
706
|
+
als genai-iterate --using='add Order Details and Products'
|
|
707
|
+
# open Docs/db.dbml
|
|
708
|
+
```
|
|
709
|
+
|
|
710
|
+
</details>
|
|
711
|
+
</br>
|
|
712
|
+
|
|
713
|
+
<details markdown>
|
|
714
|
+
|
|
715
|
+
<summary> AI somtimes fails - here's how to recover</summary>
|
|
716
|
+
|
|
717
|
+
<br>AI results are not consistent, so the model file may need corrections. You can find it at `system/genai/temp/model.py`. You can correct the model file, and then run:
|
|
718
|
+
|
|
719
|
+
```bash
|
|
720
|
+
als create --project-name=genai_demo --from-model=system/genai/temp/create_db_models.py --db-url=sqlite
|
|
721
|
+
```
|
|
722
|
+
|
|
723
|
+
Or, correct the chatgpt response, and
|
|
724
|
+
|
|
725
|
+
```bash
|
|
726
|
+
als genai --repaired-response=system/genai/examples/genai_demo/genai_demo.response_example --project-name=genai_demo
|
|
727
|
+
```
|
|
728
|
+
|
|
729
|
+
We have seen failures such as:
|
|
730
|
+
|
|
731
|
+
* duplicate definition of `DECIMAL`
|
|
732
|
+
* unclosed parentheses
|
|
733
|
+
* data type errors in test data creation
|
|
734
|
+
* wrong engine import: from logic_bank import Engine, constraint
|
|
735
|
+
* bad test data creation: with Engine() as engine...
|
|
736
|
+
* Bad load code (no session)
|
|
737
|
+
|
|
738
|
+
</details>
|
|
739
|
+
</br>
|
|
740
|
+
|
|
741
|
+
<details markdown>
|
|
742
|
+
|
|
743
|
+
<summary> Postgresql Example </summary>
|
|
744
|
+
|
|
745
|
+
You can test this as follows:
|
|
746
|
+
|
|
747
|
+
1. Use [our docker image](https://apilogicserver.github.io/Docs/Database-Docker/):
|
|
748
|
+
2. And try:
|
|
749
|
+
|
|
750
|
+
```bash
|
|
751
|
+
als genai --using=system/genai/examples/postgres/genai_demo_pg.prompt --db-url=postgresql://postgres:p@localhost/genai_demo
|
|
752
|
+
```
|
|
753
|
+
|
|
754
|
+
Provisos:
|
|
755
|
+
|
|
756
|
+
* You have to create the database first; we are considering automating that: https://stackoverflow.com/questions/76294523/why-cant-create-database-if-not-exists-using-sqlalchemy
|
|
757
|
+
|
|
758
|
+
</details>
|
|
759
|
+
</details>
|
|
760
|
+
</br>
|
|
761
|
+
|
|
762
|
+
<details markdown>
|
|
763
|
+
|
|
764
|
+
<summary> 3. New Database - using Copilot (Signup optional) </summary>
|
|
765
|
+
|
|
766
|
+
<br>You can use Copilot chat (if extension installed; if not, skip to step 3):
|
|
767
|
+
|
|
768
|
+
1. Create a model, eg:
|
|
769
|
+
|
|
770
|
+
<details markdown>
|
|
771
|
+
|
|
772
|
+
<summary> Show Me How to Use Copilot </summary>
|
|
773
|
+
|
|
774
|
+
<br>>Paste this into the Copilot prompt:
|
|
775
|
+
|
|
776
|
+
```
|
|
777
|
+
Use SQLAlchemy to create a sqlite database named sample_ai.sqlite, with customers, orders, items and product
|
|
778
|
+
|
|
779
|
+
Hints: use autonum keys, allow nulls, Decimal types, foreign keys, no check constraints.
|
|
780
|
+
|
|
781
|
+
Include a notes field for orders.
|
|
782
|
+
|
|
783
|
+
Create a few rows of only customer and product data.
|
|
784
|
+
|
|
785
|
+
Enforce the Check Credit requirement (do not generate check constraints):
|
|
786
|
+
|
|
787
|
+
1. Customer.Balance <= CreditLimit
|
|
788
|
+
2. Customer.Balance = Sum(Order.AmountTotal where date shipped is null)
|
|
789
|
+
3. Order.AmountTotal = Sum(Items.Amount)
|
|
790
|
+
4. Items.Amount = Quantity * UnitPrice
|
|
791
|
+
5. Store the Items.UnitPrice as a copy from Product.UnitPrice
|
|
792
|
+
```
|
|
793
|
+
|
|
794
|
+

|
|
795
|
+
</details>
|
|
796
|
+
|
|
797
|
+
<br>
|
|
798
|
+
|
|
799
|
+
2. Paste the copilot response into a new `sample_ai.py` file
|
|
800
|
+
|
|
801
|
+
3. Create your project:
|
|
802
|
+
|
|
803
|
+
```bash
|
|
804
|
+
als create --project-name=sample_ai --from-model=sample_ai.py --db-url=sqlite
|
|
805
|
+
```
|
|
806
|
+
|
|
807
|
+
4. This will create your database, create an API Logic Project from it, and launch your IDE.
|
|
808
|
+
|
|
809
|
+
5. Create business logic
|
|
810
|
+
|
|
811
|
+
* You can create logic with either your IDE (and code completion), or Natural Language
|
|
812
|
+
* To use Natural Language:
|
|
813
|
+
|
|
814
|
+
1. Use the CoPilot chat,
|
|
815
|
+
2. Paste the logic above
|
|
816
|
+
3. Copy it to `logic/declare_logic.py` after `discover_logic()`
|
|
817
|
+
|
|
818
|
+
* Alert: Table and Column Names may require correction to conform to the model
|
|
819
|
+
* Alert: you may to apply [defaulting](https://apilogicserver.github.io/Docs/Logic-Use/#insert-defaulting), and initialize derived attributes in your database
|
|
820
|
+
|
|
821
|
+
</details>
|
|
822
|
+
</br>
|
|
823
|
+
|
|
824
|
+
<details markdown>
|
|
825
|
+
|
|
826
|
+
<summary> 4. New Database - using ChatGPT in the Browser (Signup not required)</summary>
|
|
827
|
+
|
|
828
|
+
<br>A final option for GenAI is to use your Browser with ChatGPT.
|
|
829
|
+
|
|
830
|
+
Please see [this doc](https://apilogicserver.github.io/Docs/Sample-AI-ChatGPT/)
|
|
831
|
+
|
|
832
|
+
</details>
|
|
833
|
+
|
|
834
|
+
<br>
|
|
835
|
+
|
|
836
|
+
<br>
|
|
837
|
+
|
|
838
|
+
## Appendices
|
|
839
|
+
|
|
840
|
+
### Procedures
|
|
841
|
+
|
|
842
|
+
<details markdown>
|
|
843
|
+
|
|
844
|
+
<summary>Quick Basic Demo - Cheat Sheet</summary>
|
|
845
|
+
|
|
846
|
+
<br>This demo creates and customizes a project, starting from a database:
|
|
847
|
+
|
|
848
|
+
```bash title="Quick Basic Demo"
|
|
849
|
+
|
|
850
|
+
# Microservice Automation
|
|
851
|
+
# Admin App, API, Project
|
|
852
|
+
als create --project-name=basic_demo --db-url=basic_demo
|
|
853
|
+
|
|
854
|
+
# Logic and Securityf
|
|
855
|
+
# see logic (logic/declare_logic.py, logic/cocktail-napkin.jpg); add an Order and Item
|
|
856
|
+
# see security (security/declare_security.py); compare customers, s1 vs. admin
|
|
857
|
+
als add-cust
|
|
858
|
+
als add-auth --db_url=auth
|
|
859
|
+
|
|
860
|
+
# Python Extensibility, Kafka Integration, Rebuild Iteration
|
|
861
|
+
# see logic/declare_logic.py (breakpoint for Kafka)
|
|
862
|
+
# Swagger: ServicesEndPoint.OrderB2B
|
|
863
|
+
als add-cust
|
|
864
|
+
als rebuild-from-database --db_url=sqlite:///database/db.sqlite
|
|
865
|
+
```
|
|
866
|
+
|
|
867
|
+
</details>
|
|
868
|
+
<br>
|
|
869
|
+
|
|
870
|
+
<details markdown>
|
|
871
|
+
|
|
872
|
+
<summary>Quick GenAI Demo - Cheat Sheet</summary>
|
|
873
|
+
|
|
874
|
+
<br>This demo creates and customizes a project, starting from a prompt:
|
|
875
|
+
|
|
876
|
+
```bash title="Quick GenAI Demo"
|
|
877
|
+
|
|
878
|
+
# Microservice Automation from GenAI Prompt
|
|
879
|
+
# Admin App, API, Project
|
|
880
|
+
als genai --using=system/genai/examples/genai_demo/genai_demo.prompt
|
|
881
|
+
|
|
882
|
+
# Or, Microservice Automation from Saved Response
|
|
883
|
+
# Admin App, API, Project
|
|
884
|
+
als genai --repaired-response=system/genai/temp/chatgpt_retry.response
|
|
885
|
+
|
|
886
|
+
# Logic and Security
|
|
887
|
+
# - see logic (logic/declare_logic.py, logic/cocktail-napkin.jpg); add an Order and Item
|
|
888
|
+
# - see security (security/declare_security.py); compare customers, s1 vs. admin
|
|
889
|
+
# Python Extensibility, Kafka Integration, Rebuild Iteration
|
|
890
|
+
# - see logic/declare_logic.py (breakpoint for Kafka)
|
|
891
|
+
# - Swagger: ServicesEndPoint.OrderB2B
|
|
892
|
+
als add-cust
|
|
893
|
+
```
|
|
894
|
+
|
|
895
|
+
</details>
|
|
896
|
+
<br>
|
|
897
|
+
|
|
898
|
+
<details markdown>
|
|
899
|
+
|
|
900
|
+
<summary> Detail Procedures</summary>
|
|
901
|
+
|
|
902
|
+
<br>Specific procedures for running the demo are here, so they do not interrupt the conceptual discussion above.
|
|
903
|
+
|
|
904
|
+
You can use either VSCode or Pycharm.
|
|
905
|
+
|
|
906
|
+
|
|
907
|
+
**1. Establish your Virtual Environment**
|
|
908
|
+
|
|
909
|
+
Python employs a virtual environment for project-specific dependencies. Create one as shown below, depending on your IDE.
|
|
910
|
+
|
|
911
|
+
For VSCode:
|
|
912
|
+
|
|
913
|
+
Establish your `venv`, and run it via the first pre-built Run Configuration. To establish your venv:
|
|
914
|
+
|
|
915
|
+
```bash
|
|
916
|
+
python -m venv venv; venv\Scripts\activate # win
|
|
917
|
+
python3 -m venv venv; . venv/bin/activate # mac/linux
|
|
918
|
+
|
|
919
|
+
pip install -r requirements.txt
|
|
920
|
+
```
|
|
921
|
+
|
|
922
|
+
For PyCharm, you will get a dialog requesting to create the `venv`; say yes.
|
|
923
|
+
|
|
924
|
+
See [here](https://apilogicserver.github.io/Docs/Install-Express/) for more information.
|
|
925
|
+
|
|
926
|
+
|
|
927
|
+
|
|
928
|
+
**2. Start and Stop the Server**
|
|
929
|
+
|
|
930
|
+
Both IDEs provide Run Configurations to start programs. These are pre-built by `ApiLogicServer create`.
|
|
931
|
+
|
|
932
|
+
For VSCode, start the Server with F5, Stop with Shift-F5 or the red stop button.
|
|
933
|
+
|
|
934
|
+
For PyCharm, start the server with CTL-D, Stop with red stop button.
|
|
935
|
+
|
|
936
|
+
|
|
937
|
+
|
|
938
|
+
**3. Entering a new Order**
|
|
939
|
+
|
|
940
|
+
To enter a new Order:
|
|
941
|
+
|
|
942
|
+
1. Click `Customer 1``
|
|
943
|
+
|
|
944
|
+
2. Click `+ ADD NEW ORDER`
|
|
945
|
+
|
|
946
|
+
3. Set `Notes` to "hurry", and press `SAVE AND SHOW`
|
|
947
|
+
|
|
948
|
+
4. Click `+ ADD NEW ITEM`
|
|
949
|
+
|
|
950
|
+
5. Enter Quantity 1, lookup "Product 1", and click `SAVE AND ADD ANOTHER`
|
|
951
|
+
|
|
952
|
+
6. Enter Quantity 2000, lookup "Product 2", and click `SAVE`
|
|
953
|
+
|
|
954
|
+
7. Observe the constraint error, triggered by rollups from the `Item` to the `Order` and `Customer`
|
|
955
|
+
|
|
956
|
+
8. Correct the quantity to 2, and click `Save`
|
|
957
|
+
|
|
958
|
+
|
|
959
|
+
**4. Update the Order**
|
|
960
|
+
|
|
961
|
+
To explore our new logic for green products:
|
|
962
|
+
|
|
963
|
+
1. Access the previous order, and `ADD NEW ITEM`
|
|
964
|
+
|
|
965
|
+
2. Enter quantity 11, lookup product `Green`, and click `Save`.
|
|
966
|
+
|
|
967
|
+
</details>
|
|
968
|
+
|
|
969
|
+
|
|
970
|
+
|
|
971
|
+
### Setup Codespaces
|
|
972
|
+
|
|
973
|
+
Codespaces enables you to run in the cloud: VSCode via your Browser, courtesy GitHub.
|
|
974
|
+
|
|
975
|
+
<details markdown>
|
|
976
|
+
|
|
977
|
+
<summary> Using codespaces on your GenAI project</summary>
|
|
978
|
+
|
|
979
|
+
__1. Open your project on GitHub__
|
|
980
|
+
|
|
981
|
+

|
|
982
|
+
|
|
983
|
+
__2. Open it in Codespaces (takes a minute or 2):__
|
|
984
|
+
|
|
985
|
+

|
|
986
|
+
|
|
987
|
+
> You will now see your project - running in VSCode, _in the Browser._ But that's just what you _see..._
|
|
988
|
+
|
|
989
|
+
> Behind the scenes, Codespaces has requisitioned a cloud machine, and loaded your project - with a _complete development environment_ - Python, your dependencies, git, etc.
|
|
990
|
+
|
|
991
|
+
> You are attached to this machine in your Browser, running VSCode.
|
|
992
|
+
|
|
993
|
+
> :trophy: Pretty remarkable.
|
|
994
|
+
|
|
995
|
+
__3. Start the Server and open the App in the Browser__
|
|
996
|
+
|
|
997
|
+
* Use the pre-defined Launch Configuration
|
|
998
|
+
|
|
999
|
+

|
|
1000
|
+
|
|
1001
|
+
|
|
1002
|
+
We think you'll find Codespaces pretty amazing - check it out!
|
|
1003
|
+
|
|
1004
|
+
</details>
|
|
1005
|
+
|
|
1006
|
+
|
|
1007
|
+
|
|
1008
|
+
### Get an OpenAI ApiKey
|
|
1009
|
+
|
|
1010
|
+
<br>GenAI-Logic uses OpenAI, which requires an OpenAI Key:
|
|
1011
|
+
|
|
1012
|
+
1. Obtain one from [here](https://platform.openai.com/account/api-keys) or [here](https://platform.openai.com/api-keys)
|
|
1013
|
+
|
|
1014
|
+
2. Authorize payments [here](https://platform.openai.com/settings/organization/billing/overview)
|
|
1015
|
+
|
|
1016
|
+
</details>
|
|
1017
|
+
|
|
1018
|
+
|
|
1019
|
+
|
|
1020
|
+
### Pre-created Samples
|
|
1021
|
+
|
|
1022
|
+
<details markdown>
|
|
1023
|
+
|
|
1024
|
+
<summary> Explore Pre-created Samples</summary>
|
|
1025
|
+
|
|
1026
|
+
<br>The `samples` folder has pre-created important projects you will want to review at some point (Important: look for **readme files**):
|
|
1027
|
+
|
|
1028
|
+
* [nw_sample_nocust](https://apilogicserver.github.io/Docs/Tutorial/) - northwind (customers, orders...) database
|
|
1029
|
+
|
|
1030
|
+
* This reflects the results you can expect with your own databases
|
|
1031
|
+
|
|
1032
|
+
* [nw_sample](https://apilogicserver.github.io/Docs/Sample-Database/) - same database, but with ***with [customizations](https://apilogicserver.github.io/Docs/IDE-Customize/) added***. It's a great resource for exploring how to customize your projects.
|
|
1033
|
+
|
|
1034
|
+
* Hint: use your IDE to search for `#als`
|
|
1035
|
+
|
|
1036
|
+
* [tutorial](https://apilogicserver.github.io/Docs/Tutorial/) - short (~30 min) walk-through of using API Logic Server using the northwind (customers, orders...) database
|
|
1037
|
+
|
|
1038
|
+
</br>
|
|
1039
|
+
|
|
1040
|
+
<details markdown>
|
|
1041
|
+
|
|
1042
|
+
<summary>You can always re-create the samples</summary>
|
|
1043
|
+
|
|
1044
|
+
<br>Re-create them as follows:
|
|
1045
|
+
|
|
1046
|
+
1. Open a terminal window (**Terminal > New Terminal**), and paste the following CLI command:
|
|
1047
|
+
|
|
1048
|
+
```bash
|
|
1049
|
+
ApiLogicServer create --project-name=samples/tutorial --db-url=
|
|
1050
|
+
ApiLogicServer create --project-name=samples/nw_sample --db-url=nw+
|
|
1051
|
+
ApiLogicServer create --project-name=samples/nw_sample_nocust --db-url=nw
|
|
1052
|
+
```
|
|
1053
|
+
</details>
|
|
1054
|
+
|
|
1055
|
+
|
|
1056
|
+
</details>
|
|
1057
|
+
|