Building an LLM assistant for editing blog posts
By default, the gt4llm framework comes with an assistant for editing blog posts. To get a background on what an assistant is, refer to Handling custom instructions using assistants. For the purposes of this case study, it can be conceptualized as an AI agent with custom instructions.
This particular example relies on OpenAI. Before using it, please go to Adding an OpenAI API key to ensure you have the key setup.
As example, let's consider we have a string with a post we want to write. Like this one:
blogPostText := 'This is the start of a blog post on LLM. It ain’t much, but it’s mine.' asRopedText
And now, let's say we want to have a chat about it with a dedicated LLM:
GtOpenAIBlogPostAssistant new createChatOn: blogPostText
The above assistant has been evolved from a generic assistant. We can refine a generic assistant to get to a similar result. This page demonstrates how to do that.
We start by instantiating a generic assistant with a description.
assistant := GtLlmAssistant new description: 'You are an assistant that is used to interactively work on blog posts.'
We want the assistant to work with a Post format, so we create it and give information on how to serialize and deserialize the blog post for the assistant.
assistant addFormat: (GtLlmAssistantFormatDescription new type: 'string'; format: 'Text'; name: 'Post'; priority: 10). serializableText := GtLlmSerializableValueHolder new name: 'Post'; content: blogPostText; serializer: #asString; updater: [ :aText :aString | aText deleteAll appendString: aString; yourself ]
From there, we can create a chat and tell it to work with our text.
chat := assistant createChat. chat onInstance: serializableText
As of now, the assistant has no specific actions, however. Let’s add a simple one now.
assistant addAction: (GtLlmAssistantAction new name: 'Create title'; priority: 10; description: 'Create title. Put result in the `Text` property. Do not use quotes of any kind. Be crisp.')
Ideally, we would add examples, but since we have none, a description of the action will need to be enough. From here, we can reify the assistant. To do so, click on the reify button on any of the messages in the chat. You will be allowed to create an assistant class as well as a message class. The latter then allows you to add custom views for your messages, such as the diff view in GtOpenAIBlogPostAssistant
above.