Towards a new annotation-based model #246
Replies: 5 comments 22 replies
-
I think this make a lot of sense. The The rest is totally doable and I do think it's the proper way to provide more control. My question really is, should we do it now or wait until this is really needed? |
Beta Was this translation helpful? Give feedback.
-
Good idea! My 2 cents:
System message is not added again if it is already in the memory (even if called from different methods). Only when System message is different (e.g. each method has own system message), it replaces the previous one in the history.
BTW it is now called
I like many of the ideas (e.g |
Beta Was this translation helpful? Give feedback.
-
Annotation-less AI services offtopic: There is one thing that I have removed from AI services that I am reconsidering adding back: "prompt derivation" or whatever is the better name for it. Same idea as spring data jpa derives SQL queries from method names. So you do public interface Assistant {
String tellMeAJoke();
}
String joke = assistant.tellMeAJoke(); // LLM prompt: "tell me a joke" Or public interface Assistant {
String tellMeAJokeAbout(String topic);
}
String joke = assistant.tellMeAJokeAbout("python"); // LLM prompt: "tell me a joke about python"
Or
```java
public interface Assistant {
String tellMeAJoke(String topic, String style);
}
String joke = assistant.tellMeAJoke("python", "ironic"); // LLM prompt: "tell me a joke \n topic: python \n style: ironic" WDYT? Probably not very useful for prod cases, but might be impressive for demos 😆 This can also work together with @SystemMessage |
Beta Was this translation helpful? Give feedback.
-
@langchain4j are you okay with the implied changes in the langchain4j annotations? |
Beta Was this translation helpful? Give feedback.
-
I was about to start implementing |
Beta Was this translation helpful? Give feedback.
-
Hello,
This topic has been discussed many times (briefly) in several issues (#237, #210, #42, #41, #10). This discussion aims to see if another annotation-based model is possible and what it would look like.
Current approach
Currently, declarative AI services are annotated with
@RegisterAiService
. In this annotation, we configure the memory, retriever, tools, moderation model, and chat model... Then, in theapplication.properties
, we configure the LLM provider used by this service.This design is simple and avoids having many annotations, but it also has a few limits:
In this discussion, I would like to discuss a more sophisticated model.
The overall idea
The main ideas are:
A simpler @RegisterAiService
We first need to simplify the
@RegisterAiService
annotation to achieve these goals. The retriever and tools attributes will be deprecated and planned for removal.AI qualifier or new RegisterAiService attribute
The second step is to allow the selection of the LLM to be more easily (without the supplier). There are several ways to do this, such as adding a "name" attribute or a dedicated qualifier (annotation):
This will enable multiple instance configurations of each LLM:
Open Question: Should it be
quarkus.langchain4j.<name>.<provider>.attribute=value
, orquarkus.langchain4j.<provider>.<name>.attribute=value
.IMPORTANT: An AI service is bound to a single LLM in this proposal. Multi-model AI Service is out of scope. The workaround is to use multiple interfaces. One issue with multi-models is handling the "memory," as the included messages are specific to the LLM.
SystemMessage on the class
The system message (when supported) allows explaining the "role" or "scope" to the LLM. A system message requires a memory of at least 3 (system + user + response).
Currently, we need to configure the system message on each method of the AI service interface. It would be helpful to configure it once. It would also:
Tools and Retriever on method
Unlike the system message, tools and retrievers need a bit more flexibility. Adding documents to every call might not be helpful and can be misleading for the LLM. It can also be better to restrict the method allowed to access tools.
So, the idea would be to define two new annotations:
DocumentRetrieverContentRetriever
- this annotation can select the document retriever, but it might need to be changed with the advanced RAG idea emerging in langchain4jToolbox
- the list of classes containing methods annotated with@Tool
(note: declaring a class that does not contain@Tool
should be considered illegal).The tools and document retriever would be added when the method is invoked instead of all the calls.
Example
Concerns
This proposal has a few drawbacks:
Beta Was this translation helpful? Give feedback.
All reactions