ApiLogicServer 14.2.20__py3-none-any.whl → 14.3.0__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.
Files changed (67) hide show
  1. {ApiLogicServer-14.2.20.dist-info → ApiLogicServer-14.3.0.dist-info}/METADATA +2 -2
  2. {ApiLogicServer-14.2.20.dist-info → ApiLogicServer-14.3.0.dist-info}/RECORD +65 -47
  3. api_logic_server_cli/api_logic_server.py +4 -1
  4. api_logic_server_cli/api_logic_server_info.yaml +3 -3
  5. api_logic_server_cli/create_from_model/__pycache__/api_logic_server_utils.cpython-312.pyc +0 -0
  6. api_logic_server_cli/create_from_model/__pycache__/ont_build.cpython-312.pyc +0 -0
  7. api_logic_server_cli/create_from_model/__pycache__/ont_create.cpython-312.pyc +0 -0
  8. api_logic_server_cli/create_from_model/api_logic_server_utils.py +4 -0
  9. api_logic_server_cli/create_from_model/ont_build.py +53 -19
  10. api_logic_server_cli/create_from_model/ont_create.py +14 -5
  11. api_logic_server_cli/fragments/declare_logic.py +72 -0
  12. api_logic_server_cli/{prototypes/manager/system/genai/create_db_models_inserts/logic_discovery_prefix.py → fragments/declare_logic_begin.py} +2 -1
  13. api_logic_server_cli/fragments/declare_logic_end.py +52 -0
  14. api_logic_server_cli/genai/genai.py +21 -8
  15. api_logic_server_cli/genai/genai_logic_builder.py +14 -11
  16. api_logic_server_cli/genai/genai_svcs.py +102 -7
  17. api_logic_server_cli/model_migrator/model_migrator_start.py +1 -1
  18. api_logic_server_cli/model_migrator/reposreader.py +9 -1
  19. api_logic_server_cli/model_migrator/rule_obj.py +24 -6
  20. api_logic_server_cli/prototypes/base/api/api_discovery/ontimize_api.py +4 -1
  21. api_logic_server_cli/prototypes/base/config/activate_logicbank.py +8 -4
  22. api_logic_server_cli/prototypes/base/database/bind_dbs.py +1 -1
  23. api_logic_server_cli/prototypes/base/database/test_data/readme.md +5 -5
  24. api_logic_server_cli/prototypes/base/logic/declare_logic.py +8 -3
  25. api_logic_server_cli/prototypes/base/logic/load_verify_rules.py +216 -0
  26. api_logic_server_cli/prototypes/base/logic/logic_discovery/auto_discovery.py +22 -13
  27. api_logic_server_cli/prototypes/genai_demo/logic/declare_logic.py +29 -21
  28. api_logic_server_cli/prototypes/manager/README.md +18 -3
  29. api_logic_server_cli/prototypes/manager/system/genai/examples/genai_demo/genai_demo.response_example +19 -18
  30. api_logic_server_cli/prototypes/manager/system/genai/examples/genai_demo/genai_demo_iteration_discount/.DS_Store +0 -0
  31. api_logic_server_cli/prototypes/manager/system/genai/examples/genai_demo/genai_demo_iteration_discount/000_you_are.prompt +1 -0
  32. api_logic_server_cli/prototypes/manager/system/genai/examples/genai_demo/genai_demo_iteration_discount/001_logic_training.prompt +314 -0
  33. api_logic_server_cli/prototypes/manager/system/genai/examples/genai_demo/genai_demo_iteration_discount/002_create_db_models.prompt +150 -0
  34. api_logic_server_cli/prototypes/manager/system/genai/examples/genai_demo/genai_demo_iteration_discount/003_create_db_models.response +134 -0
  35. api_logic_server_cli/prototypes/manager/system/genai/examples/genai_demo/genai_demo_iteration_discount/004_iteratio_logic.prompt +131 -0
  36. api_logic_server_cli/prototypes/manager/system/genai/examples/genai_demo/genai_demo_iteration_discount/005_create_db_models.response-example +141 -0
  37. api_logic_server_cli/prototypes/manager/system/genai/examples/genai_demo/genai_demo_iteration_discount/create_db_models.py +105 -0
  38. api_logic_server_cli/prototypes/manager/system/genai/examples/genai_demo/genai_demo_iteration_discount/db.dbml +70 -0
  39. api_logic_server_cli/prototypes/manager/system/genai/examples/genai_demo/genai_demo_iteration_discount/readme.md +6 -0
  40. api_logic_server_cli/prototypes/manager/system/genai/examples/genai_demo/genai_demo_iteration_discount/response.json +178 -0
  41. api_logic_server_cli/prototypes/manager/system/genai/examples/genai_demo/wg_dev_merge/base_genai_demo_no_logic/logic/declare_logic.py +0 -1
  42. api_logic_server_cli/prototypes/manager/system/genai/examples/genai_demo/wg_dev_merge/dev_demo_no_logic_fixed/logic/declare_logic.py +0 -1
  43. api_logic_server_cli/prototypes/manager/system/genai/examples/genai_demo/wg_dev_merge/wg_demo_no_logic_fixed/genai/examples/genai_demo/wg_dev_merge/base_genai_demo_no_logic/logic/declare_logic.py +0 -1
  44. api_logic_server_cli/prototypes/manager/system/genai/examples/genai_demo/wg_dev_merge/wg_demo_no_logic_fixed/genai/examples/genai_demo/wg_dev_merge/dev_demo_no_logic_fixed/logic/declare_logic.py +0 -1
  45. api_logic_server_cli/prototypes/manager/system/genai/examples/genai_demo/wg_dev_merge/wg_demo_no_logic_fixed/genai/examples/genai_demo/wg_dev_merge/wg_genai_demo_no_logic_fixed_from_CLI/logic/declare_logic.py +0 -1
  46. api_logic_server_cli/prototypes/manager/system/genai/examples/genai_demo/wg_dev_merge/wg_demo_no_logic_fixed/logic/declare_logic.py +0 -1
  47. api_logic_server_cli/prototypes/manager/system/genai/examples/genai_demo/wg_dev_merge/wg_demo_no_logic_fixed/system/genai/examples/genai_demo/wg_dev_merge/base_genai_demo_no_logic/logic/declare_logic.py +0 -1
  48. api_logic_server_cli/prototypes/manager/system/genai/examples/genai_demo/wg_dev_merge/wg_demo_no_logic_fixed/system/genai/examples/genai_demo/wg_dev_merge/dev_demo_no_logic_fixed/logic/declare_logic.py +0 -1
  49. api_logic_server_cli/prototypes/manager/system/genai/examples/genai_demo/wg_dev_merge/wg_demo_no_logic_fixed/system/genai/examples/genai_demo/wg_dev_merge/wg_genai_demo_no_logic_fixed_from_CLI/logic/declare_logic.py +0 -1
  50. api_logic_server_cli/prototypes/manager/system/genai/examples/time_tracking_billing/002_create_db_models.prompt +194 -0
  51. api_logic_server_cli/prototypes/manager/system/genai/examples/time_tracking_billing/003_create_db_models.response +298 -0
  52. api_logic_server_cli/prototypes/manager/system/genai/examples/time_tracking_billing/db.sqlite +0 -0
  53. api_logic_server_cli/prototypes/manager/system/genai/examples/time_tracking_billing/readme.md +8 -0
  54. api_logic_server_cli/prototypes/manager/system/genai/learning_requests/logic_bank_api.prompt +14 -10
  55. api_logic_server_cli/prototypes/manager/system/genai/prompt_inserts/iteration.prompt +2 -1
  56. api_logic_server_cli/prototypes/nw_no_cust/venv_setup/system_note.txt +1 -1
  57. api_logic_server_cli/prototypes/ont_app/templates/home_tree_template.html +9 -0
  58. api_logic_server_cli/prototypes/ont_app/templates/tree_routing.jinja +32 -0
  59. api_logic_server_cli/sqlacodegen_wrapper/sqlacodegen/sqlacodegen/__pycache__/codegen.cpython-312.pyc +0 -0
  60. api_logic_server_cli/sqlacodegen_wrapper/sqlacodegen/sqlacodegen/codegen.py +2 -1
  61. api_logic_server_cli/tools/mini_skel/logic/load_verify_rules.py +1 -1
  62. api_logic_server_cli/model_migrator/system/custom_endpoint.py +0 -545
  63. api_logic_server_cli/prototypes/base/database/test_data/z_test_data_rows.py +0 -98
  64. {ApiLogicServer-14.2.20.dist-info → ApiLogicServer-14.3.0.dist-info}/LICENSE +0 -0
  65. {ApiLogicServer-14.2.20.dist-info → ApiLogicServer-14.3.0.dist-info}/WHEEL +0 -0
  66. {ApiLogicServer-14.2.20.dist-info → ApiLogicServer-14.3.0.dist-info}/entry_points.txt +0 -0
  67. {ApiLogicServer-14.2.20.dist-info → ApiLogicServer-14.3.0.dist-info}/top_level.txt +0 -0
