Objective : Creating a tool to write books.
I wrote some technical books in my life but I always wanted to write novel, I need a tool and AI will help me.
Check my previous articles about Agent AI for more details, here I will go faster to the point.
What I need:
Visual Studio Code
Github Copilot (agent that write the code for you, free with limit usage, 10/EUR month to make miracles)
Python
Ollama
a GPU on your computer.
The idea is to create a book without using online services, only in local, you need of course a GPU.
For this we will use ollama, which is really easy
Download the program from https://ollama.com/ and install it. Then run, you will see a little llama in your ashtray:
Ollama works with a lot of models but I notice that Phi4 is quite fast for creating my book.
Go to https://ollama.com/library/phi4
Open a CMD prompt and run ollama run phi4 , I have already installed in my system , the first time will download a model of ~9GB
To test the model you can already use like a chat.
Now you are ready to use it.
Ollama exposes some API automatically in your computer at http://127.0.0.1:11434/
Go to your browser and you will see the message, now you are ready to go.
Open visual studio, go to View >> Chat and you will see the chat option
My prompt this time will be:
I would like to make a client in python that let me :
Create a new book from scratch with Ollama installed in my computer
The app should save the information of my project in a json file, better if one json file per project.
The Idea it that the app request for a prompt with the idea of the book.
Ask for the name of the people, the role and a little background
Let the user select the number of chapters of the book.
When the use press create book, using the provided prompt and protagonist , it will create at first the chapters with the title and a little description that what will happen.
It will show to the user and then the user can change it and with a button it will call ollama passing the all book data to expand the chapter from 2000 to 5000 words.
The user can save all the time the project and reopen it.
At the end the app should permit the user to save the book in Word or PDF with a nice formating creating the summary , page numbers.
The user can provide also images for the front and back page of the book.
The Agent started to write the app asking some annoying info while he was doing it.
At the end I have my app ready to run.
Also it has created a requirement.txt
# MisterMRBookMaker Dependencies
# Core dependencies
requests>=2.25.1
# Word document processing
python-docx>=0.8.11
# PDF generation
reportlab>=3.6.1
# Image processing
Pillow>=8.3.1
I did run and found few little issues that I solved thought prompting, but 95% of the project was already working .
To runt he project i execute :
python src\main.py
The app started and I have the option to create a new book or open an existing project
When you clic on new he connect to the api of ollama and gets the list of AI Models.
As requested you can write the title, main idea/concept and add Characters
I am very impressed, I can add the characters with different roles and background
I wrote some data and added 3 characters, selected phi4 and press "create Book"
As requested I can see the book info on top that I can update
I didn't save the project yet. Go to File and you have all the options.
I saved the file, the file is a json file, you can open it with and editor to check the data.
When you press generate it shows a line moving
Then you got a summary of the chapter that you can change
I manually updated the title and press expand the chapter.
Now the first chapter is ready, you can change it.
I go faster and I create the other chapters, the speed of ollama depends on the model an in your GPU. Also the language, if you want to write in other language than English check if the model is compatible.
Now I go to File Export in PDF and to word
For my first book (that I even read yet.. look good (I made 17 pages)Attached to the article you can find the source code, and my "beautiful book" (it is a miracle if somebody will read it)
I asked also to the agent to make the .exe , he has created an script build_exe.py to create it.
you need to run
pip install pyinstaller
The file created is 40MB and cannot be attached to this article
You can find the .exe at this link: https://misterm.itch.io/mistermr-book-maker-ai-tool-made-by-ai
I hope you enjoy to read the article.
The power of agent AI are crazy, also ollama is a local chatgpt, you can use for so many things trough API. Sone model has vision (you can give images to get prompt or read data from images)