@@ -1956,6 +1956,11 @@ private AiServiceMethodCreateInfo.UserMessageInfo gatherUserMessageInfo(MethodIn
19561956 MethodParameterInfo pdfUrlParam = method .parameters ().get (pdfParamPosition .get ());
19571957 validatePdfUrlParam (pdfUrlParam );
19581958 }
1959+ Optional <Integer > videoParamPosition = determineVideoParamPosition (method );
1960+ if (videoParamPosition .isPresent ()) {
1961+ MethodParameterInfo videoUrlParam = method .parameters ().get (videoParamPosition .get ());
1962+ validateVideoUrlParam (videoUrlParam );
1963+ }
19591964
19601965 AnnotationInstance userMessageInstance = method .declaredAnnotation (LangChain4jDotNames .USER_MESSAGE );
19611966 if (userMessageInstance != null ) {
@@ -1974,7 +1979,7 @@ private AiServiceMethodCreateInfo.UserMessageInfo gatherUserMessageInfo(MethodIn
19741979 return AiServiceMethodCreateInfo .UserMessageInfo .fromTemplate (
19751980 AiServiceMethodCreateInfo .TemplateInfo .fromText (userMessageTemplate ,
19761981 TemplateParameterInfo .toNameToArgsPositionMap (templateParams )),
1977- userNameParamPosition , imageParamPosition , audioParamPosition , pdfParamPosition );
1982+ userNameParamPosition , imageParamPosition , audioParamPosition , pdfParamPosition , videoParamPosition );
19781983 } else {
19791984 Optional <AnnotationInstance > userMessageOnMethodParam = method .annotations (LangChain4jDotNames .USER_MESSAGE )
19801985 .stream ()
@@ -1987,11 +1992,13 @@ private AiServiceMethodCreateInfo.UserMessageInfo gatherUserMessageInfo(MethodIn
19871992 Short .valueOf (userMessageOnMethodParam .get ().target ().asMethodParameter ().position ())
19881993 .intValue (),
19891994 TemplateParameterInfo .toNameToArgsPositionMap (templateParams )),
1990- userNameParamPosition , imageParamPosition , audioParamPosition , pdfParamPosition );
1995+ userNameParamPosition , imageParamPosition , audioParamPosition , pdfParamPosition ,
1996+ videoParamPosition );
19911997 } else {
19921998 return AiServiceMethodCreateInfo .UserMessageInfo .fromMethodParam (
19931999 userMessageOnMethodParam .get ().target ().asMethodParameter ().position (),
1994- userNameParamPosition , imageParamPosition , audioParamPosition , pdfParamPosition );
2000+ userNameParamPosition , imageParamPosition , audioParamPosition , pdfParamPosition ,
2001+ videoParamPosition );
19952002 }
19962003 } else {
19972004 Set <String > templateParamNames = Collections .EMPTY_SET ;
@@ -2026,7 +2033,7 @@ private AiServiceMethodCreateInfo.UserMessageInfo gatherUserMessageInfo(MethodIn
20262033 return AiServiceMethodCreateInfo .UserMessageInfo .fromTemplate (
20272034 AiServiceMethodCreateInfo .TemplateInfo .fromText ("" , Map .of ()), Optional .empty (),
20282035 Optional .empty (),
2029- Optional .empty (), Optional .empty ());
2036+ Optional .empty (), Optional .empty (), Optional . empty () );
20302037 }
20312038
20322039 throw illegalConfigurationForMethod (
@@ -2038,11 +2045,11 @@ private AiServiceMethodCreateInfo.UserMessageInfo gatherUserMessageInfo(MethodIn
20382045 if (userMessageParamPosition == -1 ) {
20392046 // There is no user message
20402047 return new AiServiceMethodCreateInfo .UserMessageInfo (Optional .empty (), Optional .empty (), Optional .empty (),
2041- Optional .empty (), Optional .empty (), Optional .empty ());
2048+ Optional .empty (), Optional .empty (), Optional .empty (), Optional . empty () );
20422049 } else {
20432050 return AiServiceMethodCreateInfo .UserMessageInfo .fromMethodParam (userMessageParamPosition ,
20442051 userNameParamPosition ,
2045- imageParamPosition , audioParamPosition , pdfParamPosition );
2052+ imageParamPosition , audioParamPosition , pdfParamPosition , videoParamPosition );
20462053
20472054 }
20482055 }
@@ -2082,6 +2089,17 @@ private static Optional<Integer> determinePdfParamPosition(MethodInfo method) {
20822089 .map (pi -> (int ) pi .position ()).findFirst ();
20832090 }
20842091
2092+ private static Optional <Integer > determineVideoParamPosition (MethodInfo method ) {
2093+ Optional <Integer > result = method .annotations (LangChain4jDotNames .VIDEO_URL ).stream ().filter (
2094+ IS_METHOD_PARAMETER_ANNOTATION ).map (METHOD_PARAMETER_POSITION_FUNCTION ).findFirst ();
2095+ if (result .isPresent ()) {
2096+ return result ;
2097+ }
2098+ // we don't need @VideoUrl if the parameter is of type PdfFile
2099+ return method .parameters ().stream ().filter (pi -> pi .type ().name ().equals (LangChain4jDotNames .VIDEO ))
2100+ .map (pi -> (int ) pi .position ()).findFirst ();
2101+ }
2102+
20852103 private void validateImageUrlParam (MethodParameterInfo param ) {
20862104 if (param == null ) {
20872105 throw new IllegalArgumentException ("Unhandled @ImageUrl annotation" );
@@ -2121,6 +2139,19 @@ private void validatePdfUrlParam(MethodParameterInfo param) {
21212139 throw new IllegalArgumentException ("Unhandled @PdfUrl type '" + type .name () + "'" );
21222140 }
21232141
2142+ private void validateVideoUrlParam (MethodParameterInfo param ) {
2143+ if (param == null ) {
2144+ throw new IllegalArgumentException ("Unhandled @VideoUrl annotation" );
2145+ }
2146+ Type type = param .type ();
2147+ DotName typeName = type .name ();
2148+ if (typeName .equals (DotNames .STRING ) || typeName .equals (DotNames .URI ) || typeName .equals (DotNames .URL )
2149+ || typeName .equals (LangChain4jDotNames .VIDEO )) {
2150+ return ;
2151+ }
2152+ throw new IllegalArgumentException ("Unhandled @VideoUrl type '" + type .name () + "'" );
2153+ }
2154+
21242155 private Optional <AiServiceMethodCreateInfo .MetricsTimedInfo > gatherMetricsTimedInfo (MethodInfo method ,
21252156 boolean addMicrometerMetrics ) {
21262157 if (!addMicrometerMetrics ) {
0 commit comments