From be9aecc45f68ff4922196a902f9fe96f2ecfacf5 Mon Sep 17 00:00:00 2001 From: moyangzhan Date: Sat, 11 May 2024 09:02:42 +0800 Subject: [PATCH] fix: model platform --- .../java/com/moyz/adi/common/dto/AiSearchRecordResp.java | 4 ++++ .../java/com/moyz/adi/common/entity/AiSearchRecord.java | 4 ++++ .../com/moyz/adi/common/service/AiSearchRecordService.java | 6 +++++- .../java/com/moyz/adi/common/service/SearchService.java | 5 +++++ docs/create.sql | 5 +++-- 5 files changed, 21 insertions(+), 3 deletions(-) diff --git a/adi-common/src/main/java/com/moyz/adi/common/dto/AiSearchRecordResp.java b/adi-common/src/main/java/com/moyz/adi/common/dto/AiSearchRecordResp.java index c8b492c..0243f02 100644 --- a/adi-common/src/main/java/com/moyz/adi/common/dto/AiSearchRecordResp.java +++ b/adi-common/src/main/java/com/moyz/adi/common/dto/AiSearchRecordResp.java @@ -30,4 +30,8 @@ public class AiSearchRecordResp { private String userUuid; private LocalDateTime createTime; + + private Long aiModelId; + + private String aiModelPlatform; } diff --git a/adi-common/src/main/java/com/moyz/adi/common/entity/AiSearchRecord.java b/adi-common/src/main/java/com/moyz/adi/common/entity/AiSearchRecord.java index 87419b1..5897265 100644 --- a/adi-common/src/main/java/com/moyz/adi/common/entity/AiSearchRecord.java +++ b/adi-common/src/main/java/com/moyz/adi/common/entity/AiSearchRecord.java @@ -47,4 +47,8 @@ public class AiSearchRecord extends BaseEntity { @Schema(title = "提问用户id") @TableField("user_id") private Long userId; + + @Schema(title = "adi_ai_model id") + @TableField("ai_model_id") + private Long aiModelId; } diff --git a/adi-common/src/main/java/com/moyz/adi/common/service/AiSearchRecordService.java b/adi-common/src/main/java/com/moyz/adi/common/service/AiSearchRecordService.java index fe49420..a21c1f0 100644 --- a/adi-common/src/main/java/com/moyz/adi/common/service/AiSearchRecordService.java +++ b/adi-common/src/main/java/com/moyz/adi/common/service/AiSearchRecordService.java @@ -7,6 +7,7 @@ import com.moyz.adi.common.base.ThreadContext; import com.moyz.adi.common.dto.AiSearchRecordResp; import com.moyz.adi.common.dto.AiSearchResp; import com.moyz.adi.common.dto.SearchEngineResp; +import com.moyz.adi.common.entity.AiModel; import com.moyz.adi.common.entity.AiSearchRecord; import com.moyz.adi.common.exception.BaseException; import com.moyz.adi.common.mapper.AiSearchRecordMapper; @@ -20,6 +21,7 @@ import java.util.ArrayList; import java.util.List; import static com.moyz.adi.common.enums.ErrorEnum.A_DATA_NOT_FOUND; +import static com.moyz.adi.common.util.LocalCache.MODEL_ID_TO_OBJ; /** * Ai search @@ -46,11 +48,13 @@ public class AiSearchRecordService extends ServiceImpl { List list = MPPageUtil.convertToList(recordList, AiSearchRecordResp.class); list.forEach(item -> { - if(null == item.getSearchEngineResp()){ + if (null == item.getSearchEngineResp()) { SearchEngineResp searchEngineResp = new SearchEngineResp(); searchEngineResp.setItems(new ArrayList<>()); item.setSearchEngineResp(searchEngineResp); } + AiModel aiModel = MODEL_ID_TO_OBJ.get(item.getAiModelId()); + item.setAiModelPlatform(null == aiModel ? "" : aiModel.getPlatform()); }); result.setRecords(list); result.setMinId(minId); diff --git a/adi-common/src/main/java/com/moyz/adi/common/service/SearchService.java b/adi-common/src/main/java/com/moyz/adi/common/service/SearchService.java index 7d033df..494e026 100644 --- a/adi-common/src/main/java/com/moyz/adi/common/service/SearchService.java +++ b/adi-common/src/main/java/com/moyz/adi/common/service/SearchService.java @@ -57,6 +57,9 @@ public class SearchService { @Resource private UserDayCostService userDayCostService; + @Resource + private AiModelService aiModelService; + @Resource private AsyncTaskExecutor mainExecutor; @@ -138,6 +141,7 @@ public class SearchService { newRecord.setAnswerTokens(answerMeta.getTokens()); newRecord.setUserUuid(user.getUuid()); newRecord.setUserId(user.getId()); + newRecord.setAiModelId(aiModelService.getIdByName(modelName)); aiSearchRecordService.save(newRecord); userDayCostService.appendCostToUser(user, promptMeta.getTokens() + answerMeta.getTokens()); @@ -168,6 +172,7 @@ public class SearchService { newRecord.setSearchEngineResp(resp); newRecord.setUserId(user.getId()); newRecord.setUserUuid(user.getUuid()); + newRecord.setAiModelId(aiModelService.getIdByName(modelName)); aiSearchRecordService.save(newRecord); CountDownLatch countDownLatch = new CountDownLatch(resultItems.size()); diff --git a/docs/create.sql b/docs/create.sql index 32451a1..3fe2d62 100644 --- a/docs/create.sql +++ b/docs/create.sql @@ -140,8 +140,6 @@ COMMENT ON COLUMN public.adi_conversation_message.message_role IS '产生该消 COMMENT ON COLUMN public.adi_conversation_message.tokens IS '消耗的token数量'; -COMMENT ON COLUMN public.adi_conversation_message.language_model_name IS 'LLM name'; - COMMENT ON COLUMN public.adi_conversation_message.user_id IS '用户ID'; COMMENT ON COLUMN public.adi_conversation_message.ai_model_id IS 'adi_ai_model id'; @@ -621,6 +619,7 @@ create table adi_ai_search_record answer_tokens integer DEFAULT 0 NOT NULL, user_id bigint default '0' NOT NULL, user_uuid varchar(32) default ''::character varying not null, + ai_model_id bigint default 0 not null, create_time timestamp default CURRENT_TIMESTAMP not null, update_time timestamp default CURRENT_TIMESTAMP not null, is_deleted boolean default false not null @@ -641,6 +640,8 @@ comment on column adi_ai_search_record.answer_tokens is 'LLM响应消耗的token comment on column adi_ai_search_record.user_id is 'Id from adi_user'; +COMMENT ON COLUMN adi_ai_search_record.ai_model_id IS 'adi_ai_model id'; + comment on column adi_ai_search_record.create_time is '创建时间'; comment on column adi_ai_search_record.update_time is '更新时间';