ApiLogicServer 12.1.0__py3-none-any.whl → 12.2.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 (51) hide show
  1. {ApiLogicServer-12.1.0.dist-info → ApiLogicServer-12.2.0.dist-info}/METADATA +1 -1
  2. {ApiLogicServer-12.1.0.dist-info → ApiLogicServer-12.2.0.dist-info}/RECORD +47 -39
  3. {ApiLogicServer-12.1.0.dist-info → ApiLogicServer-12.2.0.dist-info}/WHEEL +1 -1
  4. api_logic_server_cli/api_logic_server.py +15 -4
  5. api_logic_server_cli/api_logic_server_info.yaml +3 -3
  6. api_logic_server_cli/cli.py +20 -9
  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__/ont_create.cpython-312.pyc +0 -0
  10. api_logic_server_cli/create_from_model/__pycache__/ui_admin_creator.cpython-312.pyc +0 -0
  11. api_logic_server_cli/create_from_model/ont_create.py +3 -1
  12. api_logic_server_cli/create_from_model/ui_admin_creator.py +6 -4
  13. api_logic_server_cli/genai.py +387 -287
  14. api_logic_server_cli/logging.yml +5 -0
  15. api_logic_server_cli/prototypes/.DS_Store +0 -0
  16. api_logic_server_cli/prototypes/base/api_logic_server_run.py +0 -2
  17. api_logic_server_cli/prototypes/base/config/server_setup.py +15 -1
  18. api_logic_server_cli/prototypes/base/integration/kafka/kafka_consumer.py +1 -1
  19. api_logic_server_cli/prototypes/base/integration/kafka/kafka_producer.py +1 -1
  20. api_logic_server_cli/prototypes/base/readme.md +21 -8
  21. api_logic_server_cli/prototypes/manager/.DS_Store +0 -0
  22. api_logic_server_cli/prototypes/manager/.vscode/.DS_Store +0 -0
  23. api_logic_server_cli/prototypes/manager/.vscode/launch.json +20 -0
  24. api_logic_server_cli/prototypes/manager/README.md +25 -1
  25. api_logic_server_cli/prototypes/manager/system/.DS_Store +0 -0
  26. api_logic_server_cli/prototypes/manager/system/genai/.DS_Store +0 -0
  27. api_logic_server_cli/prototypes/manager/system/genai/create_db_models_inserts/create_db_models_create_db.py +1 -0
  28. api_logic_server_cli/prototypes/manager/system/genai/create_db_models_inserts/create_db_models_imports.py +10 -7
  29. api_logic_server_cli/prototypes/manager/system/genai/create_db_models_inserts/create_db_models_test_data.py +1 -1
  30. api_logic_server_cli/prototypes/manager/system/genai/examples/genai_demo/genai_demo.response_example +99 -22
  31. api_logic_server_cli/prototypes/manager/system/genai/learning_requests/logic_bank_api.prompt +120 -7
  32. api_logic_server_cli/prototypes/manager/system/genai/prompt_inserts/.DS_Store +0 -0
  33. api_logic_server_cli/prototypes/manager/system/genai/prompt_inserts/response_format.prompt +26 -2
  34. api_logic_server_cli/prototypes/manager/system/genai/prompt_inserts/sqlite_inserts.prompt +10 -4
  35. api_logic_server_cli/prototypes/manager/system/genai/prompt_inserts/{sqlite_inserts_iterations.prompt → zsqlite_inserts_iterations.prompt} +5 -2
  36. api_logic_server_cli/prototypes/manager/system/genai/retry/conv/create_db_models.py +96 -0
  37. api_logic_server_cli/prototypes/manager/system/genai/retry/conv/inf-1_iter_1_1_000.response +1 -0
  38. api_logic_server_cli/prototypes/manager/system/genai/retry/conv/inf-1_iter_1_1_001.prompt +208 -0
  39. api_logic_server_cli/prototypes/manager/system/genai/retry/conv/inf-1_iter_1_1_002.prompt +89 -0
  40. api_logic_server_cli/prototypes/manager/system/genai/retry/conv/inf-1_iter_1_1_003.prompt +40 -0
  41. api_logic_server_cli/prototypes/manager/system/genai/retry/conv/inf-1_iter_1_1_004.response +57 -0
  42. api_logic_server_cli/prototypes/manager/system/genai/retry/conv/inf-1_iter_1_1_005.response +57 -0
  43. api_logic_server_cli/prototypes/manager/system/genai/retry/readme.md +1 -0
  44. api_logic_server_cli/prototypes/manager/system/genai/retry/retry.response +57 -0
  45. api_logic_server_cli/genaiZ.py +0 -752
  46. api_logic_server_cli/prototypes/manager/system/genai/examples/genai_demo/genai_demo.response_example_z +0 -130
  47. api_logic_server_cli/prototypes/manager/system/genai/prompt_inserts/web_genai copy.prompt +0 -15
  48. api_logic_server_cli/prototypes/manager/system/secrets.txt +0 -6
  49. {ApiLogicServer-12.1.0.dist-info → ApiLogicServer-12.2.0.dist-info}/LICENSE +0 -0
  50. {ApiLogicServer-12.1.0.dist-info → ApiLogicServer-12.2.0.dist-info}/entry_points.txt +0 -0
  51. {ApiLogicServer-12.1.0.dist-info → ApiLogicServer-12.2.0.dist-info}/top_level.txt +0 -0
