-
Notifications
You must be signed in to change notification settings - Fork 948
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FEATURE] Option to pass extra parameters to RAG/Tool/XyzProvider via AI service #1122
Comments
how about this?
Example // the definition of tool
public static class SendMailTools {
public void sendEmail(String content, @ToolUserData Map<String, Object> userData) {
String subject = (String) userData.getOrDefault("subject", "default subject");
log.info("send email with content: {} userData: {}", content, subject);
}
}
//the definition of AiService
public interface ChatService {
@UserMessage("summary text ```{{text}}``` and send summary by email")
String summaryAndSendEmail(@V("text") String text, @UserData Map<String, Object> userData);
}
//example
public static void main(String[] args) {
ChatService chatService = AiServices.builder(ChatService.class)
.tools(new SendMailTools())
.build();
Map<String, Object> userData = Collections.singletonMap("subject", "customizeSubject");
chatService.summaryAndSendEmail("a very long text", userData);
} Things may need to discuss
|
@Yellow-- Sounds good!
We should consider other names, because this data might not be really a user data, but something related to the tenant or the whole app
Ideally we shouldn't restrict the type (as it is done for memory id) |
@langchain4j // the definition of tool
public static class SendMailTools {
public void sendEmail(String content, @ToolTransparentData Map<String, Object> emailContext) {
String subject = (String) userData.getOrDefault("subject", "default subject");
log.info("send email with content: {} userData: {}", content, subject);
}
}
//the definition of AiService
//the ```@TransparentData``` parameter type is not restricted,you could pass any object as you like
public interface ChatService {
@UserMessage("summary text ```{{text}}``` and send summary by email")
String summaryAndSendEmail(@V("text") String text, @TransparentData Map<String, Object> emailContext);
}
//example
public static void main(String[] args) {
ChatService chatService = AiServices.builder(ChatService.class)
.tools(new SendMailTools())
.build();
Map<String, Object> userData = Collections.singletonMap("subject", "customizeSubject");
chatService.summaryAndSendEmail("a very long text", userData);
} |
A few comments:
|
We would want to allow the different components (tools and RAG components) to update the contents of these parameters over time, right? So that for example if a query transformer adds something into it, and later the LLM decides to execute a tool, the tool should be able to see it. In that case, my suggestion would be to introduce a class like
This would be quite robust I think, but a potential problem with this is that we would have to change the interfaces for RAG components ( |
Hi @jmartisk, I am not sure if we should restrict the type though. With the annotation approach, user will be able to pass any object between tools and RAG. |
I'm not restricting the type, just wrapping it into a class that will internally contain |
Related: #1566 |
TODO
Currently only memory id can be passed around.
It would be great to be able to pass custom parameters.
For example, to be able to set
Filter
expression.Consider passing
ChatMemory
orList<ChatMessage>
as well, so that i cna be accessed from tool method.The text was updated successfully, but these errors were encountered: