Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

Dependency conflicts with Azure openai integration with AEM

Avatar

Level 4

Hello all,

 

I am trying to integrate the Azure openai with AEM. Following the below documentation

https://learn.microsoft.com/en-us/azure/ai-services/openai/quickstart?pivots=programming-language-ja... 

 

I am using the below dependency and added the

<dependency>
            <groupId>com.azure</groupId>
            <artifactId>azure-ai-openai</artifactId> 
            <version>1.0.0-beta.3</version>                   
        </dependency>	
        
		<dependency>
		    <groupId>com.azure</groupId>
		    <artifactId>azure-core</artifactId>   
		    <version>1.42.0</version>
		</dependency>

 To resolve the above dependency exported the package as below

<plugin>
                <groupId>biz.aQute.bnd</groupId>
                <artifactId>bnd-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>bnd-process</id>
                        <goals>
                            <goal>bnd-process</goal>
                        </goals>
                        <configuration>
                            <bnd><![CDATA[
Import-Package: javax.annotation;version=0.0.0,*

Export-Package: com.azure.ai.openai.*,com.azure.core.*
                                ]]></bnd>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

 

But I keep getting new dependency issues, any pointer would be helpful

dependency.png

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @SwetaB,

In the majority of instances involving third-party bundles, the resolution of the Maven dependency in both the main pom.xml and the core pom.xml results in the successful inclusion of the required bundle.

Nevertheless, there are situations where this automatic process does not occur as expected. In such scenarios, it becomes necessary to prepare the dependency for OSGi compatibility and then embed it into the system.

To accomplish this, you can refer to the instructions provided in the documentation. 
https://myaemlearnings.blogspot.com/2021/08/embedding-third-party-dependencyosgi.html

For detailed changes and procedures, you can refer to this GitHub commit: https://github.com/Sady-Rifat/aem-demo/commit/65f8ce112744134728bf2f85d7bc5f131a2ef290

 

Same problem is being discussed here: https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/including-third-party-bund... 

View solution in original post

7 Replies

Avatar

Employee

you need to add includeresource after Export-Package

 

Example : 

 

<plugin>
                <groupId>biz.aQute.bnd</groupId>
                <artifactId>bnd-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>bnd-process</id>
                        <goals>
                            <goal>bnd-process</goal>
                        </goals>
                        <configuration>
                            <bnd><![CDATA[
Import-Package: javax.annotation;version=0.0.0,*
Export-Package: com.azure.ai.openai.*,com.azure.core.*
-includeresource: azure-ai-openai-*.jar;lib:=true, azure-core-*.jar;lib:=true
                                ]]></bnd>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

 

 

Avatar

Level 4

Hi Nishant,

 

I did add before the jar in using the include resource with specific java class and export package as