@@ -6,19 +6,25 @@ Hints: use autonum keys (for all tables - including for link/join/junction/inter
6
6
 
7
7
  Be sure to create classes, never tables.
8
8
 
9
+ If you create sum, count or formula Logic Bank rules, then you MUST create a corresponding column in the data model.
10
+
9
11
  Remember that SQLite DateTime type only accepts Python datetime and date objects as input,
10
12
  this means you can not enter string attributes where a date or datetime object is expected.
11
13
 
12
14
  Don't install additional packages.
13
15
  Don't use the faker pip package.
14
16
 
15
- Create multiple rows of test data for each table, and follow these guidelines carefully:
17
+ When creating SQLAlchemy data model classes, follow these guidelines carefully:
16
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.
22
+
23
+ Create multiple rows of test data for each table, and follow these guidelines carefully:
17
24
  * Create separate objects for each test data row, not in arrays.
18
- * Be sure to initialize derived attributes for test data rows - including all sums and counts, but do not rely on LogicBank,
25
+ * Be sure to initialize derived attributes for test data rows - including all sums and counts, but do not rely on Logic Bank,
19
26
  and do not generate db.execute statements.
20
27
  * Do not create arrays of test data.
21
28
  * Do not create a function to load test data.
22
29
  * Do not print the test data.
23
-
24
- For each data model class, create a docstring describing the table, prefixed with 'description: '.
30
+ * For test data, format dates as date(year, month, day).
@@ -7,6 +7,8 @@ Hints: use autonum keys (for all tables - including for link/join/junction/inter
7
7
 
8
8
  Be sure to create classes, never tables.
9
9
 
10
+ If you create sum, count or formula Logic Bank rules, then you MUST create a corresponding column in the data model.
11
+
10
12
  Remember that SQLite DateTime type only accepts Python datetime and date objects as input,
11
13
  this means you can not enter string attributes where a date or datetime object is expected.
12
14
 
@@ -16,10 +18,11 @@ Don't use the faker pip package.
16
18
  Create multiple rows of test data for each table, and follow these guidelines carefully:
17
19
  * Use foreign key columns instead of relationship names for the data.
18
20
  * Create separate objects for each test data row, not in arrays.
19
- * Be sure to initialize derived attributes for test data rows - including all sums and counts, but do not rely on LogicBank,
21
+ * Be sure to initialize derived attributes for test data rows - including all sums and counts, but do not rely on Logic Bank,
20
22
  and do not generate db.execute statements.
21
23
  * Do not create arrays of test data.
22
24
  * Do not create a function to load test data.
23
- * Do not print the test data.
25
+ * Do not print the test data.
26
+ * For test data, format dates as date(year, month, day).
24
27
 
25
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
@@ -0,0 +1,208 @@
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
+ Use only the methods provided below.
8
+
9
+ class Rule:
10
+ """Invoke these functions to declare rules in the created declare_logic function. """
11
+
12
+ @staticmethod
13
+ def sum(derive: Column, as_sum_of: any, where: any = None, child_role_name: str = "", insert_parent: bool=False):
14
+ """
15
+ Derive parent column as sum of designated child column, optional where
16
+
17
+ Example
18
+ Prompt
19
+ Customer.Balance = Sum(Order.amount_total where date_shipped is null)
20
+ Response
21
+ Rule.sum(derive=Customer.Balance, as_sum_of=Order.AmountTotal,
22
+ where=lambda row: row.ShippedDate is None)
23
+
24
+ Args:
25
+ derive: name of parent <class.attribute> being derived
26
+ as_sum_of: name of child <class.attribute> being summed
27
+ 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
+ """
31
+ return Sum(derive, as_sum_of, where, child_role_name, insert_parent)
32
+
33
+ @staticmethod
34
+ def count(derive: Column, as_count_of: object, where: any = None, child_role_name: str = "", insert_parent: bool=False):
35
+ """
36
+ Derive parent column as count of designated child rows
37
+
38
+ Example
39
+ Prompt
40
+ Customer.UnPaidOrders = count(Orders where ShippedDate is None)
41
+ Response
42
+ Rule.count(derive=Customer.UnPaidOrders, as_count_of=Order,
43
+ where=Lambda row: row.ShippedDate is None)
44
+
45
+ Args:
46
+ derive: name of parent <class.attribute> being derived
47
+ as_count_of: name of child <class> being counted
48
+ child_role_name: parent's child accessor attribute (required only for disambiguation)
49
+ where: optional where clause, designates which child rows are counted
50
+ """
51
+ return Count(derive, as_count_of, where, child_role_name, insert_parent)
52
+
53
+ @staticmethod
54
+ def constraint(validate: object,
55
+ calling: Callable = None,
56
+ as_condition: any = None,
57
+ error_msg: str = "(error_msg not provided)",
58
+ error_attributes=None):
59
+ """
60
+ Constraints declare condition that must be true for all commits
61
+
62
+ Example
63
+ Prompt
64
+ Customer.balance <= credit_limit
65
+ Response
66
+ Rule.constraint(validate=Customer,
67
+ as_condition=lambda row: row.Balance <= row.CreditLimit,
68
+ error_msg="balance ({row.Balance}) exceeds credit ({row.CreditLimit})")
69
+
70
+ Args:
71
+ validate: name of mapped <class>
72
+ as_condition: lambda, passed row (simple constraints)
73
+ error_msg: string, with {row.attribute} replacements
74
+ error_attributes: list of attributes
75
+
76
+ """
77
+ if error_attributes is None:
78
+ error_attributes = []
79
+ return Constraint(validate=validate, as_condition=as_condition,
80
+ error_attributes=error_attributes, error_msg=error_msg)
81
+
82
+ @staticmethod
83
+ def parent_check(validate: object,
84
+ error_msg: str = "(error_msg not provided)",
85
+ enable: bool = True):
86
+ """
87
+ Parent Checks ensure that non-null foreign keys are present in parent class
88
+
89
+ Example
90
+ Rule.parent_check(validate=Customer, enable=True, error_msg="Missing Parent")
91
+
92
+ Parent_check failures raise ConstraintException, e.g.:
93
+ try:
94
+ session.commit()
95
+ except ConstraintException as ce:
96
+ print("Constraint raised: " + str(ce))
97
+
98
+ Args:
99
+ validate: name of mapped class
100
+ error_msg: message included in exception (can have {} syntax)
101
+ enable: True (default) = enable, False means disable (tolerate orphans)
102
+
103
+ Note: False not recommended - for existing databases with bad data
104
+ Behavior is undefined for other rules (sum, count, parent references, etc)
105
+
106
+ """
107
+ return ParentCheck(validate=validate, error_msg=error_msg, enable=enable)
108
+
109
+ @staticmethod
110
+ def formula(derive: Column,
111
+ as_expression: Callable = None,
112
+ no_prune: bool = False):
113
+ """
114
+ Formulas declare column value, based on current and parent rows
115
+
116
+ Example
117
+ Prompt
118
+ Item.amount = quantity * unit_price
119
+ Response
120
+ Rule.formula(derive=OrderDetail.Amount,
121
+ as_expression=lambda row: row.UnitPrice * row.Quantity)
122
+
123
+ Args:
124
+ derive: <class.attribute> being derived
125
+ as_expression: lambda, passed row (for syntax checking)
126
+ no_prune: disable pruning (rarely used, default False)
127
+ """
128
+ return Formula(derive=derive,
129
+ as_expression=as_expression,
130
+ no_prune=no_prune)
131
+
132
+ @staticmethod
133
+ def copy(derive: Column, from_parent: any):
134
+ """
135
+ Copy declares child column copied from parent column
136
+
137
+ Example
138
+ Prompt
139
+ Store the Item.unit_price as a copy from Product.unit_price
140
+ Response
141
+ Rule.copy(derive=OrderDetail.UnitPrice, from_parent=Product.UnitPrice)
142
+
143
+ Args:
144
+ derive: <class.attribute> being copied into
145
+ from_parent: <parent-class.attribute> source of copy
146
+ """
147
+ return Copy(derive=derive, from_parent=from_parent)
148
+
149
+
150
+ Expanded example:
151
+
152
+ Prompt:
153
+
154
+ 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
160
+
161
+ Response:
162
+
163
+ def declare_logic(): # created by Web/GenAI for ApiLogicServer, LogicBank
164
+
165
+ Rule.sum(derive=CustomerAccount.balance, as_sum_of=Order.amount_total, where=lambda row: row.date_shipped is None)
166
+ Rule.sum(derive=Order.amount_total, as_sum_of=Item.amount)
167
+ Rule.formula(derive=Item.amount, as_expression=lambda row: row.quantity * row.unit_price)
168
+ Rule.copy(derive=Item.unit_price, from_parent=Product.unit_price)
169
+ Rule.constraint(validate=CustomerAccount,
170
+ as_condition=lambda row: row.balance <= row.credit_limit,
171
+ error_msg="Customer balance ({row.balance}) exceeds credit limit ({row.credit_limit})")
172
+
173
+
174
+ Equivalent expanded example using informal syntax:
175
+
176
+ Prompt:
177
+
178
+ Use Logic Bank to enforce the Check Credit requirement (do not generate check constraints):
179
+ 1. The Customer's balance is less than the credit limit
180
+ 2. The Customer's balance is the sum of the Order amount_total where date_shipped is null
181
+ 3. The Order's amount_total is the sum of the Item amount
182
+ 4. The Item amount is the quantity * unit_price
183
+ 5. The Item unit_price is copied from the Product unit_price
184
+
185
+ Response is the same:
186
+
187
+ def declare_logic(): # created by Web/GenAI for ApiLogicServer, LogicBank
188
+
189
+ Rule.sum(derive=CustomerAccount.balance, as_sum_of=Order.amount_total, where=lambda row: row.date_shipped is None)
190
+ Rule.sum(derive=Order.amount_total, as_sum_of=Item.amount)
191
+ Rule.formula(derive=Item.amount, as_expression=lambda row: row.quantity * row.unit_price)
192
+ Rule.copy(derive=Item.unit_price, from_parent=Product.unit_price)
193
+ Rule.constraint(validate=CustomerAccount,
194
+ as_condition=lambda row: row.balance <= row.credit_limit,
195
+ error_msg="Customer balance ({row.balance}) exceeds credit limit ({row.credit_limit})")
196
+
197
+ Intermediate sum/count values require a new column, with a LogicBank sum/count rule. For example:
198
+
199
+ Prompt:
200
+ The sum of the child value cannot exceed the parent limit
201
+
202
+ Response is to create 2 rules - a derivation and a constraint, as follows:
203
+ First Rule to Create:
204
+ Rule.sum(derive=Parent.value_total, as_sum_of=Child.value)
205
+ And, be sure to create the second Rule:
206
+ Rule.constraint(validate=Parent,
207
+ as_condition=lambda row: row.value_total <= row.limit,
208
+ error_msg="Parent value total ({row.value_total}) exceeds limit ({row.limit})")
@@ -0,0 +1,89 @@
1
+
2
+ Use SQLAlchemy to create a sqlite database named system/genai/temp/create_db_models.sqlite, to
3
+
4
+ Create a system with customers, orders, items and products.
5
+
6
+ Include a notes field for orders.
7
+
8
+ 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:
9
+ 1. The Customer's balance is less than the credit limit
10
+ 2. The Customer's balance is the sum of the Order amount_total where date_shipped is null
11
+ 3. The Order's amount_total is the sum of the Item amount
12
+ 4. The Item amount is the quantity * unit_price
13
+ 5. The Item unit_price is copied from the Product unit_price
14
+
15
+ .
16
+
17
+ Hints: use autonum keys (for all tables - including for link/join/junction/intersection tables), allow nulls, foreign keys, no check constraints.
18
+
19
+ Be sure to create classes, never tables.
20
+
21
+ Remember that SQLite DateTime type only accepts Python datetime and date objects as input,
22
+ this means you can not enter string attributes where a date or datetime object is expected.
23
+
24
+ Don't install additional packages.
25
+ Don't use the faker pip package.
26
+
27
+ Create multiple rows of test data for each table, and follow these guidelines carefully:
28
+ * Use foreign key columns instead of relationship names for the data.
29
+ * Create separate objects for each test data row, not in arrays.
30
+ * Be sure to initialize derived attributes for test data rows - including all sums and counts, but do not rely on LogicBank,
31
+ and do not generate db.execute statements.
32
+ * Do not create arrays of test data.
33
+ * Do not create a function to load test data.
34
+ * Do not print the test data.
35
+ * For test data, format dates as date(year, month, day).
36
+
37
+ For each data model class, create a docstring describing the table, prefixed with 'description: '.
38
+
39
+ class WGResult(BaseModel): # must match system/genai/prompt_inserts/response_format.prompt
40
+
41
+ models : List[Model] # list of sqlalchemy classes in the response
42
+
43
+ rules : List[Rule] # list rule declarations
44
+
45
+ test_data: str
46
+
47
+ name: str # suggest a short name for the project
48
+
49
+
50
+
51
+ Format the response as a WGResult.
52
+
53
+ Update the prior response - be sure not to lose classes and test data already created.
54
+
55
+ Hints: use autonum keys (for all tables - including for link/join/junction/intersection tables), allow nulls, foreign keys, no check constraints.
56
+
57
+ Be sure to create classes, never tables.
58
+
59
+ Remember that SQLite DateTime type only accepts Python datetime and date objects as input,
60
+ this means you can not enter string attributes where a date or datetime object is expected.
61
+
62
+ Don't install additional packages.
63
+ Don't use the faker pip package.
64
+
65
+ Create multiple rows of test data for each table, and follow these guidelines carefully:
66
+ * Use foreign key columns instead of relationship names for the data.
67
+ * Create separate objects for each test data row, not in arrays.
68
+ * Be sure to initialize derived attributes for test data rows - including all sums and counts, but do not rely on LogicBank,
69
+ and do not generate db.execute statements.
70
+ * Do not create arrays of test data.
71
+ * Do not create a function to load test data.
72
+ * Do not print the test data.
73
+ * For test data, format dates as date(year, month, day).
74
+
75
+ For each data model class, create a docstring describing the table, prefixed with 'description: '.
76
+
77
+ class WGResult(BaseModel): # must match system/genai/prompt_inserts/response_format.prompt
78
+
79
+ models : List[Model] # list of sqlalchemy classes in the response
80
+
81
+ rules : List[Rule] # list rule declarations
82
+
83
+ test_data: str
84
+
85
+ name: str # suggest a short name for the project
86
+
87
+
88
+
89
+ Format the response as a WGResult.
@@ -0,0 +1,40 @@
1
+
2
+ please initialize the customer.balance and order.amount_total
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
+ Remember that SQLite DateTime type only accepts Python datetime and date objects as input,
11
+ this means you can not enter string attributes where a date or datetime object is expected.
12
+
13
+ Don't install additional packages.
14
+ Don't use the faker pip package.
15
+
16
+ Create multiple rows of test data for each table, and follow these guidelines carefully:
17
+ * Use foreign key columns instead of relationship names for the data.
18
+ * Create separate objects for each test data row, not in arrays.
19
+ 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:
20
+ and do not generate db.execute statements.
21
+ * Do not create arrays of test data.
22
+ * Do not create a function to load test data.
23
+ * Do not print the test data.
24
+ * For test data, format dates as date(year, month, day).
25
+
26
+ For each data model class, create a docstring describing the table, prefixed with 'description: '.
27
+
28
+ class WGResult(BaseModel): # must match system/genai/prompt_inserts/response_format.prompt
29
+
30
+ models : List[Model] # list of sqlalchemy classes in the response
31
+
32
+ rules : List[Rule] # list rule declarations
33
+
34
+ test_data: str
35
+
36
+ name: str # suggest a short name for the project
37
+
38
+
39
+
40
+ Format the response as a WGResult.
@@ -0,0 +1,57 @@
1
+ {
2
+ "models": [
3
+ {
4
+ "classname": "Customer",
5
+ "code": "class Customer(Base):\n \"\"\"description: Table representing customers in the system.\"\"\"\n\n __tablename__ = 'customers'\n\n id = Column(Integer, primary_key=True, autoincrement=True)\n name = Column(String, nullable=False)\n balance = Column(Float, default=0.0) # Derived as sum of Order.amount_total where shipped_date is null\n credit_limit = Column(Float, nullable=False)",
6
+ "description": "Table representing customers in the system.",
7
+ "name": "Customer"
8
+ },
9
+ {
10
+ "classname": "Order",
11
+ "code": "class Order(Base):\n \"\"\"description: Table representing customer orders with associated notes.\"\"\"\n\n __tablename__ = 'orders'\n\n id = Column(Integer, primary_key=True, autoincrement=True)\n customer_id = Column(Integer, ForeignKey('customers.id'))\n notes = Column(Text)\n amount_total = Column(Float, default=0.0) # Derived as sum of Item.amount\n date_shipped = Column(DateTime)",
12
+ "description": "Table representing customer orders with associated notes.",
13
+ "name": "Order"
14
+ },
15
+ {
16
+ "classname": "Item",
17
+ "code": "class Item(Base):\n \"\"\"description: Table representing items associated with orders.\"\"\"\n\n __tablename__ = 'items'\n\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 amount = Column(Float, default=0.0) # Derived as quantity * unit_price\n unit_price = Column(Float) # Copied from Product.unit_price",
18
+ "description": "Table representing items associated with orders.",
19
+ "name": "Item"
20
+ },
21
+ {
22
+ "classname": "Product",
23
+ "code": "class Product(Base):\n \"\"\"description: Table representing products available for sale.\"\"\"\n\n __tablename__ = 'products'\n\n id = Column(Integer, primary_key=True, autoincrement=True)\n name = Column(String, nullable=False)\n unit_price = Column(Float, nullable=False)",
24
+ "description": "Table representing products available for sale.",
25
+ "name": "Product"
26
+ }
27
+ ],
28
+ "rules": [
29
+ {
30
+ "name": "Customer Balance Constraint",
31
+ "description": "Ensure customer's balance is less than the credit limit.",
32
+ "code": "Rule.constraint(validate=Customer, as_condition=lambda row: row.balance <= row.credit_limit, error_msg=\"Customer's balance ({row.balance}) exceeds the credit limit ({row.credit_limit})\")"
33
+ },
34
+ {
35
+ "name": "Customer Balance Sum Rule",
36
+ "description": "Derive customer's balance as the sum of order amount_total where date_shipped is null.",
37
+ "code": "Rule.sum(derive=Customer.balance, as_sum_of=Order.amount_total, where=lambda row: row.date_shipped is None)"
38
+ },
39
+ {
40
+ "name": "Order Amount Total Sum Rule",
41
+ "description": "Derive order's amount_total as the sum of item amounts.",
42
+ "code": "Rule.sum(derive=Order.amount_total, as_sum_of=Item.amount)"
43
+ },
44
+ {
45
+ "name": "Item Amount Formula",
46
+ "description": "Derive item amount as quantity multiplied by unit_price.",
47
+ "code": "Rule.formula(derive=Item.amount, as_expression=lambda row: row.quantity * row.unit_price)"
48
+ },
49
+ {
50
+ "name": "Item Unit Price Copy Rule",
51
+ "description": "Copy item unit_price from product unit_price.",
52
+ "code": "Rule.copy(derive=Item.unit_price, from_parent=Product.unit_price)"
53
+ }
54
+ ],
55
+ "test_data": "# Test Data Loading\nfrom datetime import date, datetime\n\ntest_product1 = Product(id=1, name=\"Laptop\", unit_price=1000.00)\ntest_product2 = Product(id=2, name=\"Phone\", unit_price=600.00)\n\ntest_customer1 = Customer(id=1, name=\"Alice Smith\", credit_limit=5000.00, balance=0.0)\ntest_customer2 = Customer(id=2, name=\"Bob Johnson\", credit_limit=3000.00, balance=0.0)\n\ntest_order1 = Order(id=1, customer_id=1, notes=\"Urgent delivery\", amount_total=0.0, date_shipped=None)\ntest_order2 = Order(id=2, customer_id=2, notes=\"Gift wrap\", amount_total=0.0, date_shipped=datetime(2023, 5, 10))\n\ntest_item1 = Item(id=1, order_id=1, product_id=1, quantity=2, amount=2000.00, unit_price=1000.00)\ntest_item2 = Item(id=2, order_id=1, product_id=2, quantity=3, amount=1800.00, unit_price=600.00)\ntest_item3 = Item(id=3, order_id=2, product_id=1, quantity=1, amount=1000.00, unit_price=1000.00)",
56
+ "name": "SalesSystem"
57
+ }
@@ -0,0 +1,57 @@
1
+ {
2
+ "models": [
3
+ {
4
+ "classname": "Customer",
5
+ "code": "class Customer(Base):\n \"\"\"description: Table representing customers in the system.\"\"\"\n\n __tablename__ = 'customers'\n\n id = Column(Integer, primary_key=True, autoincrement=True)\n name = Column(String, nullable=False)\n balance = Column(Float, default=0.0) # Derived as sum of Order.amount_total where shipped_date is null\n credit_limit = Column(Float, nullable=False)",
6
+ "description": "Table representing customers in the system.",
7
+ "name": "Customer"
8
+ },
9
+ {
10
+ "classname": "Order",
11
+ "code": "class Order(Base):\n \"\"\"description: Table representing customer orders with associated notes.\"\"\"\n\n __tablename__ = 'orders'\n\n id = Column(Integer, primary_key=True, autoincrement=True)\n customer_id = Column(Integer, ForeignKey('customers.id'))\n notes = Column(Text)\n amount_total = Column(Float, default=0.0) # Derived as sum of Item.amount\n date_shipped = Column(DateTime)",
12
+ "description": "Table representing customer orders with associated notes.",
13
+ "name": "Order"
14
+ },
15
+ {
16
+ "classname": "Item",
17
+ "code": "class Item(Base):\n \"\"\"description: Table representing items associated with orders.\"\"\"\n\n __tablename__ = 'items'\n\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 amount = Column(Float, default=0.0) # Derived as quantity * unit_price\n unit_price = Column(Float) # Copied from Product.unit_price",
18
+ "description": "Table representing items associated with orders.",
19
+ "name": "Item"
20
+ },
21
+ {
22
+ "classname": "Product",
23
+ "code": "class Product(Base):\n \"\"\"description: Table representing products available for sale.\"\"\"\n\n __tablename__ = 'products'\n\n id = Column(Integer, primary_key=True, autoincrement=True)\n name = Column(String, nullable=False)\n unit_price = Column(Float, nullable=False)",
24
+ "description": "Table representing products available for sale.",
25
+ "name": "Product"
26
+ }
27
+ ],
28
+ "rules": [
29
+ {
30
+ "name": "Customer Balance Constraint",
31
+ "description": "Ensure customer's balance is less than the credit limit.",
32
+ "code": "Rule.constraint(validate=Customer, as_condition=lambda row: row.balance <= row.credit_limit, error_msg=\"Customer's balance ({row.balance}) exceeds the credit limit ({row.credit_limit})\")"
33
+ },
34
+ {
35
+ "name": "Customer Balance Sum Rule",
36
+ "description": "Derive customer's balance as the sum of order amount_total where date_shipped is null.",
37
+ "code": "Rule.sum(derive=Customer.balance, as_sum_of=Order.amount_total, where=lambda row: row.date_shipped is None)"
38
+ },
39
+ {
40
+ "name": "Order Amount Total Sum Rule",
41
+ "description": "Derive order's amount_total as the sum of item amounts.",
42
+ "code": "Rule.sum(derive=Order.amount_total, as_sum_of=Item.amount)"
43
+ },
44
+ {
45
+ "name": "Item Amount Formula",
46
+ "description": "Derive item amount as quantity multiplied by unit_price.",
47
+ "code": "Rule.formula(derive=Item.amount, as_expression=lambda row: row.quantity * row.unit_price)"
48
+ },
49
+ {
50
+ "name": "Item Unit Price Copy Rule",
51
+ "description": "Copy item unit_price from product unit_price.",
52
+ "code": "Rule.copy(derive=Item.unit_price, from_parent=Product.unit_price)"
53
+ }
54
+ ],
55
+ "test_data": "# Test Data Loading\nfrom datetime import date, datetime\n\ntest_product1 = Product(id=1, name=\"Laptop\", unit_price=1000.00)\ntest_product2 = Product(id=2, name=\"Phone\", unit_price=600.00)\n\ntest_customer1 = Customer(id=1, name=\"Alice Smith\", credit_limit=5000.00, balance=3800.00)\ntest_customer2 = Customer(id=2, name=\"Bob Johnson\", credit_limit=3000.00, balance=0.0)\n\ntest_order1 = Order(id=1, customer_id=1, notes=\"Urgent delivery\", amount_total=3800.00, date_shipped=None)\ntest_order2 = Order(id=2, customer_id=2, notes=\"Gift wrap\", amount_total=1000.00, date_shipped=datetime(2023, 5, 10))\n\ntest_item1 = Item(id=1, order_id=1, product_id=1, quantity=2, amount=2000.00, unit_price=1000.00)\ntest_item2 = Item(id=2, order_id=1, product_id=2, quantity=3, amount=1800.00, unit_price=600.00)\ntest_item3 = Item(id=3, order_id=2, product_id=1, quantity=1, amount=1000.00, unit_price=1000.00)",
56
+ "name": "SalesSystem"
57
+ }
@@ -0,0 +1 @@
1
+ Use this as a temp folder to store and edit retry files.