formentor-studio / magnolia-ai-training

Fine tuning of LLM models using contents in Magnolia CMS
0 stars 1 forks source link

Magnolia AI Training

This module of Magnolia CMS provides a tool to fine-tune Large language models like GPT using as input dataset contents in Magnolia CMS.

Features

Setup

  1. Add maven dependency to your bundle of Magnolia

    <dependencies>
    <dependency>
        <groupId>org.formentor</groupId>
        <artifactId>magnolia-ai-training</artifactId>
        <version>0.0.1</version>
    </dependency>
    </dependencies>
  2. Activate and configure Open AI or Azure OpenAI

OpenAI

config:/formentor-ai-training/openAI

open-ai-magnolia

openai-api-key

Azure OpenAI

config:/formentor-ai-training/azure

azure-magnolia

azure-openai-api-key

Usage

The module ai-training provides the command ModelTrainerCommand to create fine-tuned models

Input parameters of ModelTrainerCommand

Example

cm = info.magnolia.commands.CommandsManager.getInstance()
command = cm.getCommand('formentor','FineTuneModelCommand')

/**
 *
 * This example fine-tunes the model using as dataset:
 * INPUT: properties "tourTypes", "category" and "displayName" of nodtypes "mgnl:content" in the workspace "tours" from path "/magnolia-travels" 
 * COMPLETION: property "body"
 *
 * The fine-tuned model will be trained for the task of writing description of tours from the factsheet
 */
propertyPromptTourTypes = new com.formentor.magnolia.ai.training.domain.PropertyPromptValue()
propertyPromptTourTypes.setPropertyName('tourTypes')
reference = new com.formentor.magnolia.ai.training.domain.PropertyPromptValue.Reference()
reference.setTargetWorkspace("category")
reference.setTargetPropertyName("displayName")
propertyPromptTourTypes.setReference(reference)

propertyPromptLocation = new com.formentor.magnolia.ai.training.domain.PropertyPromptValue()
propertyPromptLocation.setPropertyName('location')

command.setWorkspace('tours')
command.setModelName('magnolia-tours')
command.setRoot('/magnolia-travels')
command.setNodeType('mgnl:content')
command.setPropertiesAsPrompt([propertyPromptTourTypes, propertyPromptLocation])
command.setPropertyAsCompletion(['body'])

command.execute(new info.magnolia.context.SimpleContext())