fix: model platform

This commit is contained in:
moyangzhan 2024-05-11 09:02:42 +08:00
parent 7a6f404c74
commit be9aecc45f
5 changed files with 21 additions and 3 deletions

View File

@ -30,4 +30,8 @@ public class AiSearchRecordResp {
private String userUuid; private String userUuid;
private LocalDateTime createTime; private LocalDateTime createTime;
private Long aiModelId;
private String aiModelPlatform;
} }

View File

@ -47,4 +47,8 @@ public class AiSearchRecord extends BaseEntity {
@Schema(title = "提问用户id") @Schema(title = "提问用户id")
@TableField("user_id") @TableField("user_id")
private Long userId; private Long userId;
@Schema(title = "adi_ai_model id")
@TableField("ai_model_id")
private Long aiModelId;
} }

View File

@ -7,6 +7,7 @@ import com.moyz.adi.common.base.ThreadContext;
import com.moyz.adi.common.dto.AiSearchRecordResp; import com.moyz.adi.common.dto.AiSearchRecordResp;
import com.moyz.adi.common.dto.AiSearchResp; import com.moyz.adi.common.dto.AiSearchResp;
import com.moyz.adi.common.dto.SearchEngineResp; 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.entity.AiSearchRecord;
import com.moyz.adi.common.exception.BaseException; import com.moyz.adi.common.exception.BaseException;
import com.moyz.adi.common.mapper.AiSearchRecordMapper; import com.moyz.adi.common.mapper.AiSearchRecordMapper;
@ -20,6 +21,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import static com.moyz.adi.common.enums.ErrorEnum.A_DATA_NOT_FOUND; 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 * Ai search
@ -46,11 +48,13 @@ public class AiSearchRecordService extends ServiceImpl<AiSearchRecordMapper, AiS
BizPager.listByMaxId(maxId, wrapper, this, AiSearchRecord::getId, (recordList, minId) -> { BizPager.listByMaxId(maxId, wrapper, this, AiSearchRecord::getId, (recordList, minId) -> {
List<AiSearchRecordResp> list = MPPageUtil.convertToList(recordList, AiSearchRecordResp.class); List<AiSearchRecordResp> list = MPPageUtil.convertToList(recordList, AiSearchRecordResp.class);
list.forEach(item -> { list.forEach(item -> {
if(null == item.getSearchEngineResp()){ if (null == item.getSearchEngineResp()) {
SearchEngineResp searchEngineResp = new SearchEngineResp(); SearchEngineResp searchEngineResp = new SearchEngineResp();
searchEngineResp.setItems(new ArrayList<>()); searchEngineResp.setItems(new ArrayList<>());
item.setSearchEngineResp(searchEngineResp); item.setSearchEngineResp(searchEngineResp);
} }
AiModel aiModel = MODEL_ID_TO_OBJ.get(item.getAiModelId());
item.setAiModelPlatform(null == aiModel ? "" : aiModel.getPlatform());
}); });
result.setRecords(list); result.setRecords(list);
result.setMinId(minId); result.setMinId(minId);

View File

@ -57,6 +57,9 @@ public class SearchService {
@Resource @Resource
private UserDayCostService userDayCostService; private UserDayCostService userDayCostService;
@Resource
private AiModelService aiModelService;
@Resource @Resource
private AsyncTaskExecutor mainExecutor; private AsyncTaskExecutor mainExecutor;
@ -138,6 +141,7 @@ public class SearchService {
newRecord.setAnswerTokens(answerMeta.getTokens()); newRecord.setAnswerTokens(answerMeta.getTokens());
newRecord.setUserUuid(user.getUuid()); newRecord.setUserUuid(user.getUuid());
newRecord.setUserId(user.getId()); newRecord.setUserId(user.getId());
newRecord.setAiModelId(aiModelService.getIdByName(modelName));
aiSearchRecordService.save(newRecord); aiSearchRecordService.save(newRecord);
userDayCostService.appendCostToUser(user, promptMeta.getTokens() + answerMeta.getTokens()); userDayCostService.appendCostToUser(user, promptMeta.getTokens() + answerMeta.getTokens());
@ -168,6 +172,7 @@ public class SearchService {
newRecord.setSearchEngineResp(resp); newRecord.setSearchEngineResp(resp);
newRecord.setUserId(user.getId()); newRecord.setUserId(user.getId());
newRecord.setUserUuid(user.getUuid()); newRecord.setUserUuid(user.getUuid());
newRecord.setAiModelId(aiModelService.getIdByName(modelName));
aiSearchRecordService.save(newRecord); aiSearchRecordService.save(newRecord);
CountDownLatch countDownLatch = new CountDownLatch(resultItems.size()); CountDownLatch countDownLatch = new CountDownLatch(resultItems.size());

View File

@ -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.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.user_id IS '用户ID';
COMMENT ON COLUMN public.adi_conversation_message.ai_model_id IS 'adi_ai_model 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, answer_tokens integer DEFAULT 0 NOT NULL,
user_id bigint default '0' NOT NULL, user_id bigint default '0' NOT NULL,
user_uuid varchar(32) default ''::character varying 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, create_time timestamp default CURRENT_TIMESTAMP not null,
update_time timestamp default CURRENT_TIMESTAMP not null, update_time timestamp default CURRENT_TIMESTAMP not null,
is_deleted boolean default false 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.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.create_time is '创建时间';
comment on column adi_ai_search_record.update_time is '更新时间'; comment on column adi_ai_search_record.update_time is '更新时间';