Skip to content

Commit 513256e

Browse files
committed
informal and multi-table logic
1 parent b9dbc95 commit 513256e

File tree

1 file changed

+78
-4
lines changed

1 file changed

+78
-4
lines changed

docs/WebGenAI-CLI.md

Lines changed: 78 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,17 +101,91 @@ As of release 11.2.10, you can declare Natural Language Logic when you create pr
101101

102102
As shown below, you can the CLI `als genai` command to designate a prompt file that generates a system, including logic.
103103

104-
![Create Projects wit Logic](images/web_genai/logic/new-projects.png)
105104

106105
Note:
107106

108107
1. Logic files can contain derivations and constraints
109-
2. Use 'strict' `entity.attribute` references (e.g, `Employee.TotalSalaries`)
108+
2. The system will create model attributes for derived columns. Note these can dramatically improve performance.
109+
110+
You can declare logic formally, or informally.
110111

111-
* The system does not recognize implicit references like *sum of employee salaries*
112112
 
113113

114-
3. The system will create model attributes for derived columns. Note these can dramatically improve performance.
114+
#### Formal Rules
115+
116+
You can use familiar dot notation in declaring rules, e.g.
117+
118+
![Create Projects with Logic](images/web_genai/logic/new-projects.png)
119+
120+
```bash title='Formal Logic - Familar Dot Notation'
121+
Create a system with customers, orders, items and products.
122+
123+
Include a notes field for orders.
124+
125+
Use LogicBank to enforce the Check Credit requirement:
126+
1. Customer.balance <= credit_limit
127+
2. Customer.balance = Sum(Order.amount_total where date_shipped is null)
128+
3. Order.amount_total = Sum(Item.amount)
129+
4. Item.amount = quantity * unit_price
130+
5. Store the Item.unit_price as a copy from Product.unit_price
131+
```
132+
133+
&nbsp;
134+
135+
#### Informal Rules
136+
137+
You can also use a more relaxed declaration. For example, you can create a system (database, API, Admin App and Logic) with the following prompt (see `system/genai/examples/genai_demo/genai_demo_informal.prompt`):
138+
139+
```bash title='Prompt With Informal Logic'
140+
Create a system with customers, orders, items and products.
141+
142+
Include a notes field for orders.
143+
144+
Use LogicBank to enforce the Check Credit requirement:
145+
1. The Customer's balance is less than the credit limit
146+
2. The Customer's balance is the sum of the Order amount_total where date_shipped is null
147+
3. The Order's amount_total is the sum of the Item amount
148+
4. The Item amount is the quantity * unit_price
149+
5. The Item unit_price is copied from the Product unit_price
150+
```
151+
152+
&nbsp;
153+
154+
#### Multi-rule Logic
155+
156+
You can even declare logic that is transformed into 2 rules:
157+
158+
```bash title='Prompt with Multi-Rule Logic'
159+
System for Departments and Employees.
160+
161+
LogicBank:
162+
1. Sum of employee salaries cannot exceed department budget
163+
```
164+
165+
This creates a running system: a database, an API, an Admin App, and logic. From the Manager:
166+
167+
```bash title='CLI Command to Create a microservice, with logic'
168+
als genai --using=system/genai/examples/emp_depts/emp_dept.prompt
169+
```
170+
171+
The logic is non-trivial:
172+
173+
1. A `Department.total_salaries` is created
174+
2. Two rules are created in `logic/declare_logic.py`
175+
176+
```python title='Logic Creates 2 Rules'
177+
# Logic from GenAI: (or, use your IDE w/ code completion)
178+
179+
# Aggregate the total salaries of employees for each department.
180+
Rule.sum(derive=Department.total_salaries, as_sum_of=Employee.salary)
181+
182+
# Ensure the sum of employee salaries does not exceed the department budget.
183+
Rule.constraint(validate=Department, as_condition=lambda row: row.total_salaries <= row.budget, error_msg="Total salaries ({row.total_salaries}) exceed the department budget ({row.budget})")
184+
185+
# End Logic from GenAI
186+
```
187+
188+
> This support is in technology-preview state.
115189
116190
&nbsp;
117191

0 commit comments

Comments
 (0)