-includeresource: @azure-ai-openai-1.0.0-beta.3.jar!/*,@azure-core-1.42.0.jar!/*,@azure-xml-1.0.0-beta.2.jar!/*,@azure-json-1.1.0.jar!/*

well though it is resolving the main dependencies of 'com.azure.opeai',

'com.azure.core' 'com.azure.json', 'com.azure.xml' but creating more new dependencies.

SwetaB_1-1692347311230.png

 

 

Avatar

Correct answer by
Community Advisor

Hi @SwetaB,

In the majority of instances involving third-party bundles, the resolution of the Maven dependency in both the main pom.xml and the core pom.xml results in the successful inclusion of the required bundle.

Nevertheless, there are situations where this automatic process does not occur as expected. In such scenarios, it becomes necessary to prepare the dependency for OSGi compatibility and then embed it into the system.

To accomplish this, you can refer to the instructions provided in the documentation. 
https://myaemlearnings.blogspot.com/2021/08/embedding-third-party-dependencyosgi.html

For detailed changes and procedures, you can refer to this GitHub commit: https://github.com/Sady-Rifat/aem-demo/commit/65f8ce112744134728bf2f85d7bc5f131a2ef290

 

Same problem is being discussed here: https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/including-third-party-bund... 

Avatar

Level 2

I followed above solution, but getting below issue:

"Could not initialize class com.azure.ai.openai.OpenAIClientBuilder"

Caused by: java.lang.ExceptionInInitializerError: Exception java.lang.LinkageError: loader constraint violation: when resolving method "org.slf4j.impl.StaticLoggerBinder.getLoggerFactory()Lorg/slf4j/ILoggerFactory;"

 

 

 

 

 

2.08.2023 19:36:05.022 *ERROR* [[0:0:0:0:0:0:0:1] [1692713165019] GET /bin/generative/ai/desc HTTP/1.1] org.apache.sling.engine.impl.SlingRequestProcessorImpl service: Uncaught Throwable
java.lang.NoClassDefFoundError: Could not initialize class com.azure.ai.openai.OpenAIClientBuilder
	at com.adobe.aem.azurechatgtp.core.servlets.GenerateInfServlet.generateMessage2(GenerateInfServlet.java:48) [aem-azurechatgtp.core:0.0.1.SNAPSHOT]
	at com.adobe.aem.azurechatgtp.core.servlets.GenerateInfServlet.doGet(GenerateInfServlet.java:38) [aem-azurechatgtp.core:0.0.1.SNAPSHOT]
	at org.apache.sling.api.servlets.SlingSafeMethodsServlet.mayService(SlingSafeMethodsServlet.java:266) [org.apache.sling.api:2.22.0.B002]
	at org.apache.sling.api.servlets.SlingSafeMethodsServlet.service(SlingSafeMethodsServlet.java:342) [org.apache.sling.api:2.22.0.B002]
	at org.apache.sling.api.servlets.SlingSafeMethodsServlet.service(SlingSafeMethodsServlet.java:374) [org.apache.sling.api:2.22.0.B002]
	at org.apache.sling.engine.impl.request.RequestData.service(RequestData.java:579) [org.apache.sling.engine:2.7.10.B0004]
	at org.apache.sling.engine.impl.filter.SlingComponentFilterChain.render(SlingComponentFilterChain.java:45) [org.apache.sling.engine:2.7.10.B0004]
	at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:88) [org.apache.sling.engine:2.7.10.B0004]
	at com.day.cq.wcm.core.impl.WCMDebugFilter.doFilter(WCMDebugFilter.java:156) [com.day.cq.wcm.cq-wcm-core:5.12.230]
	at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:78) [org.apache.sling.engine:2.7.10.B0004]
	at com.day.cq.wcm.core.impl.WCMComponentFilter.filterRootInclude(WCMComponentFilter.java:375) [com.day.cq.wcm.cq-wcm-core:5.12.230]
	at com.day.cq.wcm.core.impl.WCMComponentFilter.doFilter(WCMComponentFilter.java:190) [com.day.cq.wcm.cq-wcm-core:5.12.230]
	at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:78) [org.apache.sling.engine:2.7.10.B0004]
	at com.day.cq.wcm.core.impl.page.PageLockFilter.doFilter(PageLockFilter.java:91) [com.day.cq.wcm.cq-wcm-core:5.12.230]
	at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:78) [org.apache.sling.engine:2.7.10.B0004]
	at com.day.cq.personalization.impl.TargetComponentFilter.doFilter(TargetComponentFilter.java:94) [com.day.cq.cq-personalization:5.12.48]
	at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:78) [org.apache.sling.engine:2.7.10.B0004]
	at org.apache.sling.engine.impl.SlingRequestProcessorImpl.processComponent(SlingRequestProcessorImpl.java:283) [org.apache.sling.engine:2.7.10.B0004]
	at org.apache.sling.engine.impl.filter.RequestSlingFilterChain.render(RequestSlingFilterChain.java:49) [org.apache.sling.engine:2.7.10.B0004]
	at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:82) [org.apache.sling.engine:2.7.10.B0004]
	at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:84) [org.apache.sling.engine:2.7.10.B0004]
	at com.day.cq.wcm.core.impl.warp.TimeWarpFilter.doFilter(TimeWarpFilter.java:109) [com.day.cq.wcm.cq-wcm-core:5.12.230]
	at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:78) [org.apache.sling.engine:2.7.10.B0004]
	at com.adobe.cq.social.ugcbase.security.impl.SaferSlingPostServlet.doFilter(SaferSlingPostServlet.java:114) [com.adobe.cq.social.cq-social-ugcbase-impl:2.5.3]
	at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:78) [org.apache.sling.engine:2.7.10.B0004]
	at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:84) [org.apache.sling.engine:2.7.10.B0004]
	at com.day.cq.dam.core.impl.assetlinkshare.AdhocAssetShareAuthHandler.doFilter(AdhocAssetShareAuthHandler.java:440) [com.day.cq.dam.cq-dam-core:5.12.366]
	at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:78) [org.apache.sling.engine:2.7.10.B0004]
	at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:84) [org.apache.sling.engine:2.7.10.B0004]
	at com.day.cq.dam.core.impl.servlet.ActivityRecordHandler.doFilter(ActivityRecordHandler.java:141) [com.day.cq.dam.cq-dam-core:5.12.366]
	at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:78) [org.apache.sling.engine:2.7.10.B0004]
	at com.adobe.granite.rest.impl.servlet.ApiResourceFilter.doFilter(ApiResourceFilter.java:70) [com.adobe.granite.rest.api:1.1.16.CQ650-B0005]
	at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:78) [org.apache.sling.engine:2.7.10.B0004]
	at com.adobe.granite.requests.logging.impl.RequestLoggerImpl.doFilter(RequestLoggerImpl.java:121) [com.adobe.granite.requests.logging:1.0.20]
	at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:78) [org.apache.sling.engine:2.7.10.B0004]
	at com.adobe.granite.rest.assets.impl.AssetContentDispositionFilter.doFilter(AssetContentDispositionFilter.java:96) [com.adobe.granite.rest.assets:1.0.58]
	at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:78) [org.apache.sling.engine:2.7.10.B0004]
	at com.day.cq.wcm.core.impl.AuthoringUIModeServiceImpl.doFilter(AuthoringUIModeServiceImpl.java:394) [com.day.cq.wcm.cq-wcm-core:5.12.230]
	at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:78) [org.apache.sling.engine:2.7.10.B0004]
	at com.day.cq.wcm.mobile.core.impl.redirect.RedirectFilter.doFilter(RedirectFilter.java:248) [com.day.cq.wcm.cq-wcm-mobile-core:5.11.10]
	at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:78) [org.apache.sling.engine:2.7.10.B0004]
	at com.adobe.aem.azurechatgtp.core.filters.LoggingFilter.doFilter(LoggingFilter.java:58) [aem-azurechatgtp.core:0.0.1.SNAPSHOT]
	at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:78) [org.apache.sling.engine:2.7.10.B0004]
	at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:84) [org.apache.sling.engine:2.7.10.B0004]
	at org.apache.sling.engine.impl.debug.RequestProgressTrackerLogFilter.doFilter(RequestProgressTrackerLogFilter.java:110) [org.apache.sling.engine:2.7.10.B0004]
	at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:78) [org.apache.sling.engine:2.7.10.B0004]
	at com.adobe.cq.social.commons.cors.CORSAuthenticationFilter.doFilter(CORSAuthenticationFilter.java:91) [com.adobe.cq.social.cq-social-commons:1.10.87]
	at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:78) [org.apache.sling.engine:2.7.10.B0004]
	at com.day.cq.wcm.foundation.forms.FormsHandlingServletHelper.handleFilter(FormsHandlingServletHelper.java:226) [com.day.cq.wcm.cq-wcm-foundation:5.12.64]
	at com.day.cq.wcm.foundation.forms.impl.FormsHandlingServlet.doFilter(FormsHandlingServlet.java:138) [com.day.cq.wcm.cq-wcm-foundation:5.12.64]
	at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:78) [org.apache.sling.engine:2.7.10.B0004]
	at com.adobe.granite.optout.impl.OptOutFilter.doFilter(OptOutFilter.java:76) [com.adobe.granite.optout:1.0.0]
	at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:78) [org.apache.sling.engine:2.7.10.B0004]
	at com.day.cq.wcm.foundation.forms.FormsHandlingServletHelper.handleFilter(FormsHandlingServletHelper.java:226) [com.day.cq.wcm.cq-wcm-foundation:5.12.64]
	at com.adobe.cq.wcm.core.components.internal.servlets.CoreFormHandlingServlet.doFilter(CoreFormHandlingServlet.java:123)
	at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:78) [org.apache.sling.engine:2.7.10.B0004]
	at com.day.cq.wcm.core.impl.WCMRequestFilter.doFilter(WCMRequestFilter.java:90) [com.day.cq.wcm.cq-wcm-core:5.12.230]
	at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:78) [org.apache.sling.engine:2.7.10.B0004]
	at com.adobe.cq.history.impl.HistoryRequestFilter.doFilter(HistoryRequestFilter.java:122) [com.adobe.cq.cq-history:5.10.6]
	at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:78) [org.apache.sling.engine:2.7.10.B0004]
	at org.apache.sling.rewriter.impl.RewriterFilter.doFilter(RewriterFilter.java:87) [org.apache.sling.rewriter:1.2.2]
	at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:78) [org.apache.sling.engine:2.7.10.B0004]
	at com.adobe.granite.httpcache.impl.InnerCacheFilter.doFilter(InnerCacheFilter.java:81) [com.adobe.granite.httpcache.core:1.0.8]
	at com.adobe.granite.httpcache.impl.InnerCacheFilter.doFilter(InnerCacheFilter.java:60) [com.adobe.granite.httpcache.core:1.0.8]
	at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:78) [org.apache.sling.engine:2.7.10.B0004]
	at org.apache.sling.i18n.impl.I18NFilter.doFilter(I18NFilter.java:131) [org.apache.sling.i18n:2.5.14]
	at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:78) [org.apache.sling.engine:2.7.10.B0004]
	at com.adobe.granite.csrf.impl.CSRFFilter.doFilter(CSRFFilter.java:217) [com.adobe.granite.csrf:1.0.20.CQ650-B0002]
	at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:78) [org.apache.sling.engine:2.7.10.B0004]
	at org.apache.sling.security.impl.ContentDispositionFilter.doFilter(ContentDispositionFilter.java:152) [org.apache.sling.security:1.1.16]
	at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:78) [org.apache.sling.engine:2.7.10.B0004]
	at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:84) [org.apache.sling.engine:2.7.10.B0004]
	at com.adobe.granite.resourceresolverhelper.impl.ResourceResolverHelperImpl.doFilter(ResourceResolverHelperImpl.java:83) [com.adobe.granite.resourceresolverhelper:1.0.4]
	at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:78) [org.apache.sling.engine:2.7.10.B0004]
	at org.apache.sling.engine.impl.SlingRequestProcessorImpl.doProcessRequest(SlingRequestProcessorImpl.java:151) [org.apache.sling.engine:2.7.10.B0004]
	at org.apache.sling.engine.impl.SlingMainServlet.service(SlingMainServlet.java:250) [org.apache.sling.engine:2.7.10.B0004]
	at org.apache.felix.http.base.internal.handler.ServletHandler.handle(ServletHandler.java:126) [org.apache.felix.http.jetty:4.2.2]
	at org.apache.felix.http.base.internal.dispatch.InvocationChain.doFilter(InvocationChain.java:86) [org.apache.felix.http.jetty:4.2.2]
	at com.adobe.granite.cors.impl.CORSFilter.doFilter(CORSFilter.java:88) [com.adobe.granite.cors:1.0.10.CQ650-B0002]
	at org.apache.felix.http.base.internal.handler.FilterHandler.handle(FilterHandler.java:149) [org.apache.felix.http.jetty:4.2.2]
	at org.apache.felix.http.base.internal.dispatch.InvocationChain.doFilter(InvocationChain.java:81) [org.apache.felix.http.jetty:4.2.2]
	at com.adobe.granite.license.impl.LicenseCheckFilter.doFilter(LicenseCheckFilter.java:308) [com.adobe.granite.license:1.2.10]
	at org.apache.felix.http.base.internal.handler.FilterHandler.handle(FilterHandler.java:149) [org.apache.felix.http.jetty:4.2.2]
	at org.apache.felix.http.base.internal.dispatch.InvocationChain.doFilter(InvocationChain.java:81) [org.apache.felix.http.jetty:4.2.2]
	at org.apache.sling.i18n.impl.I18NFilter.doFilter(I18NFilter.java:131) [org.apache.sling.i18n:2.5.14]
	at org.apache.felix.http.base.internal.handler.FilterHandler.handle(FilterHandler.java:149) [org.apache.felix.http.jetty:4.2.2]
	at org.apache.felix.http.base.internal.dispatch.InvocationChain.doFilter(InvocationChain.java:81) [org.apache.felix.http.jetty:4.2.2]
	at org.apache.sling.featureflags.impl.FeatureManager.doFilter(FeatureManager.java:116) [org.apache.sling.featureflags:1.2.2]
	at org.apache.felix.http.base.internal.handler.FilterHandler.handle(FilterHandler.java:149) [org.apache.felix.http.jetty:4.2.2]
	at org.apache.felix.http.base.internal.dispatch.InvocationChain.doFilter(InvocationChain.java:81) [org.apache.felix.http.jetty:4.2.2]
	at org.apache.sling.engine.impl.log.RequestLoggerFilter.doFilter(RequestLoggerFilter.java:73) [org.apache.sling.engine:2.7.10.B0004]
	at org.apache.felix.http.base.internal.handler.FilterHandler.handle(FilterHandler.java:149) [org.apache.felix.http.jetty:4.2.2]
	at org.apache.felix.http.base.internal.dispatch.InvocationChain.doFilter(InvocationChain.java:81) [org.apache.felix.http.jetty:4.2.2]
	at org.apache.sling.engine.impl.parameters.RequestParameterSupportConfigurer.doFilter(RequestParameterSupportConfigurer.java:67) [org.apache.sling.engine:2.7.10.B0004]
	at org.apache.felix.http.base.internal.handler.FilterHandler.handle(FilterHandler.java:149) [org.apache.felix.http.jetty:4.2.2]
	at org.apache.felix.http.base.internal.dispatch.InvocationChain.doFilter(InvocationChain.java:81) [org.apache.felix.http.jetty:4.2.2]
	at org.apache.felix.http.base.internal.dispatch.Dispatcher$1.doFilter(Dispatcher.java:152) [org.apache.felix.http.jetty:4.2.2]
	at org.apache.felix.http.base.internal.whiteboard.WhiteboardManager$2.doFilter(WhiteboardManager.java:1000) [org.apache.felix.http.jetty:4.2.2]
	at com.adobe.granite.cors.impl.CORSFilter.doFilter(CORSFilter.java:88) [com.adobe.granite.cors:1.0.10.CQ650-B0002]
	at org.apache.felix.http.base.internal.handler.PreprocessorHandler.handle(PreprocessorHandler.java:137) [org.apache.felix.http.jetty:4.2.2]
	at org.apache.felix.http.base.internal.whiteboard.WhiteboardManager$2.doFilter(WhiteboardManager.java:1006) [org.apache.felix.http.jetty:4.2.2]
	at com.adobe.granite.auth.oauth.impl.OAuthCallbackFilter.doFilter(OAuthCallbackFilter.java:69) [com.adobe.granite.auth.oauth:1.7.2]
	at org.apache.felix.http.base.internal.handler.PreprocessorHandler.handle(PreprocessorHandler.java:137) [org.apache.felix.http.jetty:4.2.2]
	at org.apache.felix.http.base.internal.whiteboard.WhiteboardManager$2.doFilter(WhiteboardManager.java:1006) [org.apache.felix.http.jetty:4.2.2]
	at com.adobe.granite.auth.ims.impl.IMSClusterExchangeTokenPreprocessor.doFilter(IMSClusterExchangeTokenPreprocessor.java:281) [com.adobe.granite.auth.ims:1.3.12.CQ650-B0014]
	at org.apache.felix.http.base.internal.handler.PreprocessorHandler.handle(PreprocessorHandler.java:137) [org.apache.felix.http.jetty:4.2.2]
	at org.apache.felix.http.base.internal.whiteboard.WhiteboardManager$2.doFilter(WhiteboardManager.java:1006) [org.apache.felix.http.jetty:4.2.2]
	at org.apache.sling.security.impl.ReferrerFilter.doFilter(ReferrerFilter.java:326) [org.apache.sling.security:1.1.16]
	at org.apache.felix.http.base.internal.handler.PreprocessorHandler.handle(PreprocessorHandler.java:137) [org.apache.felix.http.jetty:4.2.2]
	at org.apache.felix.http.base.internal.whiteboard.WhiteboardManager$2.doFilter(WhiteboardManager.java:1006) [org.apache.felix.http.jetty:4.2.2]
	at org.apache.felix.http.sslfilter.internal.SslFilter.doFilter(SslFilter.java:97) [org.apache.felix.http.sslfilter:1.2.6]
	at org.apache.felix.http.base.internal.handler.PreprocessorHandler.handle(PreprocessorHandler.java:137) [org.apache.felix.http.jetty:4.2.2]
	at org.apache.felix.http.base.internal.whiteboard.WhiteboardManager$2.doFilter(WhiteboardManager.java:1006) [org.apache.felix.http.jetty:4.2.2]
	at org.apache.felix.http.base.internal.whiteboard.WhiteboardManager.invokePreprocessors(WhiteboardManager.java:1010) [org.apache.felix.http.jetty:4.2.2]
	at org.apache.felix.http.base.internal.dispatch.Dispatcher.dispatch(Dispatcher.java:94) [org.apache.felix.http.jetty:4.2.2]
	at org.apache.felix.http.base.internal.dispatch.DispatcherServlet.service(DispatcherServlet.java:49) [org.apache.felix.http.jetty:4.2.2]
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:764) [org.apache.felix.http.servlet-api:1.2.0]
	at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:799) [org.apache.felix.http.jetty:4.2.2]
	at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:554) [org.apache.felix.http.jetty:4.2.2]
	at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:233) [org.apache.felix.http.jetty:4.2.2]
	at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1624) [org.apache.felix.http.jetty:4.2.2]
	at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:233) [org.apache.felix.http.jetty:4.2.2]
	at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1440) [org.apache.felix.http.jetty:4.2.2]
	at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:188) [org.apache.felix.http.jetty:4.2.2]
	at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:505) [org.apache.felix.http.jetty:4.2.2]
	at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1594) [org.apache.felix.http.jetty:4.2.2]
	at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:186) [org.apache.felix.http.jetty:4.2.2]
	at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1355) [org.apache.felix.http.jetty:4.2.2]
	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141) [org.apache.felix.http.jetty:4.2.2]
	at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:191) [org.apache.felix.http.jetty:4.2.2]
	at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127) [org.apache.felix.http.jetty:4.2.2]
	at org.eclipse.jetty.server.Server.handle(Server.java:516) [org.apache.felix.http.jetty:4.2.2]
	at org.eclipse.jetty.server.HttpChannel.lambda$handle$1(HttpChannel.java:487) [org.apache.felix.http.jetty:4.2.2]
	at org.eclipse.jetty.server.HttpChannel.dispatch(HttpChannel.java:732) [org.apache.felix.http.jetty:4.2.2]
	at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:479) [org.apache.felix.http.jetty:4.2.2]
	at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:277) [org.apache.felix.http.jetty:4.2.2]
	at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:311) [org.apache.felix.http.jetty:4.2.2]
	at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:105) [org.apache.felix.http.jetty:4.2.2]
	at org.eclipse.jetty.io.ChannelEndPoint$1.run(ChannelEndPoint.java:104) [org.apache.felix.http.jetty:4.2.2]
	at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.runTask(EatWhatYouKill.java:338) [org.apache.felix.http.jetty:4.2.2]
	at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:315) [org.apache.felix.http.jetty:4.2.2]
	at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.tryProduce(EatWhatYouKill.java:173) [org.apache.felix.http.jetty:4.2.2]
	at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.run(EatWhatYouKill.java:131) [org.apache.felix.http.jetty:4.2.2]
	at org.eclipse.jetty.util.thread.ReservedThreadExecutor$ReservedThread.run(ReservedThreadExecutor.java:409) [org.apache.felix.http.jetty:4.2.2]
	at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:883) [org.apache.felix.http.jetty:4.2.2]
	at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:1034) [org.apache.felix.http.jetty:4.2.2]
	at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.lang.ExceptionInInitializerError: Exception java.lang.LinkageError: loader constraint violation: when resolving method "org.slf4j.impl.StaticLoggerBinder.getLoggerFactory()Lorg/slf4j/ILoggerFactory;" the class loader org.apache.felix.framework.BundleWiringImpl$BundleClassLoader @171cc1eb (instance of org.apache.felix.framework.BundleWiringImpl$BundleClassLoader, child of org.apache.sling.launchpad.base.shared.LauncherClassLoader @1608bcbd org.apache.sling.launchpad.base.shared.LauncherClassLoader) of the current class, org/slf4j/LoggerFactory, and the class loader org.apache.felix.framework.BundleWiringImpl$BundleClassLoader @225a141a (instance of org.apache.felix.framework.BundleWiringImpl$BundleClassLoader, child of org.apache.sling.launchpad.base.shared.LauncherClassLoader @1608bcbd org.apache.sling.launchpad.base.shared.LauncherClassLoader) for the method's defining class, org/slf4j/impl/StaticLoggerBinder, have different Class objects for the type org/slf4j/ILoggerFactory used in the signature [in thread "[0:0:0:0:0:0:0:1] [1692712961519] GET /bin/generative/ai/desc HTTP/1.1"]
	at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:418)
	at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:357)
	at com.azure.core.util.logging.ClientLogger.<init>(ClientLogger.java:100) [com.adobe.aem.azurechatgtp.commons.core:0.0.1.SNAPSHOT]
	at com.azure.core.util.logging.ClientLogger.<init>(ClientLogger.java:66) [com.adobe.aem.azurechatgtp.commons.core:0.0.1.SNAPSHOT]
	at com.azure.core.util.logging.ClientLogger.<init>(ClientLogger.java:56) [com.adobe.aem.azurechatgtp.commons.core:0.0.1.SNAPSHOT]
	at com.azure.core.util.CoreUtils.<clinit>(CoreUtils.java:36) [com.adobe.aem.azurechatgtp.commons.core:0.0.1.SNAPSHOT]
	at com.azure.ai.openai.OpenAIClientBuilder.<clinit>(OpenAIClientBuilder.java:66) [com.adobe.aem.azurechatgtp.commons.core:0.0.1.SNAPSHOT]
	at com.adobe.aem.azurechatgtp.core.servlets.GenerateInfServlet.generateMessage2(GenerateInfServlet.java:47) [aem-azurechatgtp.core:0.0.1.SNAPSHOT]
	at com.adobe.aem.azurechatgtp.core.servlets.GenerateInfServlet.doGet(GenerateInfServlet.java:37) [aem-azurechatgtp.core:0.0.1.SNAPSHOT]

 

 

 

 

Servlet:

 

 

package com.adobe.aem.azurechatgtp.core.servlets;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.Servlet;
import javax.servlet.ServletException;

import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
import org.apache.sling.api.servlets.HttpConstants;
import org.apache.sling.api.servlets.SlingSafeMethodsServlet;
import org.osgi.framework.Constants;
import org.osgi.service.component.annotations.Component;

import com.azure.ai.openai.OpenAIClient;
import com.azure.ai.openai.OpenAIClientBuilder;
import com.azure.ai.openai.models.Choice;
import com.azure.ai.openai.models.Completions;
import com.azure.ai.openai.models.CompletionsOptions;
import com.azure.ai.openai.models.CompletionsUsage;
import com.azure.core.credential.AzureKeyCredential;

@Component(immediate = true, service = Servlet.class, property = {
		Constants.SERVICE_DESCRIPTION + "=ChatGPT Integration", "sling.servlet.methods=" + HttpConstants.METHOD_GET,
		"sling.servlet.paths=" + "/bin/generative/ai/desc", "sling.servlet.extensions={\"json\"}" })

public class GenerateInfServlet extends SlingSafeMethodsServlet {

	private static final long serialVersionUID = 4567740991197964993L;

	@Override
	protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response)
			throws ServletException, IOException {

		String message2 = generateMessage2();
		response.getWriter().write(message2);
	}

	private static String generateMessage2() {
		String azureOpenaiKey = "4699cbb6884a438095ba926bc0a8e12d";
		String endpoint = "https://sandbox-ey.openai.azure.com/";
		String deploymentOrModelId = "text-davinci-003";
		String text = "Error";

		OpenAIClient client = new OpenAIClientBuilder().endpoint(endpoint)
				.credential(new AzureKeyCredential(azureOpenaiKey)).buildClient();

		List<String> prompt = new ArrayList<>();
		prompt.add("When was Microsoft founded?");

		Completions completions = client.getCompletions(deploymentOrModelId, new CompletionsOptions(prompt));

//        System.out.printf("Model ID=%s is created at %s.%n", completions.getId(), completions.getCreatedAt());
		for (Choice choice : completions.getChoices()) {
//            System.out.printf("Index: %d, Text: %s.%n", choice.getIndex(), choice.getText());
		}

		CompletionsUsage usage = completions.getUsage();
		text = "Usage: number of prompt token is, " + usage.getPromptTokens() + "number of completion token is "
				+ usage.getCompletionTokens() + ", and number of total tokens in request and response is "
				+ usage.getTotalTokens();

		return text;
	}

}

 

Link for Azure Open AI integration - https://learn.microsoft.com/en-us/azure/ai-services/openai/quickstart?pivots=programming-language-ja...

 

Avatar

Level 2

This issue was resolved by excluding slf4j dependency from Azure open AI dependency

       <dependency>
			<groupId>com.azure</groupId>
			<artifactId>azure-ai-openai</artifactId>
			<version>1.0.0-beta.3</version>
			   <exclusions>
			     <exclusion>
			        <groupId>org.slf4j</groupId>
			        <artifactId>slf4j-api</artifactId>
			     </exclusion>
			   </exclusions>
		</dependency>

 

Avatar

Level 5

My suggestion is, atleast for the initial setup until u are able to get the integration working create a new maven module with the dependencies you mentioned and have all your maven dependency jars embedded within the jar. Now this maven module can export only the packages you need in your code. Yes embedding all compile dependencies may make it look big, but an alternate way to make things work. Most of the times when we use third party jars we fall in to the import dependency trap that one or the other is missing. And once integration works then you can optimize the scope of what all to include in your embeds instead or importing all of the dependencies. Hope the inputs assist you. Thanks