Releases: ApiLogicServer/ApiLogicServer-src
ALS, WebGenAI Docker updates
This release is available via pip and docker, including als and WebGenAI.
WebGenAI now supports a 'demo mode startup' that will create and run the genai_demo
, which illustrates basic logic (note: the doc is generally correct, but is under revision):
# run local docker
https://apifabric.ai/admin-app/#/Home?demo=genai_demo
# WebGenAI website
http://localhost:8282/admin-app/#/Home?demo=genai_demo
To obtain the WebGenAI Docker:
docker pull apilogicserver/web_genai
Docker run instructions are provided on the WebGenAI Docker Repository.
14.01.00: N8N, Fixup missing attrs, Rebuild Test Data, Project Import/Merge
This major release is available via PyPi and Docker. It contains bug fixes, and new features listed below.
1. N8N
N8N enables integration with a wide range of systems. It is included as part of the nw_sample
. Include code like the following in logic/declare_logic.py
(or in logic/logic_discovery
:
if logic_row.is_inserted():
send_n8n_message(logic_row=logic_row)
Simplified RowDictMapper
The sample illustrates usage such as:
def fn_customer_workflow(row: Customer, old_row: Customer, logic_row: LogicRow):
""" #als: Send N8N message
Webhook Workflow: When Customer is inserted/updated - post n8n Webhook and call sendgrid email system
Args:
row (Customer): inserted / changed Customer
old_row (Customer): n/a
logic_row (LogicRow): bundles curr/old row, with ins/upd/dlt logic
"""
if logic_row.is_inserted():
send_n8n_message(logic_row=logic_row)
""" #als: Send Kafka message - illustrate 3 alerting methods
See also: send_kafka_message() in declare_logic.py.
"""
kafka_producer.send_kafka_message(logic_row=logic_row,
kafka_topic="customer",
kafka_key=str(row.Id),
msg="1. /integration.py: Kafka, sending logic_row=logic_row")
kafka_producer.send_kafka_message(payload={"customer_id": row.Id, "balance": row.Balance},
kafka_topic="customer",
kafka_key=str(row.Id),
msg="2. logic_discovery/integration.py: Kafka, sending payload=<dict>")
kafka_producer.send_kafka_message(logic_row=logic_row,
row_dict_mapper=Customer_Orders,
kafka_topic="customer",
kafka_key=str(row.Id),
msg="3. logic_discovery/integration.py: Kafka, sending with declarative mapping (row_dict_mapper=Customer_Orders)")
def fn_employee_workflow(row: Employee, old_row: Employee, logic_row: LogicRow):
"""
Workflow: When Employee is inserted = post n8n Webhook and call sendgrid email system
"""
send_n8n_message(logic_row=logic_row,
msg="1. /Webhook integration.py: n8n, sending Employee logic_row")
2. Fixup Missing Attributes
Introducing new rules often requires adding attributes. These are now reported when you start your API Logic Project.
For WebG projects, you can use GenAI to discover missing attributes from your logic, and add them to your test sqlite database:
# Ask ChatGPT to rebuild the data model and test data - create missing attrs per the current rules
als genai-utils --fixup
# see results in genai_demo_with_logic/docs/fixup
# create a new project with the correct data model & test data
cd .. # should be the manager
als genai --using=genai_demo_with_logic_fixed --project-name=genai_demo_with_logic_fixed --retries=-1 --repaired-response=genai_demo_with_logic/docs/fixup/response_fixup.json
3. Rebuild Test Data
Introducing new rules often requires adding attributes.. These need to be initialized with proper values that reflect the rules.
For WebG projects, you can use GenAI to update sqlite test databases:
cd <your project>
als genai-utils --rebuild-test-data
4. Project Import/Merge
For multiple team (e.g. Line Of Business and Dev) working in parallel on the same project, LOB updates can be merged into the Dev project:
als genai-utils --import-genai --using=../wg_demo_no_logic_fixed
where --using
is a project exported / unzipped from WegGenAI.
GenAI Logic with "any" cardinality rules
This release is available for PyPi and Docker, both apilogicserver/api_logic_server and apilogicserver/web_genai.
There are many improvements to GenAI, including the Landing Page with fun graphics (see the video at GenAI-Logic, such as support for "any" cardinality rules.
GenAI Informal and Multi-Rule Logic
This release (pip and docker) sees signficant advances in declaring logic via GenAI.
For example, instead of dot notation, you can create prompts like this:
Create a system with customers, orders, items and products.
Include a notes field for orders.
Use LogicBank to enforce the Check Credit requirement:
1. The Customer's balance is less than the credit limit
2. The Customer's balance is the sum of the Order amount_total where date_shipped is null
3. The Order's amount_total is the sum of the Item amount
4. The Item amount is the quantity * unit_price
5. The Item unit_price is copied from the Product unit_price
You can even infer multiple rules from a single line; create a project with a prompt like this:
System for Departments and Employees.
LogicBank:
1. Sum of employee salaries cannot exceed department budget
This creates a running system: a database, an API, an Admin App, and logic. From the Manager:
als genai --using=system/genai/examples/emp_depts/emp_dept.prompt
The logic is non-trivial:
- A
Department.total_salaries
is created - Two rules are created in
logic/declare_logic.py
# Logic from GenAI: (or, use your IDE w/ code completion)
# Aggregate the total salaries of employees for each department.
Rule.sum(derive=Department.total_salaries, as_sum_of=Employee.salary)
# Ensure the sum of employee salaries does not exceed the department budget.
Rule.constraint(validate=Department, as_condition=lambda row: row.total_salaries <= row.budget, error_msg="Total salaries ({row.total_salaries}) exceed the department budget ({row.budget})")
# End Logic from GenAI
This support is in technology-preview state.
DBML with Table Descriptions
This is mainly an internal release (PyPy and docker):
- SRA (Safrs React Admin) 10-22
- For projects created with GenAI, the DBML now shows the table descriptions
Natural Language Logic - Beta
Natural Language Logic has matured to the Beta stage. There are still occasional issues with proper initialization of derived columns, but is usually correct. It's a good idea to check your test data...
This release (pip and docker) also addresses:
- Improved Singularization: table names like Address now result in classes like
Address
(notAddres
) - Logic Learning is much-improved, with a new customizable /system/genai/learning_requests
- Improved provisions for logic hallucinations in creating logic
4, You can use Natural Language to add logic to existing projects, though see the provisos noted in the doc. - Projects created from GenAI now show "completed' prompts, ie, include system-supplied prompt engineering, which makes them easier to understand and debug
- The project readme is improved
Natural Language Logic
As of release 11.2.10, you can declare Natural Language Logic when you create projects, and for existing projects.
This is a technology preview, not yet available in docker or Web/GenAI.
Bug Fix - Constraint Reporting in Admin App
Fixes improperly reported constraints - available on PyPy and docker.
Dup Rule Detection; GenAI Hardening
This release fixes dup rule detection, and some new coding styles from ChatGPT that previously caused errors, including:
Decimal Test Data
invoice1 = Invoice(client_id=client1.id, project_id=project1.id, amount=Decimal('1000.0'), issued_date=datetime.datetime.utcnow())
This is fixed by adding import decimal
to system/genai/create_db_models_inserts/create_db_models_prefix.py
.
Improper syntax for datetime
time_entry2 = TimeEntry(employee_id=2, task_id=2, start_time=datetime.datetime.now(), end_time(datetime.datetime.now() + datetime.timedelta(hours=3), hours_worked=3.0)
The missing equal sign in end_time(datetime.datetime.now()
is specifically checked and repaired.
Database Diagrams, GenAI Conversations
This release provides:
It is available via both pip
and docker.