ApiLogicServer 14.5.0__py3-none-any.whl → 14.5.4__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/add_cust/add_cust.py +7 -21
- api_logic_server_cli/api_logic_server.py +4 -2
- api_logic_server_cli/api_logic_server_info.yaml +2 -2
- api_logic_server_cli/create_from_model/__pycache__/dbml.cpython-312.pyc +0 -0
- api_logic_server_cli/create_from_model/__pycache__/ont_build.cpython-312.pyc +0 -0
- api_logic_server_cli/create_from_model/dbml.py +3 -0
- api_logic_server_cli/prototypes/basic_demo/customizations/api/api_discovery/{mcp_server_executor.py → mcp_discovery.py} +1 -43
- api_logic_server_cli/prototypes/basic_demo/customizations/config/server_setup.py +388 -0
- api_logic_server_cli/prototypes/basic_demo/customizations/database/system/SAFRSBaseX.py +139 -0
- api_logic_server_cli/prototypes/basic_demo/customizations/integration/mcp/.DS_Store +0 -0
- api_logic_server_cli/prototypes/basic_demo/customizations/integration/mcp/README_mcp.md +3 -1
- api_logic_server_cli/prototypes/basic_demo/customizations/integration/mcp/mcp_client_executor.py +144 -131
- api_logic_server_cli/prototypes/basic_demo/customizations/logic/declare_logic.py +22 -2
- api_logic_server_cli/prototypes/basic_demo/iteration/logic/declare_logic.py +1 -1
- api_logic_server_cli/prototypes/nw/logic/declare_logic.py +2 -2
- api_logic_server_cli/prototypes/nw_no_cust/.obsidian/app.json +1 -0
- api_logic_server_cli/prototypes/nw_no_cust/.obsidian/appearance.json +1 -0
- api_logic_server_cli/prototypes/nw_no_cust/.obsidian/core-plugins.json +31 -0
- api_logic_server_cli/prototypes/nw_no_cust/.obsidian/workspace.json +166 -0
- apilogicserver-14.5.4.dist-info/METADATA +168 -0
- {apilogicserver-14.5.0.dist-info → apilogicserver-14.5.4.dist-info}/RECORD +25 -43
- {apilogicserver-14.5.0.dist-info → apilogicserver-14.5.4.dist-info}/WHEEL +1 -1
- api_logic_server_cli/prototypes/basic_demo/customizations/api/api_discovery/proper_update_def.json +0 -71
- api_logic_server_cli/prototypes/basic_demo/customizations/integration/mcp/1_langchain_loader.py +0 -71
- api_logic_server_cli/prototypes/basic_demo/customizations/integration/mcp/2_gpt_mcp_prompt.txt +0 -19
- api_logic_server_cli/prototypes/basic_demo/customizations/integration/mcp/multi_mcp_flow/multi_mcp_flow.png +0 -0
- api_logic_server_cli/prototypes/basic_demo/customizations/integration/mcp/multi_mcp_flow/multi_mcp_orchestration.yaml +0 -49
- api_logic_server_cli/prototypes/basic_demo/customizations/integration/mcp/multi_mcp_flow/wny mcp flows.png +0 -0
- api_logic_server_cli/prototypes/basic_demo/customizations/integration/mcp/natlang_to_api.py +0 -73
- api_logic_server_cli/prototypes/basic_demo/customizations/integration/mcp/resources/curl.txt +0 -5
- api_logic_server_cli/prototypes/basic_demo/customizations/integration/mcp/resources/images/MCP Overview.png +0 -0
- api_logic_server_cli/prototypes/basic_demo/customizations/integration/mcp/resources/images/MCP_Arch.png +0 -0
- api_logic_server_cli/prototypes/basic_demo/customizations/integration/mcp/resources/images/MCP_Overview_Executor.png +0 -0
- api_logic_server_cli/prototypes/basic_demo/customizations/integration/mcp/resources/invoke_llm/1 - prompt_messages_array.json +0 -10
- api_logic_server_cli/prototypes/basic_demo/customizations/integration/mcp/resources/invoke_llm/2 - completion_tool_context.json +0 -12
- api_logic_server_cli/prototypes/basic_demo/customizations/integration/mcp/resources/llm_schema.txt +0 -38
- api_logic_server_cli/prototypes/basic_demo/customizations/integration/mcp/resources/nw_swagger_2.yaml +0 -17393
- api_logic_server_cli/prototypes/basic_demo/customizations/integration/mcp/resources/nw_swagger_3.yaml +0 -16660
- api_logic_server_cli/prototypes/basic_demo/customizations/integration/mcp/resources/nw_swagger_3_relaxed.yaml +0 -109
- api_logic_server_cli/prototypes/basic_demo/customizations/integration/mcp/resources/proxy_server.py +0 -51
- api_logic_server_cli/prototypes/basic_demo/customizations/integration/mcp/resources/proxy_serverZ.py +0 -72
- api_logic_server_cli/prototypes/basic_demo/customizations/integration/mcp/resources/validate_jsonapi.py +0 -64
- api_logic_server_cli/prototypes/basic_demo/customizations/integration/mcp/run_executor.py +0 -23
- api_logic_server_cli/prototypes/basic_demo/customizations/integration/mcp/swagger_converter.py +0 -65
- api_logic_server_cli/prototypes/basic_demo/customizations/integration/mcp/z_old/3_executor_test_agent.py +0 -52
- api_logic_server_cli/prototypes/manager/README_X.md +0 -663
- apilogicserver-14.5.0.dist-info/METADATA +0 -76
- {apilogicserver-14.5.0.dist-info → apilogicserver-14.5.4.dist-info}/entry_points.txt +0 -0
- {apilogicserver-14.5.0.dist-info → apilogicserver-14.5.4.dist-info}/licenses/LICENSE +0 -0
- {apilogicserver-14.5.0.dist-info → apilogicserver-14.5.4.dist-info}/top_level.txt +0 -0
|
@@ -1,663 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
version info: 1.0 (01/11/2025)
|
|
3
|
-
---
|
|
4
|
-
## Welcome to API Logic Server
|
|
5
|
-
|
|
6
|
-
1. ***Instant microservices*** (APIs and Admin Apps) from a database or **GenAI prompt** -- 1 command
|
|
7
|
-
|
|
8
|
-
2. ***Customize*** with **Rules** and Python in your IDE: created projects use standard Python libraries (Flask, SQLAlchemy)
|
|
9
|
-
|
|
10
|
-
</br>
|
|
11
|
-
|
|
12
|
-
You are in the [API Logic Server Manager](https://apilogicserver.github.io/Docs/Manager/). This is a good place to manage projects, create notes and resources, etc.
|
|
13
|
-
|
|
14
|
-
<details markdown>
|
|
15
|
-
|
|
16
|
-
<summary>How to Run Projects from the Manager </summary>
|
|
17
|
-
|
|
18
|
-
<br>You typically run projects by opening an IDE on the project folder, using provided Run Configurations.
|
|
19
|
-
|
|
20
|
-
For a quick preview, you can also run from the Manager; there are 2 ways:
|
|
21
|
-
|
|
22
|
-
1. Use ***another instance of VSCode.*** You can *examine* them in this current instance, but *run* them in their own instance.
|
|
23
|
-
|
|
24
|
-
* To do so, you probably want to acquire this extension: `Open Folder Context Menus for VS Code`. It will enable you to open the sample, tutorial or your own projects in another instance of VSCode.
|
|
25
|
-
|
|
26
|
-
* This option provides more Run/Debug options (e.g., run without security, etc),
|
|
27
|
-
|
|
28
|
-
2. Or, use the Run/Debug Entry: `API Logic Server Run (run project from manager)`
|
|
29
|
-
|
|
30
|
-
</details>
|
|
31
|
-
</br>
|
|
32
|
-
|
|
33
|
-
<details markdown>
|
|
34
|
-
|
|
35
|
-
<summary>How API Logic Server provides GenAI Microservice Automation </summary>
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
## Using GenAI Microservice Automation
|
|
40
|
-
|
|
41
|
-
Use the CLI (Command Language Interface, in your IDE) to create projects from either existing databases, or GenAI prompts. This creates a project you can open, run and customize in your IDE.
|
|
42
|
-
|
|
43
|
-
[](https://www.youtube.com/watch?v=LSh7mqGiT0k&t=5s "Microservice Automation")
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
## What Is API Logic Server
|
|
48
|
-
|
|
49
|
-
It's an open source Python project consisting of a CLI to create projects, and runtime libraries to execute them.
|
|
50
|
-
|
|
51
|
-
[](https://apilogicserver.github.io/Docs/Architecture-What-Is/#runtimes-and-cli)
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
## Modern Scalable Runtime Architecture
|
|
56
|
-
|
|
57
|
-
Created projects use standard Flask and SQLAlchemy; automation is provided by Logic Bank (the rule engine) and SAFRS (JSON:APIs). Scripts are provided to containerize projects, and deploy to Azure.
|
|
58
|
-
|
|
59
|
-
[](https://apilogicserver.github.io/Docs/Architecture-What-Is/#key-runtime-components)
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
</details>
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
## Explore Creating Projects
|
|
68
|
-
|
|
69
|
-
**Evaluation Guide:** click on the disclosure buttons, below. Important: look for **readme files.**
|
|
70
|
-
</br>
|
|
71
|
-
|
|
72
|
-
<details markdown>
|
|
73
|
-
|
|
74
|
-
<summary> 1. Existing Database - pre-installed sample databases </summary>
|
|
75
|
-
|
|
76
|
-
<br>For a self-demo, use the CLI (**Terminal > New Terminal**), and try the pre-installed [**Basic Demo**](https://apilogicserver.github.io/Docs/Sample-Basic-Demo/):
|
|
77
|
-
|
|
78
|
-
```
|
|
79
|
-
als create --project-name=basic_demo --db-url=basic_demo
|
|
80
|
-
```
|
|
81
|
-
|
|
82
|
-
<br>To create a larger project, try the pre-installed [**northwind database**](https://apilogicserver.github.io/Docs/Tutorial/) (imagine your own database here):
|
|
83
|
-
|
|
84
|
-
```
|
|
85
|
-
als create --project-name=nw_sample_nocust --db-url=sqlite:///nw.sqlite
|
|
86
|
-
```
|
|
87
|
-
|
|
88
|
-
<br>See **with customizations** in the [pre-created sample apps](#explore-pre-created-samples). This is an **important learning resource**.
|
|
89
|
-
|
|
90
|
-
Then, try your own databases [(db-url examples here)](https://apilogicserver.github.io/Docs/Database-Connectivity/), or experiment with [these Docker databases](https://apilogicserver.github.io/Docs/Database-Docker/).
|
|
91
|
-
|
|
92
|
-
</details>
|
|
93
|
-
</br>
|
|
94
|
-
|
|
95
|
-
<details markdown>
|
|
96
|
-
|
|
97
|
-
<summary> 2. New Database - using GenAI Microservice Automation (Experiment with AI - Signup optional)</summary>
|
|
98
|
-
|
|
99
|
-
<br>You can do this with or without signup:
|
|
100
|
-
|
|
101
|
-
1. If you have signed up (see *To obtain a ChatGPT API Key*, below), this will create and open a project called `genai_demo` from `genai_demo.prompt` (available in left Explorer pane):
|
|
102
|
-
|
|
103
|
-
```bash
|
|
104
|
-
als genai --using=system/genai/examples/genai_demo/genai_demo.prompt --project-name=genai_demo
|
|
105
|
-
```
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
2. ***Or,*** you can simulate the process (no signup) using:
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
```bash
|
|
112
|
-
als genai --repaired-response=system/genai/examples/genai_demo/genai_demo.response_example --project-name=genai_demo
|
|
113
|
-
```
|
|
114
|
-
|
|
115
|
-
Verify it's operating properly:
|
|
116
|
-
|
|
117
|
-
1. Run Configurations are provided to start the server
|
|
118
|
-
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
|
|
119
|
-
3. Observe the constraint operating on the rollup of order amount_totals.
|
|
120
|
-
* View the logic in `logic/declare_logic.py`
|
|
121
|
-
* Put a breakpoint on the `as_condition`. Observe the console log to see rule execution for this multi-table transaction.
|
|
122
|
-
|
|
123
|
-
</br>
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
<details markdown>
|
|
127
|
-
|
|
128
|
-
<summary> To obtain a ChatGPT API Key</summary>
|
|
129
|
-
|
|
130
|
-
<br>GenAI-Logic uses OpenAI, which requires an Open API Key:
|
|
131
|
-
|
|
132
|
-
1. Obtain one from [here](https://platform.openai.com/account/api-keys) or [here](https://platform.openai.com/api-keys)
|
|
133
|
-
2. Authorize payments [here](https://platform.openai.com/settings/organization/billing/overview)
|
|
134
|
-
|
|
135
|
-
</details>
|
|
136
|
-
|
|
137
|
-
</br>
|
|
138
|
-
|
|
139
|
-
<details markdown>
|
|
140
|
-
|
|
141
|
-
<summary> What Just Happened? Next Steps...</summary>
|
|
142
|
-
|
|
143
|
-
<br>`genai` processing is shown below (internal steps denoted in grey):
|
|
144
|
-
|
|
145
|
-
1. You create your.prompt file, and invoke `als genai --using=your.prompt`. genai then creates your project as follows:
|
|
146
|
-
|
|
147
|
-
a. Submits your prompt to the `ChatGPT API`
|
|
148
|
-
|
|
149
|
-
b. Writes the response to file, so you can correct and retry if anything goes wrong
|
|
150
|
-
|
|
151
|
-
c. Extracts model.py from the response
|
|
152
|
-
|
|
153
|
-
d. Invokes `als create-from-model`, which creates the database and your project
|
|
154
|
-
|
|
155
|
-
2. Your created project is opened in your IDE, ready to execute and customize.
|
|
156
|
-
|
|
157
|
-
a. Review `Tutorial.md`, Explore Customizations.
|
|
158
|
-
|
|
159
|
-

|
|
160
|
-
|
|
161
|
-
</details>
|
|
162
|
-
</br>
|
|
163
|
-
|
|
164
|
-
<details markdown>
|
|
165
|
-
|
|
166
|
-
<summary> You can iterate the logic and data model</summary>
|
|
167
|
-
|
|
168
|
-
<br>The approach for an iteration is to create a new project from an existing one:
|
|
169
|
-
|
|
170
|
-
1. add another prompt to an existing projects `docs` directory, specifying your changes
|
|
171
|
-
2. use `als genai`, specifying
|
|
172
|
-
* `--using` existing projects `docs` directory, and
|
|
173
|
-
* `--project-name` as the output project
|
|
174
|
-
|
|
175
|
-
**Logic iterations** are particuarly useful. For example, here we take the basic check-credit logic, and add:
|
|
176
|
-
|
|
177
|
-
> 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
|
|
178
|
-
|
|
179
|
-
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:
|
|
180
|
-
|
|
181
|
-
```bash title='Iterate Business Logic'
|
|
182
|
-
# Iterate with data model and logic
|
|
183
|
-
als genai --project-name='genai_demo_with_discount' --using=system/genai/examples/genai_demo/genai_demo_iteration_discount
|
|
184
|
-
# open Docs/db.dbml
|
|
185
|
-
```
|
|
186
|
-
|
|
187
|
-
<br>
|
|
188
|
-
|
|
189
|
-
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):
|
|
190
|
-
|
|
191
|
-
```bash title='Iterate Without Logic'
|
|
192
|
-
# Step 1 - create without logic
|
|
193
|
-
als genai --project-name='genai_demo_no_logic' --using=system/genai/examples/genai_demo/genai_demo_no_logic.prompt
|
|
194
|
-
# open Docs/db.dbml
|
|
195
|
-
```
|
|
196
|
-
|
|
197
|
-
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`):
|
|
198
|
-
|
|
199
|
-
```bash title='Iterate With Logic'
|
|
200
|
-
# Iterate with data model and logic
|
|
201
|
-
als genai --project-name='genai_demo_with_logic' --using=system/genai/examples/genai_demo/genai_demo_iteration
|
|
202
|
-
# open Docs/db.dbml
|
|
203
|
-
```
|
|
204
|
-
|
|
205
|
-
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.
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
</details>
|
|
209
|
-
</br>
|
|
210
|
-
|
|
211
|
-
<details markdown>
|
|
212
|
-
|
|
213
|
-
<summary> You can declare informal logic</summary>
|
|
214
|
-
|
|
215
|
-
<br>You can declare rules using dot notation, or more informally:
|
|
216
|
-
|
|
217
|
-
```bash title="Informal Logic (no dot notation)"
|
|
218
|
-
als genai --using=system/genai/examples/genai_demo/genai_demo_informal.prompt --project-name=genai_demo_informal
|
|
219
|
-
```
|
|
220
|
-
</details>
|
|
221
|
-
</br>
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
<details markdown>
|
|
225
|
-
|
|
226
|
-
<summary> Multi-Rule Logic</summary>
|
|
227
|
-
|
|
228
|
-
<br>You can add new columns/tables, while keeping the prior model intact:
|
|
229
|
-
|
|
230
|
-
```bash title="Multi-Rule Logic"
|
|
231
|
-
als genai --using=system/genai/examples/emp_depts/emp_dept.prompt
|
|
232
|
-
```
|
|
233
|
-
</details>
|
|
234
|
-
</br>
|
|
235
|
-
|
|
236
|
-
<details markdown>
|
|
237
|
-
|
|
238
|
-
<summary> You can ask AI to suggest logic (great way to learn!)</summary>
|
|
239
|
-
|
|
240
|
-
<br>You can create a project, and ask GenAI for logic suggestions:
|
|
241
|
-
|
|
242
|
-
```bash title='1. Create Project, without Rules'
|
|
243
|
-
# 1. Create Project, without Rules
|
|
244
|
-
als genai --project-name='genai_demo_no_logic' --using=system/genai/examples/genai_demo/genai_demo_no_logic.prompt
|
|
245
|
-
```
|
|
246
|
-
|
|
247
|
-
```bash title="2. Request Rule Suggestions"
|
|
248
|
-
# 2. Request Rule Suggestions
|
|
249
|
-
cd genai_demo_no_logic
|
|
250
|
-
als genai-logic --suggest
|
|
251
|
-
```
|
|
252
|
-
|
|
253
|
-
You can review the [resultant logic suggestions](genai_demo_no_logic/docs/logic_suggestions) in the `genai_demo_no_logic` project:
|
|
254
|
-
|
|
255
|
-
* See and edit: `docs/logic_suggestions/002_logic_suggestions.prompt` (used in step 3, below)
|
|
256
|
-
* This corresponds to the Logic Editor - Logic View in the WebGenAI web app
|
|
257
|
-
|
|
258
|
-
```bash title="3. See the rules for the logic"
|
|
259
|
-
# 3. See the rule code for the logic
|
|
260
|
-
als genai-logic --suggest --logic='*'
|
|
261
|
-
```
|
|
262
|
-
|
|
263
|
-
Important notes about suggestions and generated code:
|
|
264
|
-
* `--suggest --logic='*'` is intended to enable you to identify logic that does not translate into proper code
|
|
265
|
-
* The example above was pretty good, but sometimes the results are downright silly:
|
|
266
|
-
* Just run suggest again, or
|
|
267
|
-
* Repair `docs/logic_suggestions/002_logic_suggestions.prompt`
|
|
268
|
-
|
|
269
|
-
Also...
|
|
270
|
-
* It is not advised to paste the code into `logic/declare_logic.py`
|
|
271
|
-
* The suggested logic may result in new data model attributes
|
|
272
|
-
* These are created automatically by running `als genai` (next step)
|
|
273
|
-
|
|
274
|
-
The [logic suggestions directory](genai_demo_no_logic/docs/logic_suggestions) now contains the prompts to create a new project with the suggested logic.
|
|
275
|
-
When you are ready to proceed:
|
|
276
|
-
1. Execute the following to create a *new project* (iteration), with suggested logic:
|
|
277
|
-
|
|
278
|
-
```bash title="4. Create a new project with the Rule Suggestions"
|
|
279
|
-
# 4. Create a new project with the Rule Suggestions
|
|
280
|
-
cd .. # important - back to manager root dir
|
|
281
|
-
als genai --project-name='genai_demo_with_logic' --using=genai_demo_no_logic/docs/logic_suggestions
|
|
282
|
-
```
|
|
283
|
-
|
|
284
|
-
Observe:
|
|
285
|
-
1. The created project has the rule suggestions in `logic/declare_logic.py`
|
|
286
|
-
2. A revised Data Model in `database/models.py` that includes attributes introduced by the logic suggestions
|
|
287
|
-
3. Revised test database, initialized to reflect the derivations in the suggested logic
|
|
288
|
-
|
|
289
|
-
Internal Note: this sequence available in the run configs (s1/s4).
|
|
290
|
-
|
|
291
|
-
</details>
|
|
292
|
-
|
|
293
|
-
</br>
|
|
294
|
-
|
|
295
|
-
<details markdown>
|
|
296
|
-
|
|
297
|
-
<summary>Fixup - update data model with new attributes from rules</summary>
|
|
298
|
-
|
|
299
|
-
<br>Fixes project issues by updating the Data Model and Test Data:
|
|
300
|
-
when adding rules, such as using suggestions, you may introduce new attributes.
|
|
301
|
-
If these are missing, you will see exceptions when you start your project.
|
|
302
|
-
|
|
303
|
-
The `genai-utils --fixup` fixes such project issues by updating the Data Model and Test Data:
|
|
304
|
-
|
|
305
|
-
1. Collects the latest model, rules, and test data from the project.
|
|
306
|
-
2. Calls ChatGPT (or similar) to resolve missing columns or data in the project.
|
|
307
|
-
3. Saves the fixup request/response under a 'fixup' folder.
|
|
308
|
-
4. You then use this to create a new project
|
|
309
|
-
|
|
310
|
-
***Setup***
|
|
311
|
-
|
|
312
|
-
After starting the [Manager](https://apilogicserver.github.io/Docs/Manager):
|
|
313
|
-
|
|
314
|
-
```bash title="0. Create Project Requiring Fixup"
|
|
315
|
-
# 0. Create a project requiring fixup
|
|
316
|
-
als genai --repaired-response=system/genai/examples/genai_demo/genai_demo_fixup_required.json --project-name=genai_demo_fixup_required
|
|
317
|
-
```
|
|
318
|
-
|
|
319
|
-
If you run this project, you will observe that it fails with:
|
|
320
|
-
```bash
|
|
321
|
-
Logic Bank Activation Error -- see https://apilogicserver.github.io/Docs/WebGenAI-CLI/#recovery-options
|
|
322
|
-
Invalid Rules: [AttributeError("type object 'Customer' has no attribute 'balance'")]
|
|
323
|
-
Missing Attrs (try als genai-utils --fixup): ['Customer.balance: constraint']
|
|
324
|
-
```
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
***Fixup***
|
|
328
|
-
|
|
329
|
-
To Fix it:
|
|
330
|
-
```bash title="1. Run FixUp to add missing attributes to the fixup response data model"
|
|
331
|
-
# 1. Run FixUp to add missing attributes to the data model
|
|
332
|
-
cd genai_demo_fixup_required
|
|
333
|
-
als genai-utils --fixup
|
|
334
|
-
```
|
|
335
|
-
|
|
336
|
-
Finally, use the created [fixup files](genai_demo_fixup_required/docs/fixup/) to rebuild the project:
|
|
337
|
-
```bash title="2. Rebuild the project from the fixup response data model"
|
|
338
|
-
# 2. Rebuild the project from the fixup response data model
|
|
339
|
-
cd ../
|
|
340
|
-
als genai --repaired-response=genai_demo_fixup_required/docs/fixup/response_fixup.json --project-name=fixed_project
|
|
341
|
-
```
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
The created project may still report some attributes as missing.
|
|
345
|
-
(ChatGPT seems to often miss attributes mentioned in sum/count where clauses.) To fix:
|
|
346
|
-
|
|
347
|
-
1. Note the missing attributes(s) from the log
|
|
348
|
-
2. Add them to `docs/003_suggest.prompt`
|
|
349
|
-
3. Rebuild the project: `als genai --project-name='genai_demo_with_logic' --using=genai_demo_no_logic/docs`
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
Internal Note: this sequence available in the run configs (f1/f2).
|
|
353
|
-
|
|
354
|
-
</details>
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
</br>
|
|
358
|
-
|
|
359
|
-
<details markdown>
|
|
360
|
-
|
|
361
|
-
<summary>Create from WebGenAI, and import (merge) subsequent changes</summary>
|
|
362
|
-
|
|
363
|
-
<br>You can use [WebGenAI](https://apilogicserver.github.io/Docs/WebGenAI/) to create a project, and export it.
|
|
364
|
-
|
|
365
|
-
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.
|
|
366
|
-
|
|
367
|
-
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/).
|
|
368
|
-
|
|
369
|
-
The Manager pre-installs a sample project you can use to explore import:
|
|
370
|
-
|
|
371
|
-
```bash
|
|
372
|
-
cd system/genai/examples/genai_demo/wg_dev_merge/dev_demo_no_logic_fixed
|
|
373
|
-
als genai-utils --import-genai --using=../wg_demo_no_logic_fixed
|
|
374
|
-
```
|
|
375
|
-
Observe:
|
|
376
|
-
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`
|
|
377
|
-
2. The test data has been updated to include these attributes, with proper values
|
|
378
|
-
|
|
379
|
-
</details>
|
|
380
|
-
|
|
381
|
-
</br>
|
|
382
|
-
|
|
383
|
-
<details markdown>
|
|
384
|
-
|
|
385
|
-
<summary>Rebuild the test data</summary>
|
|
386
|
-
|
|
387
|
-
<br>Fixes project issues by rebuilding the database to conform to the derivation rules:
|
|
388
|
-
|
|
389
|
-
1. Create genai_demo:
|
|
390
|
-
```
|
|
391
|
-
als genai --using=system/genai/examples/genai_demo/genai_demo.prompt --project-name=genai_demo
|
|
392
|
-
```
|
|
393
|
-
2. Rebuild:
|
|
394
|
-
```
|
|
395
|
-
cd genai_demo
|
|
396
|
-
als genai-utils --rebuild-test-data
|
|
397
|
-
```
|
|
398
|
-
|
|
399
|
-
</details>
|
|
400
|
-
</br>
|
|
401
|
-
|
|
402
|
-
<details markdown>
|
|
403
|
-
|
|
404
|
-
<summary> You can also execute directly, and iterate</summary>
|
|
405
|
-
|
|
406
|
-
<br>You can add new columns/tables, while keeping the prior model intact:
|
|
407
|
-
|
|
408
|
-
```bash title="Iterate"
|
|
409
|
-
# create project without creating a file...
|
|
410
|
-
als genai-create --project-name='customer_orders' --using='customer orders'
|
|
411
|
-
|
|
412
|
-
als genai-iterate --using='add Order Details and Products'
|
|
413
|
-
# open Docs/db.dbml
|
|
414
|
-
```
|
|
415
|
-
|
|
416
|
-
</details>
|
|
417
|
-
</br>
|
|
418
|
-
|
|
419
|
-
<details markdown>
|
|
420
|
-
|
|
421
|
-
<summary> AI somtimes fails - here's how to recover</summary>
|
|
422
|
-
|
|
423
|
-
<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:
|
|
424
|
-
|
|
425
|
-
```bash
|
|
426
|
-
als create --project-name=genai_demo --from-model=system/genai/temp/create_db_models.py --db-url=sqlite
|
|
427
|
-
```
|
|
428
|
-
|
|
429
|
-
Or, correct the chatgpt response, and
|
|
430
|
-
|
|
431
|
-
```bash
|
|
432
|
-
als genai --repaired-response=system/genai/examples/genai_demo/genai_demo.response_example --project-name=genai_demo
|
|
433
|
-
```
|
|
434
|
-
|
|
435
|
-
We have seen failures such as:
|
|
436
|
-
|
|
437
|
-
* duplicate definition of `DECIMAL`
|
|
438
|
-
* unclosed parentheses
|
|
439
|
-
* data type errors in test data creation
|
|
440
|
-
* wrong engine import: from logic_bank import Engine, constraint
|
|
441
|
-
* bad test data creation: with Engine() as engine...
|
|
442
|
-
* Bad load code (no session)
|
|
443
|
-
|
|
444
|
-
</details>
|
|
445
|
-
</br>
|
|
446
|
-
|
|
447
|
-
<details markdown>
|
|
448
|
-
|
|
449
|
-
<summary> Postgresql Example </summary>
|
|
450
|
-
|
|
451
|
-
You can test this as follows:
|
|
452
|
-
|
|
453
|
-
1. Use [our docker image](https://apilogicserver.github.io/Docs/Database-Docker/):
|
|
454
|
-
2. And try:
|
|
455
|
-
|
|
456
|
-
```bash
|
|
457
|
-
als genai --using=system/genai/examples/postgres/genai_demo_pg.prompt --db-url=postgresql://postgres:p@localhost/genai_demo
|
|
458
|
-
```
|
|
459
|
-
|
|
460
|
-
Provisos:
|
|
461
|
-
|
|
462
|
-
* 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
|
|
463
|
-
|
|
464
|
-
</details>
|
|
465
|
-
</details>
|
|
466
|
-
</br>
|
|
467
|
-
|
|
468
|
-
<details markdown>
|
|
469
|
-
|
|
470
|
-
<summary> 3. New Database - using Copilot (Signup optional) </summary>
|
|
471
|
-
|
|
472
|
-
<br>You can use Copilot chat (if extension installed; if not, skip to step 3):
|
|
473
|
-
|
|
474
|
-
1. Create a model, eg:
|
|
475
|
-
|
|
476
|
-
<details markdown>
|
|
477
|
-
|
|
478
|
-
<summary> Show Me How to Use Copilot </summary>
|
|
479
|
-
|
|
480
|
-
<br>>Paste this into the Copilot prompt:
|
|
481
|
-
|
|
482
|
-
```
|
|
483
|
-
Use SQLAlchemy to create a sqlite database named sample_ai.sqlite, with customers, orders, items and product
|
|
484
|
-
|
|
485
|
-
Hints: use autonum keys, allow nulls, Decimal types, foreign keys, no check constraints.
|
|
486
|
-
|
|
487
|
-
Include a notes field for orders.
|
|
488
|
-
|
|
489
|
-
Create a few rows of only customer and product data.
|
|
490
|
-
|
|
491
|
-
Enforce the Check Credit requirement (do not generate check constraints):
|
|
492
|
-
|
|
493
|
-
1. Customer.Balance <= CreditLimit
|
|
494
|
-
2. Customer.Balance = Sum(Order.AmountTotal where date shipped is null)
|
|
495
|
-
3. Order.AmountTotal = Sum(Items.Amount)
|
|
496
|
-
4. Items.Amount = Quantity * UnitPrice
|
|
497
|
-
5. Store the Items.UnitPrice as a copy from Product.UnitPrice
|
|
498
|
-
```
|
|
499
|
-
|
|
500
|
-

|
|
501
|
-
</details>
|
|
502
|
-
|
|
503
|
-
<br>
|
|
504
|
-
|
|
505
|
-
2. Paste the copilot response into a new `sample_ai.py` file
|
|
506
|
-
|
|
507
|
-
3. Create your project:
|
|
508
|
-
|
|
509
|
-
```bash
|
|
510
|
-
als create --project-name=sample_ai --from-model=sample_ai.py --db-url=sqlite
|
|
511
|
-
```
|
|
512
|
-
|
|
513
|
-
4. This will create your database, create an API Logic Project from it, and launch your IDE.
|
|
514
|
-
|
|
515
|
-
5. Create business logic
|
|
516
|
-
|
|
517
|
-
* You can create logic with either your IDE (and code completion), or Natural Language
|
|
518
|
-
* To use Natural Language:
|
|
519
|
-
|
|
520
|
-
1. Use the CoPilot chat,
|
|
521
|
-
2. Paste the logic above
|
|
522
|
-
3. Copy it to `logic/declare_logic.py` after `discover_logic()`
|
|
523
|
-
|
|
524
|
-
* Alert: Table and Column Names may require correction to conform to the model
|
|
525
|
-
* Alert: you may to apply [defaulting](https://apilogicserver.github.io/Docs/Logic-Use/#insert-defaulting), and initialize derived attributes in your database
|
|
526
|
-
|
|
527
|
-
</details>
|
|
528
|
-
</br>
|
|
529
|
-
|
|
530
|
-
<details markdown>
|
|
531
|
-
|
|
532
|
-
<summary> 4. New Database - using ChatGPT in the Browser (Signup not required)</summary>
|
|
533
|
-
|
|
534
|
-
<br>A final option for GenAI is to use your Browser with ChatGPT.
|
|
535
|
-
|
|
536
|
-
Please see [this doc](https://apilogicserver.github.io/Docs/Sample-AI-ChatGPT/)
|
|
537
|
-
|
|
538
|
-
</details>
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
## Explore Pre-created Samples
|
|
544
|
-
|
|
545
|
-
<details markdown>
|
|
546
|
-
|
|
547
|
-
<summary> Explore Pre-created Samples</summary>
|
|
548
|
-
|
|
549
|
-
<br>The `samples` folder has pre-created important projects you will want to review at some point (Important: look for **readme files**):
|
|
550
|
-
|
|
551
|
-
* [nw_sample_nocust](https://apilogicserver.github.io/Docs/Tutorial/) - northwind (customers, orders...) database
|
|
552
|
-
|
|
553
|
-
* This reflects the results you can expect with your own databases
|
|
554
|
-
|
|
555
|
-
* [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.
|
|
556
|
-
|
|
557
|
-
* Hint: use your IDE to search for `#als`
|
|
558
|
-
|
|
559
|
-
* [tutorial](https://apilogicserver.github.io/Docs/Tutorial/) - short (~30 min) walk-through of using API Logic Server using the northwind (customers, orders...) database
|
|
560
|
-
|
|
561
|
-
</br>
|
|
562
|
-
|
|
563
|
-
<details markdown>
|
|
564
|
-
|
|
565
|
-
<summary>You can always re-create the samples</summary>
|
|
566
|
-
|
|
567
|
-
<br>Re-create them as follows:
|
|
568
|
-
|
|
569
|
-
1. Open a terminal window (**Terminal > New Terminal**), and paste the following CLI command:
|
|
570
|
-
|
|
571
|
-
```bash
|
|
572
|
-
ApiLogicServer create --project-name=samples/tutorial --db-url=
|
|
573
|
-
ApiLogicServer create --project-name=samples/nw_sample --db-url=nw+
|
|
574
|
-
ApiLogicServer create --project-name=samples/nw_sample_nocust --db-url=nw
|
|
575
|
-
```
|
|
576
|
-
</details>
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
</details>
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
## Explore WebGenAI
|
|
584
|
-
|
|
585
|
-
In addition to the CLI examples above, you can use [WebGenAI](https://apilogicserver.github.io/Docs/WebGenAI/) - a web interface for creating projects from prompts. You can install WebGenAI on a server, so that created projects are easy to review with colleagues.
|
|
586
|
-
|
|
587
|
-
To try WebGenAI:
|
|
588
|
-
|
|
589
|
-
```bash
|
|
590
|
-
cd webgenai
|
|
591
|
-
docker compose up
|
|
592
|
-
```
|
|
593
|
-
|
|
594
|
-
You will be directed to the registration process. You will also require a ChatGPT API Key as described above.
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
## Appendix: Quick Basic Demo
|
|
601
|
-
|
|
602
|
-
This is a "cheat sheet" for experienced ALS users, e.g., to show your colleagues.
|
|
603
|
-
|
|
604
|
-
<details markdown>
|
|
605
|
-
|
|
606
|
-
<summary>Quick Basic Demo - Instructions</summary>
|
|
607
|
-
|
|
608
|
-
<br>This demo creates and customizes a project, starting from a database:
|
|
609
|
-
|
|
610
|
-
```bash title="Quick Basic Demo"
|
|
611
|
-
|
|
612
|
-
# Microservice Automation
|
|
613
|
-
# Admin App, API, Project
|
|
614
|
-
als create --project-name=basic_demo --db-url=basic_demo
|
|
615
|
-
|
|
616
|
-
# Logic and Security
|
|
617
|
-
# see logic (logic/declare_logic.py, logic/cocktail-napkin.jpg); add an Order and Item
|
|
618
|
-
# see security (security/declare_security.py); compare customers, s1 vs. admin
|
|
619
|
-
als add-cust
|
|
620
|
-
als add-auth --db_url=auth
|
|
621
|
-
|
|
622
|
-
# Python Extensibility, Kafka Integration, Rebuild Iteration
|
|
623
|
-
# see logic/declare_logic.py (breakpoint for Kafka)
|
|
624
|
-
# Swagger: ServicesEndPoint.OrderB2B
|
|
625
|
-
als add-cust
|
|
626
|
-
als rebuild-from-database --db_url=sqlite:///database/db.sqlite
|
|
627
|
-
```
|
|
628
|
-
|
|
629
|
-
</details>
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
## Appendix: GenAI Demo
|
|
635
|
-
|
|
636
|
-
This is a "cheat sheet" for experienced ALS users, e.g., to show your colleagues.
|
|
637
|
-
|
|
638
|
-
<details markdown>
|
|
639
|
-
|
|
640
|
-
<summary>Quick GenAI Demo - Instructions</summary>
|
|
641
|
-
|
|
642
|
-
<br>This demo creates and customizes a project, starting from a prompt:
|
|
643
|
-
|
|
644
|
-
```bash title="Quick GenAI Demo"
|
|
645
|
-
|
|
646
|
-
# Microservice Automation from GenAI Prompt
|
|
647
|
-
# Admin App, API, Project
|
|
648
|
-
als genai --using=system/genai/examples/genai_demo/genai_demo.prompt
|
|
649
|
-
|
|
650
|
-
# Or, Microservice Automation from Saved Response
|
|
651
|
-
# Admin App, API, Project
|
|
652
|
-
als genai --repaired-response=system/genai/temp/chatgpt_retry.response
|
|
653
|
-
|
|
654
|
-
# Logic and Security
|
|
655
|
-
# - see logic (logic/declare_logic.py, logic/cocktail-napkin.jpg); add an Order and Item
|
|
656
|
-
# - see security (security/declare_security.py); compare customers, s1 vs. admin
|
|
657
|
-
# Python Extensibility, Kafka Integration, Rebuild Iteration
|
|
658
|
-
# - see logic/declare_logic.py (breakpoint for Kafka)
|
|
659
|
-
# - Swagger: ServicesEndPoint.OrderB2B
|
|
660
|
-
als add-cust
|
|
661
|
-
```
|
|
662
|
-
|
|
663
|
-
</details>
|