Adding the GT book to a LLM to answer questions about GT
OpenAI assistants have a builtin RAG system based on files. This means that we can provide it with knowledge sourced from the Glamorous Toolkit Book.
We begin by taking all the pages from GT book, and creating a file we can upload to OpenAI and provide to the tutor.
pages := LeDatabase gtBook pages
aFile := FileLocator temp / 'GToolkitBook.txt'. aFile ensureDelete. aFile writeStreamDo: [ :aStream | pages do: [ :aPage | aStream nextPutAll: aPage asMarkdownPage ] ].
Then, we create an assistant and give it a description as well as overriding the provider to OpenAI assistant, since file search is currently only available for that provider and the response provider.
assistant := GtLlmAssistant new description: 'You are an assistant that answers questions about Glamorous Toolkit (also: GToolkit or GT) by referring to the GToolkit book provided to you.'; connection: (GtLlmConnection new model: 'gpt-4.1'; provider: GtOpenAIAssistantProvider). assistant
Finally, we start a chat, add the file and tool to the provider, and start asking it questions about GT or topics found in its RAG database.
chat := assistant createChat.
chat provider addFile: (GtOpenAIResourceFile new file: aFile; description: 'Lepiter booklet: GToolkit book'); addTool: (GtLlmTool new type: 'file_search'); createAssistant
chat sendChatRequest: 'What is Ludo?'