Die AIUtils stehen nur zur Verfügung, wenn man das Modul „KI-Assistent“ lizenziert hat.
Code
IAIResult executeCustomPrompt(String modelPlainKey, IAIPrompt userPrompt)
IAIResult executeCustomPrompt(String modelPlainKey, IAIPrompt systemPrompt, IAIPrompt userPrompt)
IAIResult executeCustomPrompt(String modelPlainKey, AIStructuredOutputConfig structuredOutput, IAIPrompt systemPrompt, IAIPrompt userPrompt)
Beschreibung
Führt einen frei definierten User-Prompt mit einem bestimmten KI-Modell aus. Optional kann zusätzlich ein System-Prompt übergeben werden, um Verhalten, Rolle oder Antwortstil des Modells vorzugeben.
Im Unterschied zu executePrompt basiert executeCustomPrompt nicht auf einer Vorlage aus den CRM-Agenten, sondern arbeitet direkt mit übergebenen IAIPrompt-Objekten.
Optional kann außerdem eine AIStructuredOutputConfig übergeben werden. Damit wird die KI-Antwort in ein strukturiertes JSON-Format geführt, das anschließend programmatisch weiterverarbeitet werden kann.
Die Methode liefert immer ein IAIResult zurück. Im Erfolgsfall enthält es die Antwort der KI. Im Fehlerfall enthält es einen Fehlerstatus und eine auswertbare Fehlermeldung.
Parameter
-
modelPlainKey(String) - Der eindeutige Name des KI-Modells bzw. der Modellkonfiguration, die für den Aufruf verwendet werden soll, z. B."GPT-4"oder"MistralConfig". -
structuredOutput(AIStructuredOutputConfig) - optional DieAIStructuredOutputConfig, die das erwartete strukturierte Antwortformat vorgibt, erzeugbar z. B. überAIUtils.createStructuredConfig.Hinweis
Wird
structuredOutputübergeben, muss auchsystemPromptübergeben werden, gegebenenfallsnull. -
systemPrompt(IAIPrompt) - optional DasIAIPrompt-Objekt mit zusätzlichen Instruktionen für Verhalten, Rolle oder Antwortstil der KI. -
userPrompt(IAIPrompt) - DasIAIPrompt-Objekt mit dem eigentlichen Inhalt der Anfrage.
Rückgabe
IAIResult - Die Methode gibt immer ein IAIResult zurück.
-
Im Erfolgsfall enthält das Ergebnis die Antwort der KI.
-
Im Fehlerfall enthält das Ergebnis keinen verwertbaren KI-Inhalt, sondern einen Fehlerstatus sowie eine Fehlermeldung, die standardisiert ausgewertet werden kann.
Prüfen Sie das Ergebnis deshalb immer mit AIUtils.isAIResponseSuccessful(result).
Typischer Ablauf:
-
IAIResultentgegennehmen -
Erfolg prüfen
-
bei Erfolg Antwort auslesen
-
bei Fehler Fehlermeldung auslesen und geeignet anzeigen oder weiterverarbeiten
Beispiele
Ohne Structured-Output-Schema (Freitext)
String template = 'Write a friendly email to ${custom.Name}.'
Map<String, Object> userPromptVars = ["Name": "Rainer Zufall"]
IAIPrompt systemPrompt = AIUtils.getPrompt("GenericSystemPrompt", [:], "fvvvvvv29msd61j2jp3e9fAc")
IAIPrompt userPrompt = AIUtils.createPrompt(template, userPromptVars)
IAIResult result = AIUtils.executeCustomPrompt("MistralConfig", systemPrompt, userPrompt)
if (AIUtils.isAIResponseSuccessful(result)) {
String aiResponse = AIUtils.getAIResponseMessage(result)
} else {
String errorMessage = AIUtils.getAIResponseError(result)
}
Mit Structured-Output-Schema (Datenextraktion)
AIStructuredOutputConfig contactSchema = AIUtils.createStructuredConfig()
AIUtils.addString(
contactSchema,
"fullName",
true,
"Full name of the person"
)
AIUtils.addStringEnum(
contactSchema,
"category",
true,
"Business category of the request",
["SOFTWARE", "HARDWARE", "INVOICE", "SUPPORT", "OTHER"],
"OTHER"
)
AIUtils.addBoolean(
contactSchema,
"isCustomer",
false,
"Whether the person is already a customer. If not clearly recognizable, omit the field.",
false
)
AIStructuredOutputConfig addressSchema = AIUtils.createStructuredConfig()
AIUtils.addString(
addressSchema,
"city",
false,
"City of the person. If not recognizable, omit the field.",
"Unknown city"
)
AIUtils.addObject(
contactSchema,
"address",
false,
"Address of the person",
addressSchema
)
IAIPrompt extractionSystemPrompt = AIUtils.createPrompt(
"Extract structured CRM data from the text. Omit optional fields if the information is not clearly recognizable."
)
IAIPrompt extractionUserPrompt = AIUtils.createPrompt(
"Erika Mustermann from Frankfurt is already a customer and asks about a repair."
)
IAIResult extractionResult = AIUtils.executeCustomPrompt("MistralConfig", contactSchema, extractionSystemPrompt, extractionUserPrompt)
if (AIUtils.isAIResponseSuccessful(extractionResult)) {
Map<String, Object> data = AIUtils.getAIStructuredResponse(extractionResult)
ProcessUtils.setVariable("contactData", data)
} else {
String errorMessage = AIUtils.getAIResponseError(extractionResult)
}
Mit ScriptReturn (standardisierte Rückgabe)
Falls ein KI-Ergebnis in einem Skript standardisiert zurückgegeben werden soll, kann das IAIResult in ein ScriptReturn überführt werden.
IAIPrompt summaryPrompt = AIUtils.createPrompt("Summarize the following text in one sentence.")
IAIResult summaryResult = AIUtils.executeCustomPrompt("MistralConfig", summaryPrompt)
return AIUtils.toScriptReturn(summaryResult)