From 484ffa4f1395742c52a21594ffc5fedd52a8dfc3 Mon Sep 17 00:00:00 2001 From: gewuyou Date: Sat, 10 May 2025 21:46:35 +0800 Subject: [PATCH] =?UTF-8?q?feat(core):=20=E9=87=8D=E6=9E=84=E6=A8=A1?= =?UTF-8?q?=E5=9E=8B=E8=B7=AF=E7=94=B1=E7=AE=A1=E7=90=86=E5=B9=B6=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=20Nacos=20=E9=85=8D=E7=BD=AE-=20=E7=A7=BB=E9=99=A4=20?= =?UTF-8?q?ModelProperties=20=E7=B1=BB=EF=BC=8C=E4=BD=BF=E7=94=A8=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=BA=93=E5=AD=98=E5=82=A8=E6=A8=A1=E5=9E=8B=E8=B7=AF?= =?UTF-8?q?=E7=94=B1=E6=98=A0=E5=B0=84-=20=E6=96=B0=E5=A2=9E=20ModelRouteM?= =?UTF-8?q?apping=20=E5=AE=9E=E4=BD=93=E7=B1=BB=E5=92=8C=20ModelRouteMappi?= =?UTF-8?q?ngRepository=20=E6=8E=A5=E5=8F=A3=20-=20=E6=9B=B4=E6=96=B0=20Mo?= =?UTF-8?q?delRouteManager=20=E7=B1=BB=EF=BC=8C=E4=BD=BF=E7=94=A8=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=BA=93=E6=9F=A5=E8=AF=A2=E6=A8=A1=E5=9E=8B=E8=B7=AF?= =?UTF-8?q?=E7=94=B1=E4=BF=A1=E6=81=AF-=20=E4=BF=AE=E6=94=B9=20Nacos=20?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=EF=BC=8C=E5=B0=86=20IP=20=E5=9C=B0=E5=9D=80?= =?UTF-8?q?=E4=BB=8E=20192.168.1.8=20=E6=94=B9=E4=B8=BA=20127.0.0.1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/service/config/AppConfiguration.kt | 2 - .../core/service/config/ModelProperties.kt | 21 ------ .../service/domain/model/ModelRouteMapping.kt | 74 +++++++++++++++++++ .../core/service/manager/ModelRouteManager.kt | 11 +-- .../ModelRouteMappingRepository.kt | 10 +++ .../src/main/resources/bootstrap-dev.yml | 2 +- .../src/main/resources/bootstrap-dev.yml | 2 +- 7 files changed, 92 insertions(+), 30 deletions(-) delete mode 100644 llmx-core/llmx-core-service/src/main/kotlin/org/jcnc/llmx/core/service/config/ModelProperties.kt create mode 100644 llmx-core/llmx-core-service/src/main/kotlin/org/jcnc/llmx/core/service/domain/model/ModelRouteMapping.kt create mode 100644 llmx-core/llmx-core-service/src/main/kotlin/org/jcnc/llmx/core/service/repositories/ModelRouteMappingRepository.kt diff --git a/llmx-core/llmx-core-service/src/main/kotlin/org/jcnc/llmx/core/service/config/AppConfiguration.kt b/llmx-core/llmx-core-service/src/main/kotlin/org/jcnc/llmx/core/service/config/AppConfiguration.kt index 6d400c3..bb50d8c 100644 --- a/llmx-core/llmx-core-service/src/main/kotlin/org/jcnc/llmx/core/service/config/AppConfiguration.kt +++ b/llmx-core/llmx-core-service/src/main/kotlin/org/jcnc/llmx/core/service/config/AppConfiguration.kt @@ -1,6 +1,5 @@ package org.jcnc.llmx.core.service.config -import org.springframework.boot.context.properties.EnableConfigurationProperties import org.springframework.cloud.client.loadbalancer.LoadBalanced import org.springframework.context.annotation.Bean import org.springframework.context.annotation.Configuration @@ -13,7 +12,6 @@ import org.springframework.web.reactive.function.client.WebClient * @author gewuyou */ @Configuration -@EnableConfigurationProperties(ModelProperties::class) open class AppConfiguration { /** * 创建一个配置了负载均衡的WebClient构建器 diff --git a/llmx-core/llmx-core-service/src/main/kotlin/org/jcnc/llmx/core/service/config/ModelProperties.kt b/llmx-core/llmx-core-service/src/main/kotlin/org/jcnc/llmx/core/service/config/ModelProperties.kt deleted file mode 100644 index 4e705c1..0000000 --- a/llmx-core/llmx-core-service/src/main/kotlin/org/jcnc/llmx/core/service/config/ModelProperties.kt +++ /dev/null @@ -1,21 +0,0 @@ -package org.jcnc.llmx.core.service.config - -import org.springframework.boot.context.properties.ConfigurationProperties -import org.springframework.cloud.context.config.annotation.RefreshScope - -/** - *模型属性 - * - * @since 2025-04-26 18:01:48 - * @author gewuyou - */ -@ConfigurationProperties(prefix = "llmx.model-route") -@RefreshScope -open class ModelProperties { - /** - * 模型名前缀 -> 服务名映射 - * 该映射表存储了模型名前缀与服务名的对应关系,用于快速查找模型对应的服务 - * 例:openai -> llmhub-impl-openai - */ - var modelServiceMap: Map = emptyMap() -} \ No newline at end of file diff --git a/llmx-core/llmx-core-service/src/main/kotlin/org/jcnc/llmx/core/service/domain/model/ModelRouteMapping.kt b/llmx-core/llmx-core-service/src/main/kotlin/org/jcnc/llmx/core/service/domain/model/ModelRouteMapping.kt new file mode 100644 index 0000000..a4dea5c --- /dev/null +++ b/llmx-core/llmx-core-service/src/main/kotlin/org/jcnc/llmx/core/service/domain/model/ModelRouteMapping.kt @@ -0,0 +1,74 @@ +package org.jcnc.llmx.core.service.domain.model + +import jakarta.persistence.* +import org.hibernate.annotations.ColumnDefault +import java.time.OffsetDateTime + +/** + * 表示模型与其路由信息之间的映射关系。 + * 该类用于定义模型与对应服务之间的关联, + * 包括相关的描述信息和状态信息。 + * + * 使用注解来定义表名、主键生成策略以及字段与数据库列的映射关系。 + */ +@Entity +@Table(name = "model_route_mapping", schema = "core") +open class ModelRouteMapping { + /** + * 映射关系的唯一标识符。 + * 使用序列生成器来自动生成ID。 + */ + @Id + @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "model_route_mapping_id_gen") + @SequenceGenerator( + name = "model_route_mapping_id_gen", + sequenceName = "model_route_mapping_id_seq", + allocationSize = 1 + ) + @Column(name = "id", nullable = false) + open var id: Long? = null + + /** + * 模型名称。 + * 用于标识与路由信息相关联的模型。 + */ + @Column(name = "model", nullable = false, length = 50) + open lateinit var model: String + + /** + * 对应的服务名称。 + * 表示该模型所关联的具体服务实例。 + */ + @Column(name = "service_name", nullable = false, length = 50) + open lateinit var serviceName: String + + /** + * 映射描述。 + * 提供有关映射的额外信息,便于理解和维护。 + */ + @Column(name = "description", length = 150) + open var description: String? = null + + /** + * 映射状态。 + * 表示当前映射是否启用。默认情况下,新映射是启用的。 + */ + @ColumnDefault("true") + @Column(name = "enabled") + open var enabled: Boolean=true + + /** + * 创建时间。 + * 默认为创建新映射时的当前时间戳。 + */ + @ColumnDefault("CURRENT_TIMESTAMP") + @Column(name = "create_at", nullable = false) + open var createAt: OffsetDateTime? = null + + /** + * 最后更新时间。 + * 记录映射信息的最后修改时间。 + */ + @Column(name = "update_at") + open var updateAt: OffsetDateTime? = null +} diff --git a/llmx-core/llmx-core-service/src/main/kotlin/org/jcnc/llmx/core/service/manager/ModelRouteManager.kt b/llmx-core/llmx-core-service/src/main/kotlin/org/jcnc/llmx/core/service/manager/ModelRouteManager.kt index 88324e1..3c59b71 100644 --- a/llmx-core/llmx-core-service/src/main/kotlin/org/jcnc/llmx/core/service/manager/ModelRouteManager.kt +++ b/llmx-core/llmx-core-service/src/main/kotlin/org/jcnc/llmx/core/service/manager/ModelRouteManager.kt @@ -2,7 +2,7 @@ package org.jcnc.llmx.core.service.manager import com.gewuyou.forgeboot.core.extension.log -import org.jcnc.llmx.core.service.config.ModelProperties +import org.jcnc.llmx.core.service.repositories.ModelRouteMappingRepository import org.springframework.stereotype.Component /** @@ -16,7 +16,7 @@ import org.springframework.stereotype.Component */ @Component class ModelRouteManager( - private val modelProperties: ModelProperties + private val modelRouteMappingRepository: ModelRouteMappingRepository, ) { /** * 根据模型名查找对应服务 @@ -29,10 +29,11 @@ class ModelRouteManager( * @throws IllegalArgumentException 如果模型名不匹配任何已知前缀,抛出此异常 */ fun resolveServiceName(model: String): String { - val modelServiceMap = modelProperties.modelServiceMap + val modelServiceMap = modelRouteMappingRepository.findAllByEnabled(true) + .associate { it.model to it.serviceName } log.info("modelServiceMap: $modelServiceMap") - for ((prefix, serviceName) in modelServiceMap) { - if (model.startsWith(prefix)) { + for ((model, serviceName) in modelServiceMap) { + if (model.startsWith(model)) { return serviceName } } diff --git a/llmx-core/llmx-core-service/src/main/kotlin/org/jcnc/llmx/core/service/repositories/ModelRouteMappingRepository.kt b/llmx-core/llmx-core-service/src/main/kotlin/org/jcnc/llmx/core/service/repositories/ModelRouteMappingRepository.kt new file mode 100644 index 0000000..cf4b7ec --- /dev/null +++ b/llmx-core/llmx-core-service/src/main/kotlin/org/jcnc/llmx/core/service/repositories/ModelRouteMappingRepository.kt @@ -0,0 +1,10 @@ +package org.jcnc.llmx.core.service.repositories + +import org.jcnc.llmx.core.service.domain.model.ModelRouteMapping +import org.springframework.data.jpa.repository.JpaRepository +import org.springframework.data.jpa.repository.JpaSpecificationExecutor + +interface ModelRouteMappingRepository : JpaRepository, + JpaSpecificationExecutor { + fun findAllByEnabled(isEnabled: Boolean): List +} \ No newline at end of file diff --git a/llmx-core/llmx-core-service/src/main/resources/bootstrap-dev.yml b/llmx-core/llmx-core-service/src/main/resources/bootstrap-dev.yml index 0e4cf07..62646f9 100644 --- a/llmx-core/llmx-core-service/src/main/resources/bootstrap-dev.yml +++ b/llmx-core/llmx-core-service/src/main/resources/bootstrap-dev.yml @@ -1,7 +1,7 @@ spring: cloud: nacos: - ip: 192.168.1.8 + ip: 127.0.0.1 username: nacos password: L4s6f9y3, server-addr: 49.235.96.75:8848 diff --git a/llmx-impl/llmx-impl-bailian/src/main/resources/bootstrap-dev.yml b/llmx-impl/llmx-impl-bailian/src/main/resources/bootstrap-dev.yml index d23f760..2b145bd 100644 --- a/llmx-impl/llmx-impl-bailian/src/main/resources/bootstrap-dev.yml +++ b/llmx-impl/llmx-impl-bailian/src/main/resources/bootstrap-dev.yml @@ -1,7 +1,7 @@ spring: cloud: nacos: - ip: 192.168.1.8 + ip: 127.0.0.1 username: nacos password: L4s6f9y3, server-addr: 49.235.96.75:8848 -- 2.47.2