LLM application: /xwiki prefix hardcoded when making api requests

Hello everyone,

great concepts and work so far! Very cool to see that LLMs are on the radar for XWiki.
I was testing the initial LLM Application release and found a bug. However, I am not sure where I can report it properly so apologies if this is not the right place - I have not found another way to contact you.

The problem is that accessing models rest endpoint (and probably the others too) is not working properly when loading the application in the editor. I have identified the following problem:

In the code the request seems to be hardcoded with an /xwiki prefix before the /rest/v1/…. From my research it seems that this only works when XWiki is not deployed as the ROOT application but under the xwiki-context. This is, however, not the case in the default xwiki docker images that we are using at my company. And I think the default settings for other deployment methods also don’t use the /xwiki prefix. More on the URL prefix topic here, it seems to be defined via the xwiki.webapppath property in xwiki.cfg: Short URLs (XWiki.org)

Is there a way to incorporate this config option into the request generation?

Keep up the great work!

Hello Lukas,

Thank you for the report !

Yes, there is a way to incorporate that into the request generation. I just tested a fix for that thanks to you. The fix is a bit ugly for now :).

What I’ve done is simple: now we look at the URL from where the request is sent, and check if its root or not. For example with http://localhost:8080/xwiki/bin/view/Main/#edit, it will found /xwiki and send a request with the good URI at the end. But in your case, you have something like http://localhost:8080/bin/view/Main/#edit, it will find that this is root and sent the corresponding request.

If you want, I did an hotfix of the script here : Up1
you just need to replace the JavaScriptExtension object of the LLM Application in AI.Code.Javascript (just erase the original script with the new one). Then you will have to shift+reload AI.Code.TestUI and you should be good testing the extensions !

Let me know if you have any trouble with it, or any other feedbacks ! There is a dedicated Matrix chat here if you want to share them easily.

Hi Matéo,

I had similar issues when working with URLs recently. If you want something less hacky, I suggest you take a look at the Standard URL Format (XWiki.org) documentation which explains how to construct an URL. You can retrieve the context path part of the URL from javascript using the XWiki.contextPath variable.

Thanks.

1 Like

Thank you, will use it for the official fix.

Hi Matéo,

thanks for the quick fix! I replaced the code and it worked perfectly.
How can I join the Matrix Channel? It says that federation is not allowed (using my matrix.org account) and I cannot find a way to create an account on your server :smiley:

Indeed, the room is not open for other. Since I cannot change that anymore I recreated a public room here.

Thanks @Mateo

Note that we’re supposed to use the main #xwiki chat for contrib projects (at least until the project grows to a level of chat activity that is no longer compatible with a single chat channel :)), see https://contrib.xwiki.org/xwiki/bin/view/Main/WebHome#HHostingtools

1 Like