Annotation Interface SystemMessage
Specifies either a complete system message (prompt) or a system message template to be used each time an AI service is invoked.
An example:
An example:
An example:
When both
An example:
interface Assistant {
@SystemMessage("You are a helpful assistant")
String chat(String userMessage);
}
The system message can contain template variables,
which will be resolved with values from method parameters annotated with @V.
An example:
interface Assistant {
@SystemMessage("You are a {{characteristic}} assistant")
String chat(@UserMessage String userMessage, @V("characteristic") String characteristic);
}
It can also be declared on the AI Service interface, in which case it applies to all methods of that interface.
An example:
@SystemMessage("You are a helpful assistant")
interface Assistant {
String chat(String userMessage);
}
A @SystemMessage declared on a method takes precedence over one declared on the interface.
A @SystemMessage declared only on a parent interface is not inherited by a child AI Service interface.
When both
@SystemMessage and a system message provider
(see AiServices.systemMessageProvider(Function)) are configured,
@SystemMessage takes precedence.- See Also:
-
Optional Element Summary
Optional Elements
-
Element Details
-
value
String[] valuePrompt template can be defined in one line or multiple lines. If the template is defined in multiple lines, the lines will be joined with a delimiter defined below.- Default:
{""}
-
delimiter
String delimiter- Default:
"\n"
-
fromResource
String fromResourceThe resource from which to read the prompt template. If no resource is specified, the prompt template is taken fromvalue(). If the resource is not found, anIllegalConfigurationExceptionis thrown.The resource will be read by calling
Class.getResourceAsStream(String)on the interface this annotation is declared on: the AI Service interface for an interface-level annotation, or the interface declaring the method for a method-level one.- Default:
""
-