refactor(llmx): 将 LLMProvider 接口中的 chat 方法返回类型改为 Publisher
修改了 LLMProvider 接口和 BaiLianProvider 实现类中的 chat 方法,将返回类型从 Flow 改为 Publisher,以适应 Spring WebFlux 的数据处理方式。这一变更使得系统能够更好地集成和使用 Spring WebFlux 的特性。
This commit is contained in:
parent
1ace055e37
commit
383533eb35
@ -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<ChatResponsePart>
|
||||
fun chat(request: ChatRequest): Publisher<ChatResponsePart>
|
||||
|
||||
/**
|
||||
* 嵌入功能方法
|
||||
|
||||
@ -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<ChatResponsePart> {
|
||||
return baiLianModelService.streamChat(request)
|
||||
override fun chat(@RequestBody request: ChatRequest): Publisher<ChatResponsePart> {
|
||||
return baiLianModelService.streamChat(request).asPublisher()
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user