Skip to content

Commit 7a027ae

Browse files
committed
prompt examples
1 parent 676dc2d commit 7a027ae

File tree

3 files changed

+156
-4
lines changed

3 files changed

+156
-4
lines changed

Marketing/Cust_order_items__logic.py

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
class Product:
2+
def __init__(self, product_id, unit_price):
3+
self.product_id = product_id
4+
self.unit_price = unit_price
5+
6+
7+
class Item:
8+
def __init__(self, product, quantity):
9+
self.product = product
10+
self.unit_price = product.unit_price # Copy unit_price from Product
11+
self.quantity = quantity
12+
self.amount = self.calculate_amount() # Calculate Item.amount
13+
14+
def calculate_amount(self):
15+
return self.quantity * self.unit_price
16+
17+
def update_quantity(self, new_quantity):
18+
self.quantity = new_quantity
19+
self.amount = self.calculate_amount()
20+
21+
22+
class Order:
23+
def __init__(self):
24+
self.items = []
25+
self.amount_total = 0
26+
27+
def add_item(self, item):
28+
self.items.append(item)
29+
self.update_amount_total()
30+
31+
def update_amount_total(self):
32+
self.amount_total = sum(item.amount for item in self.items)
33+
34+
def update_item(self, item, new_quantity):
35+
item.update_quantity(new_quantity)
36+
self.update_amount_total()
37+
38+
def remove_item(self, item):
39+
self.items.remove(item)
40+
self.update_amount_total()
41+
42+
43+
class Customer:
44+
def __init__(self, credit_limit):
45+
self.credit_limit = credit_limit
46+
self.balance = 0
47+
self.orders = []
48+
49+
def add_order(self, order, date_shipped=None):
50+
self.orders.append({"order": order, "date_shipped": date_shipped})
51+
self.update_balance()
52+
53+
def update_balance(self):
54+
self.balance = sum(
55+
order["order"].amount_total for order in self.orders if order["date_shipped"] is None
56+
)
57+
58+
def check_credit_limit(self):
59+
if self.balance > self.credit_limit:
60+
raise ValueError("Customer balance exceeds credit limit!")
61+
else:
62+
print("Balance is within credit limit.")
63+
64+
def process_order(self, order):
65+
self.update_balance()
66+
self.check_credit_limit()
67+
68+
69+
# Example usage:
70+
71+
# Create a product
72+
product = Product(product_id=1, unit_price=20.0)
73+
74+
# Create an order
75+
order = Order()
76+
77+
# Insert an item
78+
item1 = Item(product, quantity=5) # Insert an item with quantity 5
79+
order.add_item(item1) # Add the item to the order
80+
81+
# Create a customer with a credit limit
82+
customer = Customer(credit_limit=500)
83+
84+
# Add the order to the customer
85+
customer.add_order(order)
86+
87+
# Process and check credit limit after insertion
88+
customer.process_order(order)
89+
90+
# Update the item
91+
order.update_item(item1, new_quantity=10) # Update the item's quantity to 10
92+
93+
# Process and check credit limit after update
94+
customer.process_order(order)
95+
96+
# Delete the item
97+
order.remove_item(item1) # Remove the item from the order
98+
99+
# Process and check credit limit after deletion
100+
customer.process_order(order)
Loading

docs/WebGenAI.md

Lines changed: 56 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,65 @@ The underlying services are also available in the [genai CLI](WebGenAI-CLI.md){:
115115

116116
## Prompt Design
117117

118-
Notes reqarding prompts:
118+
Prompt design is "AI Programming". Consider the following.
119119

120-
1. You can provide a very general prompt (*an auto dealership*), or a specific one that identifies specific tables, columns and relationships (for example, [click here](https://github.com/ApiLogicServer/ApiLogicServer-src/blob/main/tests/test_databases/ai-created/budget_allocation/budget_allocations/genai.prompt){:target="_blank" rel="noopener"}).
120+
 
121+
122+
### Business Area
123+
124+
You can provide a very general prompt, for example:
125+
126+
* `an auto dealership`, or
127+
* `a restaurant`
128+
129+
 
130+
131+
### Database Oriented
132+
133+
Or, you can provide a specific prompt that identifies specific tables, columns and relationships (for example,
134+
135+
```bash title='Database, API and Web App'
136+
Create a system for Customer, Orders, Items and Products
137+
```
138+
139+
 
140+
141+
### With Logic
142+
143+
Particularly interesting is that you can declare backend behavior with rules:
144+
145+
```bash title='Database, API, Web App and Logic'
146+
Create a system with customers, orders, items and products.
147+
148+
Include a notes field for orders.
149+
150+
Use LogicBank to create declare_logic() to enforce the Check Credit requirement (do not generate check constraints):
151+
1. Customer.balance <= credit_limit
152+
2. Customer.balance = Sum(Order.amount_total where date_shipped is null)
153+
3. Order.amount_total = Sum(Item.amount)
154+
4. Item.amount = quantity * unit_price
155+
5. Store the Item.unit_price as a copy from Product.unit_price
156+
```
157+
158+
You can verify this by altering a sample order/item with a very high quantity, and verifying the credit limit is checked. (Note this is not trivial - 3 table transaction.)
159+
160+
> Note: at the time of this writing, the sample data sometimes does not totally reflect the derivation rules. This is under investigation.
161+
162+
&nbsp;
163+
164+
### Iterations
165+
166+
You can *iterate* your prompt to include more tables etc, while preserving the design you have already created.
167+
168+
* This enables you to break your system down into a set of "Use Cases", solving one at a time, and integrating back to the others.
169+
170+
&nbsp;
171+
172+
### Limitations
121173

122-
2. You can *iterate* your prompt to include more tables etc, while preserving the design you have already created.
174+
The created systems are basic database applications, not completed systems with sophisticated functionality such as images, custom screens, etc.
123175

124-
* This enables you to break your system down into a set of "Use Cases", solving one at a time, and integrating back to the others.
176+
You can "build out" the project by downloading it and using your IDE with Python and rules, or perform the same functions using Codespaces (a browser-based version of VSCode - a link is provided for this).
125177

126178
&nbsp;
127179

0 commit comments

Comments
 (0)