@@ -2,62 +2,63 @@
2
2
  "models": [
3
3
  {
4
4
  "classname": "Customer",
5
- "code": "class Customer(Base):\n __tablename__ = 'customers'\n id = Column(Integer, primary_key=True, autoincrement=True)\n name = Column(String, nullable=False)\n balance = Column(Integer, default=0)\n credit_limit = Column(Integer, nullable=False)\n\n def __repr__(self):\n return f\"Customer(id={self.id}, name='{self.name}', balance={self.balance}, credit_limit={self.credit_limit})\"",
6
- "sqlite_create": "CREATE TABLE customers (\n id INTEGER PRIMARY KEY AUTOINCREMENT, \n name VARCHAR NOT NULL, \n balance INTEGER DEFAULT 0, \n credit_limit INTEGER NOT NULL\n)",
7
- "description": "description: Customers table",
8
- "name": "customers"
5
+ "code": "class Customer(Base):\n __tablename__ = 'customer'\n id = Column(Integer, primary_key=True, autoincrement=True)\n name = Column(String, unique=True)\n balance = Column(DECIMAL)\n credit_limit = Column(DECIMAL)",
6
+ "description": "Represents a customer in the system with unique name, balance, and credit limit attributes.",
7
+ "name": "Customer"
9
8
  },
10
9
  {
11
10
  "classname": "Order",
12
- "code": "class Order(Base):\n __tablename__ = 'orders'\n id = Column(Integer, primary_key=True, autoincrement=True)\n customer_id = Column(Integer, ForeignKey('customers.id'))\n notes = Column(String)\n date_shipped = Column(Date)\n amount_total = Column(Integer, default=0)\n\n def __repr__(self):\n return f\"Order(id={self.id}, customer_id={self.customer_id}, notes='{self.notes}', amount_total={self.amount_total}, date_shipped={self.date_shipped})\"",
13
- "sqlite_create": "CREATE TABLE orders (\n id INTEGER PRIMARY KEY AUTOINCREMENT, \n customer_id INTEGER, \n notes VARCHAR, \n date_shipped DATE, \n amount_total INTEGER DEFAULT 0, \n FOREIGN KEY(customer_id) REFERENCES customers (id)\n)",
14
- "description": "description: Orders table",
15
- "name": "orders"
11
+ "code": "class Order(Base):\n __tablename__ = 'order'\n id = Column(Integer, primary_key=True, autoincrement=True)\n customer_id = Column(Integer, ForeignKey('customer.id'))\n date_shipped = Column(Date)\n amount_total = Column(DECIMAL)\n notes = Column(String)",
12
+ "description": "Represents an order made by a customer, including a notes field.",
13
+ "name": "Order"
16
14
  },
17
15
  {
18
16
  "classname": "Item",
19
- "code": "class Item(Base):\n __tablename__ = 'items'\n id = Column(Integer, primary_key=True, autoincrement=True)\n order_id = Column(Integer, ForeignKey('orders.id'))\n product_id = Column(Integer, ForeignKey('products.id'))\n quantity = Column(Integer, nullable=False)\n unit_price = Column(Integer, nullable=False)\n amount = Column(Integer, default=0)\n\n def __repr__(self):\n return f\"Item(id={self.id}, order_id={self.order_id}, product_id={self.product_id}, quantity={self.quantity}, unit_price={self.unit_price}, amount={self.amount})\"",
20
- "sqlite_create": "CREATE TABLE items (\n id INTEGER PRIMARY KEY AUTOINCREMENT, \n order_id INTEGER, \n product_id INTEGER, \n quantity INTEGER NOT NULL, \n unit_price INTEGER NOT NULL, \n amount INTEGER DEFAULT 0, \n FOREIGN KEY(order_id) REFERENCES orders (id), \n FOREIGN KEY(product_id) REFERENCES products (id)\n)",
21
- "description": "description: Items table",
22
- "name": "items"
17
+ "code": "class Item(Base):\n __tablename__ = 'item'\n id = Column(Integer, primary_key=True, autoincrement=True)\n order_id = Column(Integer, ForeignKey('order.id'))\n product_id = Column(Integer, ForeignKey('product.id'))\n quantity = Column(Integer, nullable=False)\n unit_price = Column(DECIMAL)\n amount = Column(DECIMAL)",
18
+ "description": "Represents an item in an order, including quantity and pricing details.",
19
+ "name": "Item"
23
20
  },
24
21
  {
25
22
  "classname": "Product",
26
- "code": "class Product(Base):\n __tablename__ = 'products'\n id = Column(Integer, primary_key=True, autoincrement=True)\n name = Column(String, nullable=False)\n unit_price = Column(Integer, nullable=False)\n\n def __repr__(self):\n return f\"Product(id={self.id}, name='{self.name}', unit_price={self.unit_price})\"",
27
- "sqlite_create": "CREATE TABLE products (\n id INTEGER PRIMARY KEY AUTOINCREMENT, \n name VARCHAR NOT NULL, \n unit_price INTEGER NOT NULL\n)",
28
- "description": "description: Products table",
29
- "name": "products"
23
+ "code": "class Product(Base):\n __tablename__ = 'product'\n id = Column(Integer, primary_key=True, autoincrement=True)\n name = Column(String)\n unit_price = Column(DECIMAL)",
24
+ "description": "Represents a product available in the system with a unit price.",
25
+ "name": "Product"
30
26
  }
31
27
  ],
