Package dev.langchain4j.service
Annotation Interface UserMessage
Specifies either a complete user message or a user message template to be used each time an AI service is invoked.
The user message can contain template variables,
which will be resolved with values from method parameters annotated with @
An example:
V
.
An example:
interface Assistant {
@UserMessage
("Say hello to {{name}}")
String greet(@V("name") String name);
}
@UserMessage
can also be used with method parameters:
interface Assistant {
@SystemMessage
("You are a {{characteristic}} assistant")
String chat(@UserMessage String userMessage, @V("characteristic") String characteristic);
}
In this case String userMessage
can contain unresolved template variables (e.g. "{{characteristic}}"),
which will be resolved using the values of method parameters annotated with @V
.- See Also:
-
Optional Element Summary
-
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, anIllegalConfigurationException
is thrown.The resource will be read by calling
Class.getResourceAsStream(String)
on the AI Service class (interface).- Default:
""
-