langchain4j [特性] Spring Boot集成支持异步调用(Mono)

sd2nnvve  于 2个月前  发布在  Spring
关注(0)|答案(2)|浏览(40)

描述您希望的解决方案

我查看了Spring Boot集成的示例,但没有异步调用的示例。
https://github.com/langchain4j/langchain4j-examples/blob/main/customer-support-agent-example/src/main/java/dev/langchain4j/example/CustomerSupportAgent.java

描述您考虑过的替代方案

我希望API设计能够允许异步调用返回Mono,以便用户订阅AiMessage,如下所示:

import dev.langchain4j.service.SystemMessage;

interface CustomerSupportAgent {

    @SystemMessage({
            "You are a customer support agent of a car rental company named 'Miles of Smiles'.",
            "Before providing information about booking or cancelling booking, you MUST always check:",
            "booking number, customer name and surname.",
            "Today is {{current_date}}."
    })
    String chat(String userMessage);

    @SystemMessage({ "You are a customer support agent....." })
    Mono<AiMessage> asyncChat(String userMessage); // a async call return Mono let user to subscribe results
}
cyvaqqii

cyvaqqii1#

嘿,@langchain4j,

你是否知道这个功能什么时候会发布?我正在开发一个React式原生应用,并想知道是否可以避免这样的构造:
Mono.fromCallable(() -> assistant.chat(...)).subscribeOn(Schedulers.boundedElastic());
以及以下助手:

public interface Assistant {
    @SystemMessage(fromResource = "/context/general_context.txt")
    String chat(@MemoryId @NotEmpty String userId, @UserMessage @NotEmpty String message);
}

我想解决的问题是,我的代码可以通过函数调用执行,但是在执行过程中,由于Schedulers.boundedElastic()的使用,它缺少安全上下文,因此函数无法按预期行为。

提前感谢!

30byixjq

30byixjq2#

你好,@pakamona。据我所知,目前没有人在处理这个问题。也许@ThomasVitale可以帮忙?🙏

相关问题