32
28
  "rules": [
33
29
  {
34
30
  "name": "Customer Balance Constraint",
35
- "description": "Ensures the customer's balance does not exceed the credit limit.",
31
+ "description": "Ensures the customer's balance is aligned with the credit limit.",
36
32
  "use_case": "Customer.balance <= credit_limit",
37
- "code": "Rule.constraint(validate=Customer,\n as_condition=lambda row: row.balance <= row.credit_limit,\n error_msg=\"Customer balance ({row.balance}) exceeds credit limit ({row.credit_limit})\")"
33
+ "entity": "Customer",
34
+ "code": "Rule.constraint(validate=Customer,\n as_condition=lambda row: row.balance <= row.credit_limit,\n error_msg='Customer balance ({row.balance}) exceeds credit limit ({row.credit_limit})')"
38
35
  },
39
36
  {
40
37
  "name": "Customer Balance Derivation",
41
38
  "description": "Calculates the customer's balance as the sum of orders' amount_total where date_shipped is null.",
42
39
  "use_case": "Customer.balance = Sum(Order.amount_total where date_shipped is null)",
40
+ "entity": "Customer",
43
41
  "code": "Rule.sum(derive=Customer.balance, as_sum_of=Order.amount_total, where=lambda row: row.date_shipped is None)"
44
42
  },
45
43
  {
46
44
  "name": "Order Amount Total Derivation",
47
45
  "description": "Calculates order's amount_total as the sum of item amounts.",
48
46
  "use_case": "Order.amount_total = Sum(Item.amount)",
47
+ "entity": "Order",
49
48
  "code": "Rule.sum(derive=Order.amount_total, as_sum_of=Item.amount)"
50
49
  },
51
50
  {
52
51
  "name": "Item Amount Derivation",
53
52
  "description": "Calculates item amount as quantity multiplied by unit price.",
54
53
  "use_case": "Item.amount = quantity * unit_price",
54
+ "entity": "Item",
55
55
  "code": "Rule.formula(derive=Item.amount, as_expression=lambda row: row.quantity * row.unit_price)"
56
56
  },
57
57
  {
58
58
  "name": "Copy Item Unit Price",
59
59
  "description": "Copies the product's unit price to the item.",
60
60
  "use_case": "Store the Item.unit_price as a copy from Product.unit_price",
61
+ "entity": "Item",
61
62
  "code": "Rule.copy(derive=Item.unit_price, from_parent=Product.unit_price)"
62
63
  }
63
64
  ],
