ApiLogicServer 12.0.4__py3-none-any.whl → 12.1.26__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 (66) hide show
  1. {ApiLogicServer-12.0.4.dist-info → ApiLogicServer-12.1.26.dist-info}/METADATA +2 -1
  2. {ApiLogicServer-12.0.4.dist-info → ApiLogicServer-12.1.26.dist-info}/RECORD +63 -40
  3. {ApiLogicServer-12.0.4.dist-info → ApiLogicServer-12.1.26.dist-info}/WHEEL +1 -1
  4. api_logic_server_cli/api_logic_server.py +23 -204
  5. api_logic_server_cli/api_logic_server_info.yaml +2 -2
  6. api_logic_server_cli/cli.py +25 -84
  7. api_logic_server_cli/cli_args_base.py +2 -0
  8. api_logic_server_cli/cli_args_project.py +9 -3
  9. api_logic_server_cli/create_from_model/__pycache__/dbml.cpython-312.pyc +0 -0
  10. api_logic_server_cli/create_from_model/__pycache__/meta_model.cpython-312.pyc +0 -0
  11. api_logic_server_cli/create_from_model/__pycache__/model_creation_services.cpython-312.pyc +0 -0
  12. api_logic_server_cli/create_from_model/__pycache__/ont_create.cpython-312.pyc +0 -0
  13. api_logic_server_cli/create_from_model/__pycache__/ui_admin_creator.cpython-312.pyc +0 -0
  14. api_logic_server_cli/create_from_model/meta_model.py +1 -1
  15. api_logic_server_cli/create_from_model/model_creation_services.py +3 -1
  16. api_logic_server_cli/create_from_model/ont_create.py +3 -1
  17. api_logic_server_cli/create_from_model/ui_admin_creator.py +6 -4
  18. api_logic_server_cli/genai.py +420 -198
  19. api_logic_server_cli/logging.yml +5 -0
  20. api_logic_server_cli/prototypes/.DS_Store +0 -0
  21. api_logic_server_cli/prototypes/base/api_logic_server_run.py +0 -2
  22. api_logic_server_cli/prototypes/base/config/server_setup.py +15 -1
  23. api_logic_server_cli/prototypes/base/integration/kafka/kafka_consumer.py +1 -1
  24. api_logic_server_cli/prototypes/base/integration/kafka/kafka_producer.py +1 -1
  25. api_logic_server_cli/prototypes/base/readme.md +21 -8
  26. api_logic_server_cli/prototypes/genai_demo/logic/declare_logic.py +11 -12
  27. api_logic_server_cli/prototypes/manager/.DS_Store +0 -0
  28. api_logic_server_cli/prototypes/manager/.vscode/.DS_Store +0 -0
  29. api_logic_server_cli/prototypes/manager/.vscode/launch.json +98 -1
  30. api_logic_server_cli/prototypes/manager/README.md +40 -3
  31. api_logic_server_cli/prototypes/manager/system/.DS_Store +0 -0
  32. api_logic_server_cli/prototypes/manager/system/genai/.DS_Store +0 -0
  33. api_logic_server_cli/prototypes/manager/system/genai/create_db_models_inserts/create_db_models_create_db.py +11 -0
  34. api_logic_server_cli/prototypes/manager/system/genai/create_db_models_inserts/create_db_models_imports.py +22 -0
  35. api_logic_server_cli/prototypes/manager/system/genai/create_db_models_inserts/create_db_models_test_data.py +7 -0
  36. api_logic_server_cli/prototypes/manager/system/genai/examples/emp_depts/emp_dept.prompt +4 -0
  37. api_logic_server_cli/prototypes/manager/system/genai/examples/genai_demo/genai_demo.prompt +1 -1
  38. api_logic_server_cli/prototypes/manager/system/genai/examples/genai_demo/genai_demo.response_example +133 -130
  39. api_logic_server_cli/prototypes/manager/system/genai/examples/genai_demo/genai_demo_informal.prompt +10 -0
  40. api_logic_server_cli/prototypes/manager/system/genai/examples/genai_demo/genai_demo_iterative_logic/genai_demo_iterative_logic_000.response +1 -0
  41. api_logic_server_cli/prototypes/manager/system/genai/examples/genai_demo/genai_demo_iterative_logic/genai_demo_iterative_logic_001.prompt +171 -0
  42. api_logic_server_cli/prototypes/manager/system/genai/examples/genai_demo/genai_demo_iterative_logic/genai_demo_iterative_logic_002.prompt +21 -0
  43. api_logic_server_cli/prototypes/manager/system/genai/examples/genai_demo/genai_demo_iterative_logic/genai_demo_iterative_logic_003.response +94 -0
  44. api_logic_server_cli/prototypes/manager/system/genai/examples/genai_demo/genai_demo_iterative_logic/genai_demo_iterative_logic_004.prompt +6 -0
  45. api_logic_server_cli/prototypes/manager/system/genai/examples/genai_demo/genai_demo_iterative_logic/genai_demo_iterative_logic_005.response_example +122 -0
  46. api_logic_server_cli/prototypes/manager/system/genai/learning_requests/logic_bank_api.prompt +162 -12
  47. api_logic_server_cli/prototypes/manager/system/genai/prompt_inserts/.DS_Store +0 -0
  48. api_logic_server_cli/prototypes/manager/system/genai/prompt_inserts/logic_inserts.prompt +1 -0
  49. api_logic_server_cli/prototypes/manager/system/genai/prompt_inserts/response_format.prompt +30 -0
  50. api_logic_server_cli/prototypes/manager/system/genai/prompt_inserts/sqlite_inserts.prompt +17 -2
  51. api_logic_server_cli/prototypes/manager/system/genai/prompt_inserts/zsqlite_inserts_iterations.prompt +28 -0
  52. api_logic_server_cli/prototypes/manager/system/genai/retry/conv/create_db_models.py +96 -0
  53. api_logic_server_cli/prototypes/manager/system/genai/retry/conv/inf-1_iter_1_1_000.response +1 -0
  54. api_logic_server_cli/prototypes/manager/system/genai/retry/conv/inf-1_iter_1_1_001.prompt +208 -0
  55. api_logic_server_cli/prototypes/manager/system/genai/retry/conv/inf-1_iter_1_1_002.prompt +89 -0
  56. api_logic_server_cli/prototypes/manager/system/genai/retry/conv/inf-1_iter_1_1_003.prompt +40 -0
  57. api_logic_server_cli/prototypes/manager/system/genai/retry/conv/inf-1_iter_1_1_004.response +57 -0
  58. api_logic_server_cli/prototypes/manager/system/genai/retry/conv/inf-1_iter_1_1_005.response +57 -0
  59. api_logic_server_cli/prototypes/manager/system/genai/retry/readme.md +1 -0
  60. api_logic_server_cli/prototypes/manager/system/genai/retry/retry.response +57 -0
  61. api_logic_server_cli/prototypes/manager/system/genai/examples/emp_depts/emp_dept_explicit.prompt +0 -7
  62. api_logic_server_cli/prototypes/manager/system/genai/examples/emp_depts/emp_dept_implicit_fails.prompt +0 -5
  63. api_logic_server_cli/prototypes/manager/system/secrets.txt +0 -6
  64. {ApiLogicServer-12.0.4.dist-info → ApiLogicServer-12.1.26.dist-info}/LICENSE +0 -0
  65. {ApiLogicServer-12.0.4.dist-info → ApiLogicServer-12.1.26.dist-info}/entry_points.txt +0 -0
  66. {ApiLogicServer-12.0.4.dist-info → ApiLogicServer-12.1.26.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,122 @@
1
+ Certainly! Let's incorporate the business logic using LogicBank, ensuring we add any necessary derived attributes to our model and adjust the test data accordingly. We'll also include the function `declare_logic` which utilizes LogicBank rules.
2
+
3
+ ```python
4
+ from sqlalchemy import create_engine, Column, Integer, String, Float, ForeignKey, Date
5
+ from sqlalchemy.ext.declarative import declarative_base
6
+ from sqlalchemy.orm import sessionmaker
7
+ from datetime import datetime
8
+
9
+ Base = declarative_base()
10
+
11
+
12
+ class Customer(Base):
13
+ """
14
+ description: Table for storing customer information.
15
+ """
16
+ __tablename__ = 'customers'
17
+
18
+ id = Column(Integer, primary_key=True, autoincrement=True)
19
+ name = Column(String, nullable=True)
20
+ credit_limit = Column(Float, nullable=True)
21
+ balance = Column(Float, default=0.0) # Added for logic rule
22
+
23
+
24
+ class Order(Base):
25
+ """
26
+ description: Table for orders linked to customers.
27
+ """
28
+ __tablename__ = 'orders'
29
+
30
+ id = Column(Integer, primary_key=True, autoincrement=True)
31
+ customer_id = Column(Integer, ForeignKey('customers.id'), nullable=True)
32
+ date_shipped = Column(Date, nullable=True)
33
+ notes = Column(String, nullable=True)
34
+ amount_total = Column(Float, default=0.0) # Added for logic rule
35
+
36
+
37
+ class Product(Base):
38
+ """
39
+ description: Table for products.
40
+ """
41
+ __tablename__ = 'products'
42
+
43
+ id = Column(Integer, primary_key=True, autoincrement=True)
44
+ name = Column(String, nullable=True)
45
+ unit_price = Column(Float, nullable=True)
46
+
47
+
48
+ class Item(Base):
49
+ """
50
+ description: Table for items linked to orders and products.
51
+ """
52
+ __tablename__ = 'items'
53
+
54
+ id = Column(Integer, primary_key=True, autoincrement=True)
55
+ order_id = Column(Integer, ForeignKey('orders.id'), nullable=True)
56
+ product_id = Column(Integer, ForeignKey('products.id'), nullable=True)
57
+ quantity = Column(Integer, nullable=True)
58
+ unit_price = Column(Float, nullable=True) # Added for logic rule
59
+ amount = Column(Float, default=0.0) # Added for logic rule
60
+
61
+
62
+ # Create an SQLite database
63
+ engine = create_engine('sqlite:///system/genai/temp/create_db_models.sqlite')
64
+ Base.metadata.create_all(engine)
65
+
66
+ Session = sessionmaker(bind=engine)
67
+ session = Session()
68
+
69
+ # Creating test data for tables
70
+ customer1 = Customer(name="John Doe", credit_limit=5000.0, balance=0.0)
71
+ customer2 = Customer(name="Jane Smith", credit_limit=10000.0, balance=0.0)
72
+ session.add_all([customer1, customer2])
73
+ session.commit()
74
+
75
+ order1 = Order(customer_id=customer1.id, date_shipped=None, notes="Express delivery", amount_total=0.0)
76
+ order2 = Order(customer_id=customer2.id, date_shipped=datetime.now().date(), notes="Standard delivery", amount_total=0.0)
77
+ session.add_all([order1, order2])
78
+ session.commit()
79
+
80
+ product1 = Product(name="Laptop", unit_price=1000.0)
81
+ product2 = Product(name="Smartphone", unit_price=500.0)
82
+ session.add_all([product1, product2])
83
+ session.commit()
84
+
85
+ item1 = Item(order_id=order1.id, product_id=product1.id, quantity=2, unit_price=1000.0, amount=2000.0)
86
+ item2 = Item(order_id=order1.id, product_id=product2.id, quantity=3, unit_price=500.0, amount=1500.0)
87
+ item3 = Item(order_id=order2.id, product_id=product2.id, quantity=1, unit_price=500.0, amount=500.0)
88
+ session.add_all([item1, item2, item3])
89
+ session.commit()
90
+
91
+
92
+ def declare_logic():
93
+ Rule.sum(derive=Customer.balance, as_sum_of=Order.amount_total, where=lambda row: row.date_shipped is None)
94
+ Rule.sum(derive=Order.amount_total, as_sum_of=Item.amount)
95
+ Rule.formula(derive=Item.amount, as_expression=lambda row: row.quantity * row.unit_price)
96
+ Rule.copy(derive=Item.unit_price, from_parent=Product.unit_price)
97
+ Rule.constraint(validate=Customer,
98
+ as_condition=lambda row: row.balance <= row.credit_limit,
99
+ error_msg="Customer balance ({row.balance}) exceeds credit limit ({row.credit_limit})")
100
+
101
+ ```
102
+
103
+ ### Explanation of Changes and Additions:
104
+
105
+ - **Data Model Updates**:
106
+ - Added `balance` to `Customer` to support business rules.
107
+ - Added `amount_total` to `Order` for summation logic.
108
+ - Added `unit_price` and `amount` to `Item` for business logic involving calculations and copying.
109
+
110
+ - **Test Data Updates**:
111
+ - Initialized `balance` and `amount_total` manually since we're relying on LogicBank for automatic updates.
112
+ - Set `unit_price` and `amount` for each item directly based on test data consistency with products and orders.
113
+
114
+ - **Business Logic (LogicBank)**:
115
+ - Implemented `declare_logic` function using LogicBank to define rules:
116
+ - Calculate `Customer.balance` as the sum of pending `Order.amount_total`.
117
+ - Sum `Order.amount_total` from `Item.amount`.
118
+ - Calculate `Item.amount` using `quantity * unit_price`.
119
+ - Copy `Product.unit_price` to `Item.unit_price`.
120
+ - Constraint to ensure `Customer.balance` does not exceed `credit_limit`.
121
+
122
+ By following these guidelines, the data model is prepared with a skeleton for logical integrity checks and value derivations, mirroring the application requirements without executing the logic directly in the database.
@@ -4,6 +4,8 @@ Create a function called declare_logic(), consisting of calls to Rule methods.
4
4
 
5
5
  Do not generate import statements.
6
6
 
7
+ If you create sum, count or formula LogicBank rules, you MUST create a corresponding column in the data model.
8
+
7
9
  Use only the methods provided below.
8
10
 
9
11
  class Rule:
@@ -25,8 +27,8 @@ class Rule:
25
27
  derive: name of parent <class.attribute> being derived
26
28
  as_sum_of: name of child <class.attribute> being summed
27
29
  child_role_name: parent's child accessor attribute (required only for disambiguation)
28
- where: optional where clause, designates which child rows are summed
29
-
30
+ where: optional where clause, designates which child rows are summed. 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.
30
32
  """
31
33
  return Sum(derive, as_sum_of, where, child_role_name, insert_parent)
32
34
 
@@ -46,7 +48,8 @@ class Rule:
46
48
  derive: name of parent <class.attribute> being derived
47
49
  as_count_of: name of child <class> being counted
48
50
  child_role_name: parent's child accessor attribute (required only for disambiguation)
49
- where: optional where clause, designates which child rows are counted
51
+ where: optional where clause, designates which child rows are counted. 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.
50
53
  """
51
54
  return Count(derive, as_count_of, where, child_role_name, insert_parent)
52
55
 
@@ -69,7 +72,7 @@ class Rule:
69
72
 
70
73
  Args:
71
74
  validate: name of mapped <class>
72
- as_condition: lambda, passed row (simple constraints)
75
+ as_condition: lambda, passed row (simple constraints). Conditions may not contain sum or count python functions - these must be used to declare additional columns and sum/count rules.
73
76
  error_msg: string, with {row.attribute} replacements
74
77
  error_attributes: list of attributes
75
78
 
@@ -122,7 +125,7 @@ class Rule:
122
125
 
123
126
  Args:
124
127
  derive: <class.attribute> being derived
125
- as_expression: lambda, passed row (for syntax checking)
128
+ as_expression: lambda, passed row (for syntax checking). Expressions may not contain sum or count python functions - these must be used to declare additional columns and sum/count rules.
126
129
  no_prune: disable pruning (rarely used, default False)
127
130
  """
128
131
  return Formula(derive=derive,
@@ -132,7 +135,7 @@ class Rule:
132
135
  @staticmethod
133
136
  def copy(derive: Column, from_parent: any):
134
137
  """
135
- Copy declares child column copied from parent column
138
+ Copy declares child column copied from parent column.
136
139
 
137
140
  Example
138
141
  Prompt
@@ -142,7 +145,7 @@ class Rule:
142
145
 
143
146
  Args:
144
147
  derive: <class.attribute> being copied into
145
- from_parent: <parent-class.attribute> source of copy
148
+ from_parent: <parent-class.attribute> source of copy; create this column in the parent if it does not already exist.
146
149
  """
147
150
  return Copy(derive=derive, from_parent=from_parent)
148
151
 
@@ -152,11 +155,11 @@ Expanded example:
152
155
  Prompt:
153
156
 
154
157
  Use Logic Bank to enforce the Check Credit requirement (do not generate check constraints):
155
- 1. Customer.balance <= credit_limit
156
- 2. Customer.balance = Sum(Order.amount_total where date_shipped is null)
157
- 3. Order.amount_total = Sum(Item.amount)
158
- 4. Item.amount = quantity * unit_price
159
- 5. Store the Item.unit_price as a copy from Product.unit_price
158
+ 1. Customer.balance <= credit_limit
159
+ 2. Customer.balance = Sum(Order.amount_total where date_shipped is null)
160
+ 3. Order.amount_total = Sum(Item.amount)
161
+ 4. Item.amount = quantity * unit_price
162
+ 5. Store the Item.unit_price as a copy from Product.unit_price
160
163
 
161
164
  Response:
162
165
 
@@ -169,3 +172,150 @@ def declare_logic(): # created by Web/GenAI for ApiLogicServer, LogicBank
169
172
  Rule.constraint(validate=CustomerAccount,
170
173
  as_condition=lambda row: row.balance <= row.credit_limit,
171
174
  error_msg="Customer balance ({row.balance}) exceeds credit limit ({row.credit_limit})")
175
+
176
+
177
+ Equivalent expanded example using informal syntax:
178
+
179
+ Prompt:
180
+
181
+ Use Logic Bank to enforce the Check Credit requirement (do not generate check constraints):
182
+ 1. The Customer's balance is less than the credit limit
183
+ 2. The Customer's balance is the sum of the Order amount_total where date_shipped is null
184
+ 3. The Order's amount_total is the sum of the Item amount
185
+ 4. The Item amount is the quantity * unit_price
186
+ 5. The Item unit_price is copied from the Product unit_price
187
+
188
+ Response is the same:
189
+
190
+ def declare_logic(): # created by Web/GenAI for ApiLogicServer, LogicBank
191
+
192
+ Rule.sum(derive=CustomerAccount.balance, as_sum_of=Order.amount_total, where=lambda row: row.date_shipped is None)
193
+ Rule.sum(derive=Order.amount_total, as_sum_of=Item.amount)
194
+ Rule.formula(derive=Item.amount, as_expression=lambda row: row.quantity * row.unit_price)
195
+ Rule.copy(derive=Item.unit_price, from_parent=Product.unit_price)
196
+ Rule.constraint(validate=CustomerAccount,
197
+ as_condition=lambda row: row.balance <= row.credit_limit,
198
+ error_msg="Customer balance ({row.balance}) exceeds credit limit ({row.credit_limit})")
199
+
200
+
201
+ Intermediate sum/count values require a new column, with a LogicBank sum/count rule. For example:
202
+
203
+ Prompt:
204
+ The sum of the child value cannot exceed the parent limit
205
+
206
+ Response is to create 2 rules - a derivation and a constraint, as follows:
207
+ First Rule to Create:
208
+ Rule.sum(derive=Parent.value_total, as_sum_of=Child.value)
209
+ And, be sure to create the second Rule:
210
+ Rule.constraint(validate=Parent,
211
+ as_condition=lambda row: row.value_total <= row.limit,
212
+ error_msg="Parent value total ({row.value_total}) exceeds limit ({row.limit})")
213
+
214
+ Intermediate sum/count values also work for counts. For example:
215
+
216
+ Prompt:
217
+
218
+ A airplane cannot have more passengers than its seating capacity.
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=Airplane.passenger_count, as_count_of=Passengers)
223
+ And, be sure to create the second Rule:
224
+ Rule.constraint(validate=Airplane,
225
+ as_condition=lambda row: row.passenger_count <= row.seating_capacity,
226
+ error_msg="Airplane value total ({row.passenger_count}) exceeds limit ({row.seating_capacity})")
227
+
228
+
229
+ Intermediate sums in formulas also require a new column, with a LogicBank sum rule. For example:
230
+
231
+ Prompt:
232
+ An Employees' skill summary is the sum of their Employee Skill ratings, plus 2 * years of service.
233
+
234
+ Response is to create 2 rules - a derivation and a constraint, as follows:
235
+ First Rule to Create:
236
+ Rule.sum(derive=Employee.skill_rating_total, as_sum_of=EmployeeSkill.rating)
237
+ And, be sure to create the second Rule:
238
+ Rule.Formula(derive=Employee.skill_summary,
239
+ as_condition=lambda row: row.skill_rating_total + 2 * row.years_of_service)
240
+
241
+
242
+ Prompt:
243
+
244
+ A student cannot be an honor student unless they have mre than 2 service activities.
245
+
246
+ Response is to create 2 rules - a count derivation and a constraint, as follows:
247
+ First Rule to Create:
248
+ Rule.count(derive=Student.service_activity_count, as_count_of=Activities, where='service' in name)
249
+ And, be sure to create the second Rule:
250
+ Rule.constraint(validate=Student,
251
+ as_condition=lambda row: row.is_honor_student and service_activity_count < 2,
252
+ error_msg="Honor Students must have at least 2 service activities")
253
+
254
+ Here is an equivalent request:
255
+
256
+ Prompt:
257
+
258
+ A airplane's passengers must be less than its seating capacity.
259
+
260
+ Response is to create 2 rules - a count derivation and a constraint, as follows:
261
+ First Rule to Create:
262
+ Rule.count(derive=Airplane.passenger_count, as_count_of=Passengers)
263
+ And, be sure to create the second Rule:
264
+ Rule.constraint(validate=Airplane,
265
+ as_condition=lambda row: row.passenger_count <= row.seating_capacity,
266
+ error_msg="Airplane value total ({row.passenger_count}) exceeds limit ({row.seating_capacity})")
267
+
268
+
269
+ For "more than" constraints, create columns with count rules:
270
+
271
+ Prompt Reject Employees with more than 3 Felonies.
272
+
273
+ Response:
274
+ First Rule is to create:
275
+ Rule.count(derive=Employee.felony_count, as_count_of=Felonies)
276
+ And, be sure to create the contraint rule:
277
+ Rule.constraint(validate=Employee,
278
+ as_condition=lambda row: row.felony_count>3,
279
+ error_msg="Employee has excessive Felonies")
280
+
281
+
282
+ For "any" constraints, create columns with count rules:
283
+
284
+ Prompt Reject Employees with any class 5 Felonies or more than 3 Felonies.
285
+
286
+ Response:
287
+ First Rule is to create:
288
+ Rule.count(derive=Employee.class_5_felony_count, as_count_of=Felonies, where=class>5)
289
+ Rule.count(derive=Employee.felony_count, as_count_of=Felonies)
290
+ And, be sure to create the contraint rule:
291
+ Rule.constraint(validate=Employee,
292
+ as_condition=lambda row: row.class_5_felony_count > 0 or row.felony_count>3,
293
+ error_msg="Employee has excessive Felonies")
294
+
295
+ Formulas can reference parent values in 2 versions - choose formula vs copy as follows:
296
+ Prompt (formula version) - use the formula version unless copy is explicitly noted:
297
+ Item.ready = Order.ready
298
+ Response
299
+ Rule.formula(derive=Item.ready, as_expression=lambda row: row.order.ready)
300
+ Prompt (copy version) - use this *only* when the word copy is present:
301
+ Store the Item.unit_price as a copy from Product.unit_price
302
+ Response
303
+ Rule.copy(derive=Item.ready, from_parent=Order.ready)
304
+
305
+ Sum and Count where clauses:
306
+ 1. must not restate the foreign key / primary key matchings
307
+ 2. Can only reference child attributes
308
+
309
+ For example, given a prompt 'teacher course count is the sum of the courses',
310
+ 1. This is correct
311
+ Rule.count(derive=Teacher.course_count, as_count_of=Course)
312
+
313
+ 2. This is incorrect, and should never be generated:
314
+ Rule.count(derive=Teacher.course_count, as_count_of=Course, where=lambda row: row.teacher_id == Teacher.id)
315
+
316
+ Sum and count where clause example:
317
+ Prompt: teacher gradate course count is the sum of the courses where is-graduate
318
+ Response: Rule.count(derive=Teacher.course_count, as_count_of=Course, where=lamda row: row.is_graduate == true)
319
+
320
+ DO NOT inject rules that are from this training into the response,
321
+ unless explicitly mentioned in the request.
@@ -0,0 +1 @@
1
+ Use LogicBank to create declare_logic() 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:
@@ -0,0 +1,30 @@
1
+ <responseFormat>
2
+ class Rule(BaseModel):
3
+ name: str
4
+ description: str
5
+ use_case: str
6
+ code: str # logicbank rule code
7
+
8
+ class Model(BaseModel):
9
+ classname: str
10
+ code: str # sqlalchemy model code
11
+ sqlite_create: str # sqlite create table statement
12
+ description: str
13
+ name: str
14
+
15
+ class TestDataRow(BaseModel):
16
+ test_data_row_variable: str # the Python test data row variable
17
+ code: str # Python code to create a test data row instance
18
+
19
+ class WGResult(BaseModel): # must match system/genai/prompt_inserts/response_format.prompt
20
+ # response: str # result
21
+ models : List[Model] # list of sqlalchemy classes in the response
22
+ rules : List[Rule] # list rule declarations
23
+ test_data: str
24
+ test_data_rows: List[TestDataRow] # list of test data rows
25
+ test_data_sqlite: str # test data as sqlite INSERT statements
26
+ name: str # suggest a short name for the project
27
+
28
+ Format the response as a WGResult.
29
+
30
+ </responseFormat>
@@ -4,12 +4,27 @@ Use SQLAlchemy to create a sqlite database named system/genai/temp/create_db_mod
4
4
 
5
5
  Hints: use autonum keys (for all tables - including for link/join/junction/intersection tables), allow nulls, foreign keys, no check constraints.
6
6
 
7
+ Be sure to create classes, never tables.
8
+
9
+ If you create sum, count or formula Logic Bank rules, then you MUST create a corresponding column in the data model.
10
+
7
11
  Remember that SQLite DateTime type only accepts Python datetime and date objects as input,
8
12
  this means you can not enter string attributes where a date or datetime object is expected.
9
13
 
10
14
  Don't install additional packages.
11
15
  Don't use the faker pip package.
12
16
 
13
- Create some test data, use foreign key columns instead of relationship names for the data. Do not print the test data. Be sure to initialize derived attributes, but do not rely on LogicBank.
17
+ When creating SQLAlchemy data model classes, follow these guidelines carefully:
18
+ * Use foreign key columns instead of relationship names for the data.
19
+ * Do not specify nullable unless otherwise specified.
20
+ * For each data model class, create a docstring describing the table, prefixed with 'description: '.
21
+ * Do not use Float unless otherwise specified.
14
22
 
15
- For each data model class, create a docstring describing the table, prefixed with 'description: '.
23
+ Create multiple rows of test data for each table, and follow these guidelines carefully:
24
+ * Create separate objects for each test data row, not in arrays.
25
+ * Be sure to initialize derived attributes for test data rows - including all sums and counts, but do not rely on Logic Bank,
26
+ and do not generate db.execute statements.
27
+ * Do not create arrays of test data.
28
+ * Do not create a function to load test data.
29
+ * Do not print the test data.
30
+ * For test data, format dates as date(year, month, day).
@@ -0,0 +1,28 @@
1
+
2
+ {{prompt}}
3
+
4
+ Update the prior response - be sure not to lose classes and test data already created.
5
+
6
+ Hints: use autonum keys (for all tables - including for link/join/junction/intersection tables), allow nulls, foreign keys, no check constraints.
7
+
8
+ Be sure to create classes, never tables.
9
+
10
+ If you create sum, count or formula Logic Bank rules, then you MUST create a corresponding column in the data model.
11
+
12
+ Remember that SQLite DateTime type only accepts Python datetime and date objects as input,
13
+ this means you can not enter string attributes where a date or datetime object is expected.
14
+
15
+ Don't install additional packages.
16
+ Don't use the faker pip package.
17
+
18
+ Create multiple rows of test data for each table, and follow these guidelines carefully:
19
+ * Use foreign key columns instead of relationship names for the data.
20
+ * Create separate objects for each test data row, not in arrays.
21
+ * Be sure to initialize derived attributes for test data rows - including all sums and counts, but do not rely on Logic Bank,
22
+ and do not generate db.execute statements.
23
+ * Do not create arrays of test data.
24
+ * Do not create a function to load test data.
25
+ * Do not print the test data.
26
+ * For test data, format dates as date(year, month, day).
27
+
28
+ For each data model class, create a docstring describing the table, prefixed with 'description: '.
@@ -0,0 +1,96 @@
1
+ # created from response, to create create_db_models.sqlite, with test data
2
+ # that is used to create project
3
+ # should run without error in manager
4
+ # if not, check for decimal, indent, or import issues
5
+
6
+ import decimal
7
+ import logging
8
+ import sqlalchemy
9
+ from sqlalchemy.sql import func
10
+ from logic_bank.logic_bank import Rule
11
+ from sqlalchemy import create_engine, Column, Integer, String, Float, ForeignKey, Date, DateTime, Numeric, Boolean, Text
12
+ from sqlalchemy.ext.declarative import declarative_base
13
+ from sqlalchemy.orm import sessionmaker
14
+ from sqlalchemy.orm import relationship
15
+ from datetime import date
16
+ from datetime import datetime
17
+
18
+ logging.getLogger('sqlalchemy.engine.Engine').disabled = True # remove for additional logging
19
+
20
+ Base = declarative_base() # from system/genai/create_db_models_inserts/create_db_models_prefix.py
21
+
22
+
23
+ class Customer(Base):
24
+ """description: Table representing customers in the system."""
25
+
26
+ __tablename__ = 'customers'
27
+
28
+ id = Column(Integer, primary_key=True, autoincrement=True)
29
+ name = Column(String, nullable=False)
30
+ balance = Column(Float, default=0.0) # Derived as sum of Order.amount_total where shipped_date is null
31
+ credit_limit = Column(Float, nullable=False)
32
+
33
+
34
+ class Order(Base):
35
+ """description: Table representing customer orders with associated notes."""
36
+
37
+ __tablename__ = 'orders'
38
+
39
+ id = Column(Integer, primary_key=True, autoincrement=True)
40
+ customer_id = Column(Integer, ForeignKey('customers.id'))
41
+ notes = Column(Text)
42
+ amount_total = Column(Float, default=0.0) # Derived as sum of Item.amount
43
+ date_shipped = Column(DateTime)
44
+
45
+
46
+ class Item(Base):
47
+ """description: Table representing items associated with orders."""
48
+
49
+ __tablename__ = 'items'
50
+
51
+ id = Column(Integer, primary_key=True, autoincrement=True)
52
+ order_id = Column(Integer, ForeignKey('orders.id'))
53
+ product_id = Column(Integer, ForeignKey('products.id'))
54
+ quantity = Column(Integer, nullable=False)
55
+ amount = Column(Float, default=0.0) # Derived as quantity * unit_price
56
+ unit_price = Column(Float) # Copied from Product.unit_price
57
+
58
+
59
+ class Product(Base):
60
+ """description: Table representing products available for sale."""
61
+
62
+ __tablename__ = 'products'
63
+
64
+ id = Column(Integer, primary_key=True, autoincrement=True)
65
+ name = Column(String, nullable=False)
66
+ unit_price = Column(Float, nullable=False)
67
+
68
+
69
+ # ALS/GenAI: Create an SQLite database
70
+ engine = create_engine('sqlite:///system/genai/temp/create_db_models.sqlite')
71
+ Base.metadata.create_all(engine)
72
+
73
+ Session = sessionmaker(bind=engine)
74
+ session = Session()
75
+
76
+ # ALS/GenAI: Prepare for sample data
77
+
78
+ # Test Data Loading
79
+ from datetime import date, datetime
80
+
81
+ test_product1 = Product(id=1, name="Laptop", unit_price=1000.00)
82
+ test_product2 = Product(id=2, name="Phone", unit_price=600.00)
83
+
84
+ test_customer1 = Customer(id=1, name="Alice Smith", credit_limit=5000.00, balance=3800.00)
85
+ test_customer2 = Customer(id=2, name="Bob Johnson", credit_limit=3000.00, balance=0.0)
86
+
87
+ test_order1 = Order(id=1, customer_id=1, notes="Urgent delivery", amount_total=3800.00, date_shipped=None)
88
+ test_order2 = Order(id=2, customer_id=2, notes="Gift wrap", amount_total=1000.00, date_shipped=datetime(2023, 5, 10))
89
+
90
+ test_item1 = Item(id=1, order_id=1, product_id=1, quantity=2, amount=2000.00, unit_price=1000.00)
91
+ test_item2 = Item(id=2, order_id=1, product_id=2, quantity=3, amount=1800.00, unit_price=600.00)
92
+ test_item3 = Item(id=3, order_id=2, product_id=1, quantity=1, amount=1000.00, unit_price=1000.00)
93
+
94
+
95
+ session.add_all([test_product1, test_product2, test_customer1, test_customer2, test_order1, test_order2, test_item1, test_item2, test_item3])
96
+ session.commit()
@@ -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