diff --git a/llmx-core/llmx-core-spi/src/main/kotlin/org/jcnc/llmx/core/spi/provider/LLMProvider.kt b/llmx-core/llmx-core-spi/src/main/kotlin/org/jcnc/llmx/core/spi/provider/LLMProvider.kt index 404c127..9af555b 100644 --- a/llmx-core/llmx-core-spi/src/main/kotlin/org/jcnc/llmx/core/spi/provider/LLMProvider.kt +++ b/llmx-core/llmx-core-spi/src/main/kotlin/org/jcnc/llmx/core/spi/provider/LLMProvider.kt @@ -1,12 +1,11 @@ package org.jcnc.llmx.core.spi.provider -import kotlinx.coroutines.flow.Flow import org.jcnc.llmx.core.spi.entities.request.ChatRequest import org.jcnc.llmx.core.spi.entities.request.EmbeddingRequest import org.jcnc.llmx.core.spi.entities.response.ChatResponsePart import org.jcnc.llmx.core.spi.entities.response.EmbeddingResponse +import org.reactivestreams.Publisher import org.springframework.http.MediaType - import org.springframework.web.bind.annotation.PostMapping import org.springframework.web.bind.annotation.RequestMapping @@ -31,7 +30,7 @@ interface LLMProvider { * @return 返回一个Flow流,通过该流可以接收到聊天响应的部分数据,如消息、状态更新等 */ @PostMapping("/chat", produces = [MediaType.APPLICATION_NDJSON_VALUE]) - fun chat(request: ChatRequest): Flow + fun chat(request: ChatRequest): Publisher /** * 嵌入功能方法 diff --git a/llmx-impl/llmx-impl-bailian/src/main/kotlin/org/jcnc/llmx/impl/baiLian/controller/BaiLianProvider.kt b/llmx-impl/llmx-impl-bailian/src/main/kotlin/org/jcnc/llmx/impl/baiLian/controller/BaiLianProvider.kt index 028c275..e8a1e69 100644 --- a/llmx-impl/llmx-impl-bailian/src/main/kotlin/org/jcnc/llmx/impl/baiLian/controller/BaiLianProvider.kt +++ b/llmx-impl/llmx-impl-bailian/src/main/kotlin/org/jcnc/llmx/impl/baiLian/controller/BaiLianProvider.kt @@ -1,16 +1,19 @@ package org.jcnc.llmx.impl.baiLian.controller -import kotlinx.coroutines.flow.Flow + +import kotlinx.coroutines.reactive.asPublisher import org.jcnc.llmx.core.spi.entities.request.ChatRequest import org.jcnc.llmx.core.spi.entities.request.EmbeddingRequest import org.jcnc.llmx.core.spi.entities.response.ChatResponsePart import org.jcnc.llmx.core.spi.entities.response.EmbeddingResponse import org.jcnc.llmx.core.spi.provider.LLMProvider import org.jcnc.llmx.impl.baiLian.service.BaiLianModelService +import org.reactivestreams.Publisher import org.springframework.web.bind.annotation.RequestBody import org.springframework.web.bind.annotation.RestController + /** *百炼提供商 * @@ -18,10 +21,9 @@ import org.springframework.web.bind.annotation.RestController * @author gewuyou */ @RestController -//@RequestMapping("/provider") class BaiLianProvider( private val baiLianModelService: BaiLianModelService -): LLMProvider { +) : LLMProvider { /** * 初始化与聊天服务的连接,以处理聊天请求 * @@ -31,9 +33,8 @@ class BaiLianProvider( * @param request 聊天请求对象,包含建立聊天所需的信息,如用户标识、会话标识等 * @return 返回一个Flow流,通过该流可以接收到聊天响应的部分数据,如消息、状态更新等 */ -// @PostMapping("/chat") - override fun chat(@RequestBody request: ChatRequest): Flow { - return baiLianModelService.streamChat(request) + override fun chat(@RequestBody request: ChatRequest): Publisher { + return baiLianModelService.streamChat(request).asPublisher() } /**