Skip to content
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 via AI service #1122

Open
langchain4j opened this issue May 17, 2024 · 3 comments
Open
Assignees
Labels
enhancement New feature or request P1 Highest priority P2 High priority

Comments

@langchain4j
Copy link
Owner

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.

@langchain4j langchain4j added enhancement New feature or request P1 Highest priority P2 High priority labels May 17, 2024
@langchain4j langchain4j self-assigned this May 17, 2024
@Yellow--
Copy link
Contributor

how about this?

  • add annotationUserDatawhich will be used by AiService Interface
  • add annotationToolUserDatawhich indicated that relatived parameter in tools is userData
  • the userData passed in the AiService method will by bypass to tools and MetaData of RAG

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

  • does the annotation name understandable?may be need another name?
  • does strict the UserData to Map<String, Object> is good?

@langchain4j

@langchain4j
Copy link
Owner Author

@Yellow-- Sounds good!

does the annotation name understandable?may be need another name?

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

does strict the UserData to Map<String, Object> is good?

Ideally we shouldn't restrict the type (as it is done for memory id)

@Yellow--
Copy link
Contributor

@langchain4j
with you advices
the final look may be like this?

    // 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);
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request P1 Highest priority P2 High priority
Projects
None yet
Development

No branches or pull requests

2 participants