I finally got around to exploring LLM + tools with gramps. The basic idea is to make available a series of functions that can access gramps object data (the dictionary format used in JSON API, etc). I’ve added 13 functions/tools so far, things like get_person()
, get_person_death_place()
, etc.
This is a different strategy than the RAG model used in GrampsWeb. This example is designed to answer questions by using these specific functions. The functions are mostly all handle based. The LLM doesn’t care, and much of the API is centered around handles anyway.
Here is a sample showing some of the kinds of things it can do (with a modern LLM, gpt-4o):
$ python chatbot.py
Two Gramps application data directories exist.
Enter your question: Who is the home person?
Thinking....
>>> The home person is Dr. Lewis Anderson Garner, also known as "Big Louie."
Enter your question: Can you give me a table of the names of his children, where they were born, and died?
Thinking............................
>>> Here is a table of Dr. Lewis Anderson Garner's children, along with their birth and death places:
| Name | Birth Place | Death Place |
|------------------|--------------------------------------|----------------------------------------|
| Eugene Stanley | Portsmouth, OH, USA | Twin Falls, Twin Falls, ID, USA |
| Jesse V. | Paragould, Greene, AR, USA | Cedar City, UT, USA |
| Raymond E. | Paragould, Greene, AR, USA | Astoria, OR, USA |
| Jennie S. | Paragould, Greene, AR, USA | Columbus, Bartholomew, IN, USA |
| Walter E. | Paragould, Greene, AR, USA | Battle Creek, MI, USA |
| Daniel Webster | Hood River, OR, USA | Gary, Lake, IN, USA |
| Bertha P. | Hagerstown, MD, USA | Columbus, Bartholomew, IN, USA |
| Elizabeth | | |
Note: Elizabeth's birth and death places are not available.
Enter your question: Did all of the children have the same mother?
Thinking...........
>>> All of Dr. Lewis Anderson Garner's children share the same mother, Luella Jacques Martel.
Enter your question: Who was Luella's father?
Thinking....
>>> Luella Jacques Martel's father was Henry Martel.
Enter your question: Where was he born?
Thinking....
>>> Henry Martel was born in Wauchula, Hardee, FL, USA.
Enter your question: When did he die?
Thinking....
>>> Henry Martel died on January 18, 1902.
Enter your question: How old was he?
Thinking....
>>> Henry Martel was born on October 27, 1805, and died on January 18, 1902, making him 96 years old at the time of his death.
Enter your question: That is pretty old!
Thinking...
>>> Indeed, 96 years is quite a long life, especially considering the standards of the 19th and early 20th centuries. It's always fascinating to learn how life spans have changed over time.
Enter your question: Did any of Big Louie's children die in the same town?
Thinking...
>>> Yes, both Jennie S. Garner and Bertha P. Garner died in Columbus, Bartholomew, IN, USA.
Enter your question: Where is Columbus?
Thinking...
>>> Columbus is located in Bartholomew County in the state of Indiana, USA.
Enter your question: Where is that in relationship to Indianapolis?
Thinking...
>>> Columbus, Indiana, is located approximately 45 miles (about 72 kilometers) south of Indianapolis. It's about an hour's drive via Interstate 65.
Enter your question: How far is Columbus from Hagerstown, MD, USA?
Thinking...
>>> The distance between Columbus, Indiana, and Hagerstown, Maryland, is approximately 520 miles (about 837 kilometers) by road. The drive would typically take around 8 to 9 hours, depending on traffic and road conditions.
Enter your question: In 1850, how would a family get from the Port of Entry in New Orleans to Indianapolis?
Thinking...
>>> In 1850, a family traveling from the Port of New Orleans to Indianapolis would likely have used a combination of riverboats and overland travel:
1. **Riverboat on the Mississippi River**: They would start by taking a riverboat north along the Mississippi River. River travel was a popular mode of transportation due to the extensive network of rivers in the United States.
2. **Connecting to the Ohio River**: From the Mississippi River, they would likely connect to the Ohio River via riverboat. The Ohio River was a key waterway for moving goods and people eastward from the Mississippi.
3. **Reaching the Ohio Valley**: They could continue their journey on the Ohio River, stopping in cities like Louisville, Kentucky, or Cincinnati, Ohio.
4. **Overland Route to Indianapolis**: From there, the family would need to continue overland. This could involve hiring a stagecoach or taking a train, if available. Trains were becoming more widespread by 1850, but they might still have relied on horse-drawn vehicles for the final leg of the journey to Indianapolis, particularly if the rail network did not cover the entire route.
The journey would have required careful planning and could take several weeks, depending on the conditions and the mode of transportation chosen.
Some other things that I was surprised about (it inferred that grandmother was mother of mother):
Enter your question: Who was Babe's grandmother?
Thinking....
>>> Frances Lucille "Babe" Reed's maternal grandmother was Bridget Holt. If you need more information about her or any other ancestors, feel free to ask!
And this (remembers what we are talking about):
Enter your question: How many children did Robert have?
Thinking....
>>> Robert W. Garner had twelve children, including the home person, Dr. Lewis Anderson Garner Sr. If you want to know more about any of his children, just let me know!
Enter your question: What were their names?
Thinking...............
>>> Here are the names of Robert W. Garner's children:
1. Lewis Anderson Garner Sr.
2. Phebe Garner
3. Mary J. Garner
4. Mary M. Garner
5. (No name listed)
6. Rebecca Catharine Garner
7. Zelpha Josephine Carr
8. Iola Elizabeth Betty Garner
9. Robert F. Garner
10. Emma A. Garner
11. Anetta Garner
12. Antoinette Garner
If you need further details about any of them, feel free to ask!
Enter your question: Who was born first?
Thinking...............
>>> The first child born to Robert W. Garner was Phebe Garner, born in 1850. If you have any more questions or need additional details, feel free to ask!
Of course, all LLM use caveats still apply: it can get things wrong!
Any way, if you want to try this the two files needed are here:
- addons-source/GrampsChat/chatbot.py at maintenance/gramps60 · gramps-project/addons-source · GitHub
- addons-source/GrampsChat/litellm_utils.py at maintenance/gramps60 · gramps-project/addons-source · GitHub
Instructions:
- Download the Python files from above, save both in a folder
- set the enviroment variables: GRAMPS_AI_MODEL_NAME, and your OPENAI_API_KEY (or whatever provider key you will use)
- Create a Gramps family tree named “Gramps Example” (or edit code)
- pip install litellm
python chatbot.py
Example:
pip install litellm
export GRAMPS_AI_MODEL_NAME="openai/gpt-4o"
export OPENAI_API_KEY="..."
python chatbot.py
My goal is to update the GrampsChat gramplet to do this, but I have to work out some threading issues.
Other notes:
- Other models may work, but it has to be smart enough to use structured output and tools.
- This could cost $$$$.
- There is no reason why these tools need to be read-only. One could delete, or add data to the database.
- I started with the home person in these examples because I don’t have it hooked up to a good query function/tool, and you need a handle. I’ll work on a general query (maybe there will be one in Gramps 6.1…)
Let me know if you find something interesting or useful!