aichat
aichat is an open source, terminal-based chat application that allows you to communicate with AI models. What makes aichat different and exciting?
- It is terminal based
- It allows you to save detailed role definitions (system prompts)
- It allows you to save chat sessions locally (and later manipulate and extract details)
- It allows you to extract data from psql and process the data using ai and then do something with the processes data - all within the same command/script.
- It provides a trivial way to switch between models (openai, anthropic, gemini, ollama, etc...)
- It is terminal based (repeated on purpose); therefore,
- you can pipe multiple commands together in a single bash line instruction
- use the power of bash scripting to do almost anything
- you have immediate access using super+t (to quickly open a terminal from anywhere)
Primer Video
[00:00:09] LLM List
[00:00:53] AIChat - CMD
[00:01:41] AIChat Repl
[00:02:29] AIChat Shell Assist
[00:03:01] AIChat Roles
[00:04:43] AIChat Session Management
[00:04:45] Term - zero shot
[00:06:22] AIChat Session Resumed
[00:07:28] Term - LLM definition
[00:08:00] Love AIChat - no program
[00:08:48] Love Prototyping
[00:10:27] RAG start
[00:11:15] Could not edit this to make better - just awkward
[00:11:20] Ops Manual
[00:12:12] Vector Database
[00:12:18] Symantec Search
[00:13:35] Rag culminating point
[00:14:09] Rag definition
[00:15:36] Summary so far…
[00:16:28] Summary end…
[00:16:29] Function Calling start
[00:16:35] Stack Tangent
[00:19:12] Stack PostgREST
[00:20:52] Function Calling definition
[00:22:55] Roles, Tasks, Tools
[00:23:33] Role Contracts and Automation
[00:24:37] Function Calling recap
[00:25:16] Vision casting
[00:25:43] Agents
[00:26:48] Data, Easy, no Mistakes
[00:27:33] Prompt Questions
[00:27:53] AIChat Agent Prompt
[00:28:30] Employee Training
[00:29:16] AIChat remaining stuff
[00:30:11] AIChat Wiki
[00:30:27] AIChat teaching how AIChat
[00:30:47] Vision
Recommended Usage
What makes aichat so exciting is the ability to mock up scenarios with real data and real ai calls. Once you can reliably produce the desired results, simply pass the example to Logilite for implementation in iDempiere. Any call that you can make using aichat can also be execute (in real-time) using iDempiere.
Example: Product Recommendation
Here is a sql file that will looks at customer invoice product data:
>>> some.sql <<< select i.dateinvoiced as document_date, i.documentno as document_number, bp.name as customer_name, il.line as document_line, p.name as product_name, il.priceactual as price_unit, il.pricelimit as cost_unit, il.priceactual-il.pricelimit as profit_unit, il.qtyinvoiced as quantity, il.qtyinvoiced * il.priceactual as price_extended, il.qtyinvoiced * (il.priceactual-il.pricelimit) as profit_extended from c_invoiceline il join c_invoice i on il.c_invoice_id = i.c_invoice_id join c_bpartner bp on i.c_bpartner_id = bp.c_bpartner_id join m_product p on il.m_product_id = p.m_product_id where i.issotrx='Y' order by i.dateinvoiced
Here is a call that queries the data from iDempiere and asks aichat to perform an analysis:
psqli -AXqtc "SELECT JSON_AGG(t) FROM ($(cat some.sql)) t" | aichat -- what is the best product to recommend to what customer?
Here are the details:
- psqli is just an alias to connect psql to idempiere (-h localhost -d idempiere -U adempiere)
- -AXqtc tells psql to run the sql command in quotes and return it without any timing or headers or labels.
- SELECT JSON_AGG(t)... says to convert the results to json.
- $(cat some.sql) simply loads the contents of the some.sql file into psql
- "|" simply passes the result of the psql into aichat
Here is an example result of the above call:
Based on the given sales data, the best product to recommend to each customer is: 1. KDVWEGDGU Systems: Plum Tree - KDVWEGDGU Systems purchased Plum Trees in both their orders (document numbers 200001 and 200000). - The Plum Tree has the highest profit per unit ($2.5) among the products they bought. 2. GQXOMLAPQZ Systems: Oak Tree - GQXOMLAPQZ Systems purchased Planting Service, Plum Tree, and Oak Tree in a single order (document number 200002). - The Oak Tree has the highest profit per unit ($3.25) among the products they bought. 3. GPPWBA Global: Azalea Bush - GPPWBA Global made a single purchase of Azalea Bushes (document number 100000). - Since they only bought one product, the Azalea Bush is the best recommendation for them. In summary: KDVWEGDGU Systems: Recommend Plum Tree GQXOMLAPQZ Systems: Recommend Oak Tree GPPWBA Global: Recommend Azalea Bush
Markdown Work Instruction
I often emphasis the importance of documenting work instructions. Specifically, I want people to write work instructions in markdown. The above example represents an opportunity to use these instructions to help automate processes.
Here is an updated example:
psqli -AXqtc "SELECT JSON_AGG(t) FROM ($(cat some.sql)) t" | aichat -f some-task-work-instructions.md -- follow these work instructions to recommend a product in the requested format.
The above example shows how you can pass already created work instructions using the -f (file) option to feed and further automate processes.
PDF Extraction and Discussion
I used the following to analyzed my Visa statements for medical and business travel.
Here is the readme.md that I created for myself:
# Summary The purpose of this file is to describe how the analysis was performed. Steps: 1. download the pdf statements from cc, checking and savings 1. extract the text using: pdftotext -layout eStmt_2023-11-13.pdf 1. use aichat to perform the analysis. Below is an example: 1. iterate across all statements # expenses aichat -f a-prompt.txt -f a-sample.txt -f eStmt_2023-03-13.txt -- please use a-prompt.txt to evaluate eStmt_2023-03-13.txt and produce output that looks like a-sample.txt > eStmt_2023-03-13.txt.results # medical aichat -f a-prompt-med.txt -f a-sample-med.tx -f eStmt_2023-01-13.txt -- please use a-prompt-med.txt to evaluate eStmt_2023-01-13.txt and produce output that looks like a-sample-med.txt > eStmt_2023-03-13.txt.results.med # quick with variables STAT='eStmt_2023-01-13.txt' aichat -f a-prompt-med.txt -f a-sample-med.txt -f $STAT -- please use a-prompt-med.txt to evaluate $STAT and produce output that looks like a-sample-med.txt > "$STAT".results.med vim "$STAT".results.med # pdftotext install sudo apt-get install poppler-utils
Here is the business travel prompt:
I want your help identifying business related expenses. If you are not sure if an entry is business related, error on the side of including the line. If you find an entry that is not in cedar park, round rock or austin TX, please include the entry because this means I was traveling for business. Please show the amount per item. If you find more than one entry for the same vendor, please sum and count the amount per item. If the dates of the entries are far apart, the entries could represent separate trips. Please indicate how many trips if more than one.
Here is the business travel sample response:
Here is a sample response: Based on the information provided, I've identified the following business-related expenses: 1. Massage Therapy (likely for business-related stress relief): Johnny SPORTS MASS Austin TX: $360.00 (3 entries, $120 each) 2. Business Travel Expenses: - SMOOTHWIRE-CA: $240.36 - HYATT CA: $200.74 - HOMESUITES HOUSTON TX: $390.43 Total: $831.53 3. Business Meals (during travel or local business meetings): - ROOT JOINT BURGER COMPA SAN ANGELO TX: $37.63 - KEBAB SHOP Austin TX: $67.33 Total: $104.96 4. Transportation (during business travel): - SHELL OIL 12392209008 JARRELL TX: $35.03 Total: $35.03 Total identified business-related expenses: $1331.52 It seems like you traveled to or through the following cities: 1. Jarrell TX 2. San Angelo TX 3. Houston TX Please note that some expenses may require further clarification to determine if they are business-related. Additionally, there may be other business expenses that are not easily identifiable without more context.
Here is the medical expenses prompt:
I want your help identifying medical related expenses. If you are note sure if an entry is medical related, error on the side of including the line. Please show the amount per item. If you find more than one entry for the same vendor, please sum and count the amount per item.
Here is the medical expenses sample response:
Here is a sample response: Based on the information provided, I've identified the following medical-related expenses: - Johnny SPORTS MASS Austin TX: $360.00 (3 entries, $120 each) - SMOOTHWIRE-medical: $240.36 Total identified business-related expenses: $600.36