I am trying to use java interop with langchain4j, more specificaly the Aiservices. My problem is that it requires an interface with one method for the Aiservices builder. So i have the following clojure protocol implemented:
(defprotocol Assistant
(^String answer [this ^String query]))
Not sure if the hint do anything here, it seems not, i use it with Aiservices in the following way:
(defn make-assistant [model retriever]
(try
(.build (doto
(AiServices/builder rag_base.core.Assistant)
(.chatLanguageModel model)
(.contentRetriever retriever)))
(catch Throwable t (.println System/out t))))
Where rag-base.core is the namespace, hence rag_base.core.Assistant is the java interface of the corresponding protocol.
However when i call make-assistant the type of the class i get is jdk.proxy4.$Proxy46
and wean a call the answear method i get
; eval (current-form): (answer assistant "test")
; (err) Execution error (IllegalConfigurationException) at dev.langchain4j.exception.IllegalConfigurationException/illegalConfiguration (IllegalConfigurationException.java:12).
; (err) Illegal method return type: class java.lang.Object
Indicating that is something wrong with the return type, so type hints dont work
what can i do here ?I would have expected you need definterface here, not defprotocol, but I'd be curious about what AiServices.builder() really requires here. If it truly accepts an interface, it has to return a proxy object since it cannot instantiate an interface...?
correct it returns a proxy object
i have totally forgotten that definterface existed, thanks
The docs seem to suggest builder takes no arguments and that you create via the interface: https://docs.langchain4j.dev/tutorials/ai-services/#simplest-ai-service
That's not true, search for "naive rag" and see the implementation
Ah, mixed up build which doesn't and builder that does. I've never used any of this stuff before...