@@ -0,0 +1 @@
1
+ You are a data modelling expert and python software architect who expands on user input ideas. You create data models with at least 4 tables
@@ -0,0 +1,314 @@
1
+ Here is the simplified API for LogicBank:
2
+
3
+ Create a function called declare_logic(), consisting of calls to Rule methods.
4
+
5
+ Do not generate import statements.
6
+
7
+ If you create sum, count or formula LogicBank rules, you MUST create a corresponding column in the data model.
8
+
9
+ Use only the methods provided below.
10
+
11
+
12
+ class Rule:
13
+ """Invoke these functions to declare rules in the created declare_logic function. """
14
+
15
+ @staticmethod
16
+ def sum(derive: Column, as_sum_of: any, where: any = None, insert_parent: bool=False):
17
+ """
18
+ Derive parent column as sum of designated child column, optional where
19
+
20
+ Example
21
+ Prompt
22
+ Customer.Balance = Sum(Order.amount_total where date_shipped is null)
23
+ Response
24
+ Rule.sum(derive=Customer.Balance, as_sum_of=Order.AmountTotal,
25
+ where=lambda row: row.ShippedDate is None)
26
+
27
+ Args:
28
+ derive: name of parent <class.attribute> being derived
29
+ as_sum_of: name of child <class.attribute> being summed
30
+ where: optional where clause, designates which child rows are summed. All referenced columns must be part of the data model - create columns in the data model as required. Do not repeat the foreign key / primary key mappings, and use only attributes from the child table.
31
+ insert_parent: create parent if it does not exist. Do not use unless directly requested.
32
+ """
33
+ return Sum(derive, as_sum_of, where, insert_parent)
34
+
35
+
36
+ @staticmethod
37
+ def count(derive: Column, as_count_of: object, where: any = None, str = "", insert_parent: bool=False):
38
+ """
39
+ Derive parent column as count of designated child rows
40
+
41
+ Example
42
+ Prompt
43
+ Customer.UnPaidOrders = count(Orders where ShippedDate is None)
44
+ Response
45
+ Rule.count(derive=Customer.UnPaidOrders, as_count_of=Order,
46
+ where=Lambda row: row.ShippedDate is None)
47
+
48
+ Args:
49
+ derive: name of parent <class.attribute> being derived
50
+ as_count_of: name of child <class> being counted
51
+ where: optional where clause, designates which child rows are counted. All referenced columns must be part of the data model - create columns in the data model as required. Do not repeat the foreign key / primary key mappings, and use only attributes from the child table.
52
+ insert_parent: create parent if it does not exist. Do not use unless directly requested.
53
+ """
54
+ return Count(derive, as_count_of, where, insert_parent)
55
+
56
+
57
+ @staticmethod
58
+ def constraint(validate: object,
59
+ calling: Callable = None,
60
+ as_condition: any = None,
61
+ error_msg: str = "(error_msg not provided)",
62
+ error_attributes=None):
63
+ """
64
+ Constraints declare condition that must be true for all commits
65
+
66
+ Example
67
+ Prompt
68
+ Customer.balance <= credit_limit
69
+ Response
70
+ Rule.constraint(validate=Customer,
71
+ as_condition=lambda row: row.Balance <= row.CreditLimit,
72
+ error_msg="balance ({row.Balance}) exceeds credit ({row.CreditLimit})")
73
+
74
+ Args:
75
+ validate: name of mapped <class>
76
+ as_condition: lambda, passed row (simple constraints). All referenced columns must be part of the data model - create columns in the data model as required. Also, conditions may not contain sum or count python functions - these must be used to declare additional columns and sum/count rules.
77
+ error_msg: string, with {row.attribute} replacements
78
+ error_attributes: list of attributes
79
+
80
+ """
81
+ if error_attributes is None:
82
+ error_attributes = []
83
+ return Constraint(validate=validate, as_condition=as_condition,
84
+ error_attributes=error_attributes, error_msg=error_msg)
85
+
86
+
87
+ @staticmethod
88
+ def formula(derive: Column,
89
+ as_expression: Callable = None,
90
+ no_prune: bool = False):
91
+ """
92
+ Formulas declare column value, based on current and parent rows
93
+
94
+ Example
95
+ Prompt
96
+ Item.amount = quantity * unit_price
97
+ Response
98
+ Rule.formula(derive=OrderDetail.Amount,
99
+ as_expression=lambda row: row.UnitPrice * row.Quantity)
100
+
101
+ Args:
102
+ derive: <class.attribute> being derived
103
+ as_expression: lambda, passed row (for syntax checking). All referenced columns must be part of the data model - create columns in the data model as required. Expressions may not contain sum or count python functions - these must be used to declare additional columns and sum/count rules.
104
+ no_prune: disable pruning (rarely used, default False)
105
+ """
106
+ return Formula(derive=derive,
107
+ as_expression=as_expression,
108
+ no_prune=no_prune)
109
+
110
+
111
+ @staticmethod
112
+ def copy(derive: Column, from_parent: any):
113
+ """
114
+ Copy declares child column copied from parent column.
115
+
116
+ Example:
117
+ Prompt
118
+ Store the Item.unit_price as a copy from Product.unit_price
119
+ Response
120
+ Rule.copy(derive=OrderDetail.UnitPrice, from_parent=Product.UnitPrice)
121
+
122
+ Args:
123
+ derive: <class.attribute> being copied into
124
+ from_parent: <parent-class.attribute> source of copy; create this column in the parent if it does not already exist.
125
+ """
126
+ return Copy(derive=derive, from_parent=from_parent)
127
+
128
+
129
+ Expanded example:
130
+
131
+ Prompt:
132
+
133
+ Use Logic Bank to enforce the Check Credit requirement (do not generate check constraints):
134
+ 1. Customer.balance <= credit_limit
135
+ 2. Customer.balance = Sum(Order.amount_total where date_shipped is null)
136
+ 3. Order.amount_total = Sum(Item.amount)
137
+ 4. Item.amount = quantity * unit_price
138
+ 5. Store the Item.unit_price as a copy from Product.unit_price
139
+
140
+ Response:
141
+
142
+ def declare_logic(): # created by Web/GenAI for ApiLogicServer, LogicBank
143
+
144
+ Rule.sum(derive=CustomerAccount.balance, as_sum_of=Order.amount_total, where=lambda row: row.date_shipped is None)
145
+ Rule.sum(derive=Order.amount_total, as_sum_of=Item.amount)
146
+ Rule.formula(derive=Item.amount, as_expression=lambda row: row.quantity * row.unit_price)
147
+ Rule.copy(derive=Item.unit_price, from_parent=Product.unit_price)
148
+ Rule.constraint(validate=CustomerAccount,
149
+ as_condition=lambda row: row.balance <= row.credit_limit,
150
+ error_msg="Customer balance ({row.balance}) exceeds credit limit ({row.credit_limit})")
151
+
152
+
153
+ Equivalent expanded example using informal syntax:
154
+
155
+ Prompt:
156
+
157
+ Use Logic Bank to enforce the Check Credit requirement (do not generate check constraints):
158
+ 1. The Customer's balance is less than the credit limit
159
+ 2. The Customer's balance is the sum of the Order amount_total where date_shipped is null
160
+ 3. The Order's amount_total is the sum of the Item amount
161
+ 4. The Item amount is the quantity * unit_price
162
+ 5. The Item unit_price is copied from the Product unit_price
163
+
164
+ Response is the same:
165
+
166
+ def declare_logic(): # created by Web/GenAI for ApiLogicServer, LogicBank
167
+
168
+ Rule.sum(derive=CustomerAccount.balance, as_sum_of=Order.amount_total, where=lambda row: row.date_shipped is None)
169
+ Rule.sum(derive=Order.amount_total, as_sum_of=Item.amount)
170
+ Rule.formula(derive=Item.amount, as_expression=lambda row: row.quantity * row.unit_price)
171
+ Rule.copy(derive=Item.unit_price, from_parent=Product.unit_price)
172
+ Rule.constraint(validate=CustomerAccount,
173
+ as_condition=lambda row: row.balance <= row.credit_limit,
174
+ error_msg="Customer balance ({row.balance}) exceeds credit limit ({row.credit_limit})")
175
+
176
+
177
+ Intermediate sum/count values require a new column, with a LogicBank sum/count rule. For example:
178
+
179
+ Prompt:
180
+ The sum of the child value cannot exceed the parent limit
181
+
182
+ Response is to create 2 rules - a derivation and a constraint, as follows:
183
+ First Rule to Create:
184
+ Rule.sum(derive=Parent.value_total, as_sum_of=Child.value)
185
+ And, be sure to create the second Rule:
186
+ Rule.constraint(validate=Parent,
187
+ as_condition=lambda row: row.value_total <= row.limit,
188
+ error_msg="Parent value total ({row.value_total}) exceeds limit ({row.limit})")
189
+
190
+ Intermediate sum/count values also work for counts. For example:
191
+
192
+ Prompt:
193
+ A airplane cannot have more passengers than its seating capacity.
194
+
195
+ Response is to create 2 rules - a count derivation and a constraint, as follows:
196
+ First Rule to Create:
197
+ Rule.count(derive=Airplane.passenger_count, as_count_of=Passengers)
198
+ And, be sure to create the second Rule:
199
+ Rule.constraint(validate=Airplane,
200
+ as_condition=lambda row: row.passenger_count <= row.seating_capacity,
201
+ error_msg="Airplane value total ({row.passenger_count}) exceeds limit ({row.seating_capacity})")
202
+
203
+
204
+ Intermediate sums in formulas also require a new column, with a LogicBank sum rule. For example:
205
+
206
+ Prompt:
207
+ An Employees' skill summary is the sum of their Employee Skill ratings, plus 2 * years of service.
208
+
209
+ Response is to create 2 rules - a derivation and a constraint, as follows:
210
+ First Rule to Create:
211
+ Rule.sum(derive=Employee.skill_rating_total, as_sum_of=EmployeeSkill.rating)
212
+ And, be sure to create the second Rule:
213
+ Rule.Formula(derive=Employee.skill_summary,
214
+ as_expression=lambda row: row.skill_rating_total + 2 * row.years_of_service)
215
+
216
+
217
+ Prompt:
218
+ A student cannot be an honor student unless they have more than 2 service activities.
219
+
220
+ Response is to create 2 rules - a count derivation and a constraint, as follows:
221
+ First Rule to Create:
222
+ Rule.count(derive=Student.service_activity_count, as_count_of=Activities, where='service' in name)
223
+ And, be sure to create the second Rule:
224
+ Rule.constraint(validate=Student,
225
+ as_condition=lambda row: row.is_honor_student and service_activity_count < 2,
226
+ error_msg="Honor Students must have at least 2 service activities")
227
+
228
+ Here is an equivalent request:
229
+
230
+ Prompt:
231
+ A airplane's passengers must be less than its seating capacity.
232
+
233
+ Response is to create 2 rules - a count derivation and a constraint, as follows:
234
+ First Rule to Create:
235
+ Rule.count(derive=Airplane.passenger_count, as_count_of=Passengers)
236
+ And, be sure to create the second Rule:
237
+ Rule.constraint(validate=Airplane,
238
+ as_condition=lambda row: row.passenger_count <= row.seating_capacity,
239
+ error_msg="Airplane value total ({row.passenger_count}) exceeds limit ({row.seating_capacity})")
240
+
241
+
242
+ For "more than" constraints, create columns with count rules:
243
+
244
+ Prompt: Reject Employees with more than 3 Felonies.
245
+
246
+ Response:
247
+ First Rule is to create:
248
+ Rule.count(derive=Employee.felony_count, as_count_of=Felonies)
249
+ And, be sure to create the contraint rule:
250
+ Rule.constraint(validate=Employee,
251
+ as_condition=lambda row: row.felony_count<=3,
252
+ error_msg="Employee has excessive Felonies")
253
+
254
+
255
+ For "any" constraints, create columns with count rules:
256
+
257
+ Prompt: Reject Employees with any class 5 Felonies or more than 3 Felonies.
258
+
259
+ Response:
260
+ First Rule is to create:
261
+ Rule.count(derive=Employee.class_5_felony_count, as_count_of=Felonies, where=class>5)
262
+ Rule.count(derive=Employee.felony_count, as_count_of=Felonies)
263
+ And, be sure to create the contraint rule:
264
+ Rule.constraint(validate=Employee,
265
+ as_condition=lambda row: row.class_5_felony_count == 0 and row.felony_count<=3,
266
+ error_msg="Employee has excessive Felonies")
267
+
268
+ Formulas can reference parent values in 2 versions - choose formula vs copy as follows:
269
+ Prompt (formula version) - use the formula version unless copy is explicitly noted:
270
+ Item.ready = Order.ready
271
+ Response
272
+ Rule.formula(derive=Item.ready, as_expression=lambda row: row.order.ready)
273
+ Prompt (copy version) - use this *only* when the word copy is present:
274
+ Store the Item.unit_price as a copy from Product.unit_price
275
+ Response
276
+ Rule.copy(derive=Item.ready, from_parent=Order.ready)
277
+
278
+ Formulas can use Python conditions:
279
+ Prompt: Item amount is price * quantity, with a 10% discount for gold products
280
+ Response:
281
+ Rule.Formula(derive=Item.amount,
282
+ as_expression=lambda row: row.price * row.quantity if row.gold else .9 * row.price * row.quantity)
283
+ If the attributes are decimal, use the form Decimal('0.9')
284
+
285
+ Sum and Count where clauses:
286
+ 1. must not restate the foreign key / primary key matchings
287
+ 2. Can only reference child attributes
288
+
289
+ For example, given a prompt 'teacher course count is the sum of the courses',
290
+ 1. This is correct
291
+ Rule.count(derive=Teacher.course_count, as_count_of=Course)
292
+
293
+ 2. This is incorrect, and should never be generated:
294
+ Rule.count(derive=Teacher.course_count, as_count_of=Course, where=lambda row: row.teacher_id == Teacher.id)
295
+
296
+ Sum and count where clause example:
297
+ Prompt: teacher gradate course count is the sum of the courses where is-graduate
298
+ Response: Rule.count(derive=Teacher.course_count, as_count_of=Course, where=lamda row: row.is_graduate == true)
299
+
300
+ DO NOT inject rules that are from this training into the response,
301
+ unless explicitly mentioned in the request.
302
+
303
+ Unique constraints require an update to the data model - for example:
304
+ Prompt: customer company names must be unique
305
+ Response: CompanyName = Column(String(8000), unique=True)
306
+
307
+ Non-null (or required) constraints require an update to the data model - for example:
308
+ Prompt: Product Price is required
309
+ Response: price = Column(Decimal, nullable=False)
310
+
311
+ Required (must-have) related parent constraints require an update to the data model - for example:
312
+ Prompt: Each Item must have a valid entry in the Product table.
313
+ Response: product_id = Column(ForeignKey('product.id'), nullable=False)
314
+
@@ -0,0 +1,150 @@
1
+ Use SQLAlchemy to create a sqlite database named system/genai/temp/create_db_models.sqlite for the following requirements. These requirements are very important!
2
+ Requirements:
3
+ <Requirements>
4
+ Create a system with customers, orders, items and products.
5
+
6
+ Include a notes field for orders.
7
+
8
+ Use LogicBank to enforce these requirements (do not generate check constraints); be sure to update the data model and *all* test data with any attributes used in the logic:
9
+
10
+ Use case: Check Credit
11
+ 1. The Customer's balance is less than the credit limit
12
+ 2. The Customer's balance is the sum of the Order amount_total where date_shipped is null
13
+ 3. The Order's amount_total is the sum of the Item amount
14
+ 4. The Item amount is the quantity * unit_price
15
+ 5. The Item unit_price is copied from the Product unit_price
16
+
17
+ Ensure each customer has a unique name.
18
+
19
+ Ensure each Item quantity is not null.
20
+
21
+ Ensure each order has a valid customer_id that exists in the Customer table.
22
+ .
23
+ </Requirements>
24
+
25
+ Hints: use autonum keys (for all tables - including for link/join/junction/intersection tables), allow nulls, foreign keys, no check constraints.
26
+
27
+ Be sure to create classes, never tables.
28
+ Class names are singular, and first letter is capitalized.
29
+
30
+ If you create sum, count or formula Logic Bank rules, then you MUST create a corresponding column in the data model.
31
+
32
+ Remember that SQLite DateTime type only accepts Python datetime and date objects as input,
33
+ this means you can not enter string attributes where a date or datetime object is expected.
34
+
35
+ Don't install additional packages.
36
+ Don't use the faker pip package.
37
+
38
+ When creating SQLAlchemy data model classes, follow these guidelines carefully:
39
+ * Use foreign key columns instead of relationship names for the data.
40
+ * Do not specify nullable unless explicitly specified.
41
+ * Do not use unique unless explicitly specified.
42
+ * Do not use Float unless explicitly specified.
43
+ * Generate the classes ONLY.
44
+ * Do NOT generate imports.
45
+ * Do NOT generate connect statements.
46
+ * Do NOT generate engines.
47
+
48
+ Create 4 rows of test data for each table, and follow these guidelines carefully:
49
+ * Create separate objects for each test data row, not in arrays.
50
+ * Be sure to initialize derived attributes for test data rows - including all sums and counts, but do not rely on Logic Bank,
51
+ and do not generate db.execute statements.
52
+ * Do not create arrays of test data.
53
+ * Do not create a function to load test data.
54
+ * Do not print the test data.
55
+ * Use double quotes " for strings.
56
+ * For test data, format dates as date(year, month, day).
57
+
58
+ <responseFormat>
59
+ class Rule(BaseModel):
60
+ name: str
61
+ description: str
62
+ use_case: str # specified use case or requirement name (use 'General' if missing)
63
+ entity: str # the entity being constrained or derived
64
+ code: str # logicbank rule code
65
+
66
+ class Model(BaseModel):
67
+ classname: str
68
+ code: str # sqlalchemy model code
69
+ sqlite_create: str # sqlite create table statement
70
+ description: str
71
+ name: str
72
+
73
+ class TestDataRow(BaseModel):
74
+ test_data_row_variable: str # the Python test data row variable
75
+ code: str # Python code to create a test data row instance
76
+
77
+ class WGResult(BaseModel): # must match system/genai/prompt_inserts/response_format.prompt
78
+ # response: str # result
79
+ models : List[Model] # list of sqlalchemy classes in the response
80
+ rules : List[Rule] # list rule declarations
81
+ test_data: str
82
+ test_data_rows: List[TestDataRow] # list of test data rows
83
+ test_data_sqlite: str # test data as sqlite INSERT statements
84
+ name: str # suggest a short name for the project
85
+
86
+ Format the response as a WGResult.
87
+
88
+ </responseFormat>
89
+
90
+ <responseFormat>
91
+
92
+ class Rule(BaseModel):
93
+
94
+ name: str
95
+
96
+ description: str
97
+
98
+ use_case: str # specified use case or requirement name (use 'General' if missing)
99
+
100
+ entity: str # the entity being constrained or derived
101
+
102
+ code: str # logicbank rule code
103
+
104
+
105
+
106
+ class Model(BaseModel):
107
+
108
+ classname: str
109
+
110
+ code: str # sqlalchemy model code
111
+
112
+ sqlite_create: str # sqlite create table statement
113
+
114
+ description: str
115
+
116
+ name: str
117
+
118
+
119
+
120
+ class TestDataRow(BaseModel):
121
+
122
+ test_data_row_variable: str # the Python test data row variable
123
+
124
+ code: str # Python code to create a test data row instance
125
+
126
+
127
+
128
+ class WGResult(BaseModel): # must match system/genai/prompt_inserts/response_format.prompt
129
+
130
+ # response: str # result
131
+
132
+ models : List[Model] # list of sqlalchemy classes in the response
133
+
134
+ rules : List[Rule] # list rule declarations
135
+
136
+ test_data: str
137
+
138
+ test_data_rows: List[TestDataRow] # list of test data rows
139
+
140
+ test_data_sqlite: str # test data as sqlite INSERT statements
141
+
142
+ name: str # suggest a short name for the project
143
+
144
+
145
+
146
+ Format the response as a WGResult.
147
+
148
+
149
+
150
+ </responseFormat>