Adding tools to chats
OpenAI, Ollama, Google Gemini, and Anthropic chats have, when instructed how, the capability to request function calls to be performed. Assistants mirror that capability.
To use it, we first need to define the function.
tool := GtLFunctionTool new
name: 'lookupDocumentationPage';
parameters: {'pageName'};
description: 'Looks up a documentation page by name and returns its content in Markdown format. `pageName` may be a substring. If multiple pages are found, only the first one will be returned.';
block: [ :aFunctionCall |
(LeDatabase gtBook asyncPagesForWord: aFunctionCall anyArgument) toArray wait
ifEmpty: [ 'No page found' ]
ifNotEmpty: [ :pages | pages first asMarkdownPage ] ]
First we create a chat as before, adding the tool.
chat := GtLChat new. chat addTool: tool. chat sendMarkdown: 'Tell me about gt4llm.'
There exist also explicit tools already implemented as subclasses of GtLAbstractFunctionTool
:
chat := GtLChat new. chat tools: GtLTools leSearch. chat sendMarkdown: 'Tell me about gt4llm.'