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 a tutor and give it a description as well as overriding the provider to give it access to the files and file search capabilities. This is currently only available for the OpenAI assistant provider.

tutor := GtLlmTutor 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.';
		providerStencil: [ :anInstructionFormat | 
			GtOpenAIAssistantProvider withApiKeyFromFile
				format: anInstructionFormat asJsonSchema;
				assistantMessageClass: GtOpenAIActionMessage;
				userMessageClass: GtOpenAIActionMessage;
				addFile: (GtOpenAIResourceFile new
						file: aFile;
						description: 'Lepiter booklet: GToolkit book');
				addTool: (GtLlmTool new type: 'file_search');
				instructions: anInstructionFormat asInstructionPiece instructionString ].

tutor
  

Finally, we start a chat, asking it questions about GT or topics found in its RAG database.

chat := tutor createChat
  
chat sendMessage: 'What is Ludo?'