Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Generative AI client has been designed to allow running custom Groovy scripts. The scripts can do many different tasks but they are most useful when Generative AI services are needed to be called for crawled documents and the results from those calls are to be put in the document for later indexing. When writing Groovy scripts we can use so called binding variables to simplify AI related tasks:

  • REST client comes configured with required authentication methods based on UI parameters
  • REST client can be configured how to handle automatically typical throttling issues - like 429 errors
  • Methods for creating POST body for typical AI tasks are present
  • Methods for allowing REST calls for typical AI URLs are present
  • The REST call response comes in typical fashion for easy parsing and using it in the document
  • Support for general template scripts is here to allow selection of already prepared scripts with the support of template script properties
  • If secret information must be used in Groovy script they can be defined in UI, stored as encrypted and use as automatically decrypted in the scripts
  • Typical scenarios for running embeddings and prompts related tasks are built in and can be used with just several lines of Groovy script
  • Support for different AI services providers is supported - we support Azure and Google Palm in the present version

Easy Heading Free
navigationTitleOn this Page
wrapNavigationTexttrue
navigationExpandOptionexpand-all-by-default

Binding variables


Name in scriptDescriptionAspire typeInit scriptProcess script
docCrawled documentAspireObjectfalsetrue
componentAspire workflow component running Groovy scriptsComponentImpltruetrue
connection.clientREST client component for making AI callsGenAIRestRequestertruetrue

utilities.azure.embeddings

utilities.google.embeddings

Methods related to "embeddings" processingEmbeddingstruetrue

job

Job containing the crawled documentJobfalsetrue

secrets

Map of secrets provided in UIMap<String,String>truetrue

template

Map of selected script template variablesMap<String,String>truetrue

utilities.azure.prompts

utilities.google.prompts

Methods related to "prompts" processingPromptstruetrue

utilities.textSplitter

Method related to text splittingTextSplitterComponenttruetrue

variables

Map of variables provided in initialize scriptMap<String,Object>truefalse

utilities

Various helper methodsUtilstruetrue

Document

The crawled document can be used for accessing metadata and the content and also for storing a new metadata acquired from AI:

Code Block
languagegroovy
doc.add(embeddings.toAspireObject());

Component

The component can typically be used as a logger:

Code Block
languagegroovy
  component.info(" %s","${doc.id}: Got embeddings for sentence: ${currentSentence}")

Connection

// TODO

Authentication

Request

Response

Throttling, 429 Policy

Embeddings

// TODO

utilities.azure.embeddings, utilities.google.embeddings
MethodSyntaxInit scriptProcess script
Initialize Azurevoid utilities.azure.initialize(AspireObject config)truefalse

config:

NameDescriptionDefault
endpoint

model

apiVersion

apiKey



Initialize Google Palm

void utilities.google.initialize(AspireObject config)

truefalse

config:

NameDescriptionDefault
endpoint

model

apiVersion

apiKey




Process

VectorEmbeddingResult utilities.azure.embeddings.process(List<String> splitText)

VectorEmbeddingResult utilities.google.embeddings.process(List<String> splitText)

VectorEmbeddingResult:

TODO

splitText:

TODO

falsetrue
Convert response

VectorEmbeddingsResult utilities.azure.embeddings.convertResponse(String text,  AspireObjectResponse response)

VectorEmbeddingsResult utilities.google.embeddings.convertResponse(String text,  AspireObjectResponse response)

VectorEmbeddingsResult:

TODO

response:

TODO



Create POST body

AspireObject utilities.azure.embeddings.createPostBody(String text)



Create Sub document

AspireObject utilities.azure.embeddings.createSubDoc(VectorEmbeddingsResult vectorEmbeddingsResult, AspireObject doc, int chunkCount)



Example init script:

Code Block
languagegroovy
import com.accenture.aspire.services.AspireObject;

utilities.textSplitter.initialize(getTextSplitterConfig("sentence"))
utilities.azure.embeddings.initialize(getEmbeddingsConfig())

def getEmbeddingsConfig() {
    AspireObject returnValue = new AspireObject("config");
    returnValue.add("endpoint", "${template.endpoint}");
    returnValue.add("model", "${template.model}");
    returnValue.add("apiVersion", "${template.apiVersion}");
    returnValue.add("apiKey", "${secrets.apiKey}");
    return returnValue;
}

def getTextSplitterConfig(String splitType) {
  .....
}

Example script:

Code Block
languagegroovy
def sentences = utilities.textSplitter.process(doc);
embeddings = utilities.azure.embeddings.process(sentences);
doc.add(embeddings.toAspireObject());

Example script:

Code Block
languagegroovy
import com.accenture.aspire.services.AspireException

// split field "content" and create "sentences"
def sentences = utilities.textSplitter.process(doc);

// url
endpointEmbeddings = "${template.endpoint}/openai/deployments/${template.model}/embeddings?api-version=${template.apiVersion}"

// generate and publish embeddings
sentences.eachWithIndex {currentSentence, sentencesCount ->
  embeddingVector = getEmbeddingsFromSentence(endpointEmbeddings, currentSentence)
  subJobAO = utilities.azure.embeddings.createSubDoc(embeddingVector, doc, sentencesCount);
  utilities.createSubJob(job, subJobAO)
}

def getEmbeddingsFromSentence(endpointEmbeddings, sentence) {
  response = connection.client.executePost(endpointEmbeddings, utilities.azure.embeddings.createPostBody(sentence));
  def embeddings = utilities.azure.embeddings.convertResponse(sentence, response)
  return embeddings
}

Job

Job can be used when required as a parameter for other methods:

Code Block
languagegroovy
utilities.createSubJob(job, subJobAO)

Secrets

Secrets defined in UI which are stored as encrypted can be accessed in scripts:. They are automatically decrypted before using them.

Code Block
languagegroovy
client.addHeader("api-key", "${secrets.apiKey}");

Template

If in UI a template script with properties has been selected we can access those properties in the script:

Code Block
languagegroovy
def getEmbeddingsConfig() {
    AspireObject returnValue = new AspireObject("config");
    returnValue.add("endpoint", "${template.endpoint}");
    ....
}
Code Block
languagegroovy
// url
endpointEmbeddings = "${template.endpoint}/openai/deployments/${template.model}/embeddings?api-version=${template.apiVersion}"

Prompts

// TODO

Text Splitter

// TODO

Text splitterutilities.textSplitter
MethodSyntaxInit scriptProcess script
Initializevoid utilities.textSplitter.initialize(AspireObject config)truefalse

config:

NameDescriptionDefault
splitType

fieldsToSplit

customSplitRegex

characterThreshold



Process

List<String> utilities.textSplitter.process(AspireObject doc)

List<String>:

TODO

doc:

TODO

falsetrue

Example init of initialization script:

Code Block
languagegroovy
import com.accenture.aspire.services.AspireObject;

utilities.textSplitter.initialize(getTextSplitterConfig("sentence"))

def getTextSplitterConfig(String splitType) {
    AspireObject returnValue = new AspireObject("config");
    returnValue.add("splitType", splitType);
    returnValue.add("fieldsToSplit", "content");
    returnValue.add("customSplitRegex", "\\|+");
    returnValue.add("characterThreshold", 4);
    return returnValue;
}

Example script:

Code Block
languagegroovy
def sentences = utilities.textSplitter.process(doc);

Variables

// TODO

Utilities

REST connection 

Authentication

Request

Response

Throttling, 429 Policy

// TODO