Merge remote-tracking branch 'origin/master'

This commit is contained in:
sunxiqing 2025-01-06 14:45:22 +08:00
commit e85ce7be77
10 changed files with 205 additions and 10 deletions

View File

@ -58,6 +58,9 @@ public class LLMBackendProperties {
@NotNull(message = "登录 POST")
private String login;
private String account;
private String loginUsername;
private String loginPassword;
@NotNull(message = "基础模型列表 GET")
private String baseModelList;

View File

@ -1,13 +1,13 @@
package cn.iocoder.yudao.module.llm.service.http;
import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.framework.common.util.http.HttpUtils;
import cn.iocoder.yudao.module.llm.framework.backend.config.LLMBackendProperties;
import cn.iocoder.yudao.module.llm.service.http.vo.RagEmbedReqVo;
import cn.iocoder.yudao.module.llm.service.http.vo.RagQueryMultipleReqVo;
import cn.iocoder.yudao.module.llm.service.http.vo.RagQueryReqVo;
import cn.iocoder.yudao.module.llm.service.http.vo.*;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.toolkit.BeanUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
@ -17,6 +17,7 @@ import java.util.Map;
* 训练相关接口
*/
@Service
@Slf4j
public class TrainHttpService {
@Resource
@ -98,10 +99,39 @@ public class TrainHttpService {
/**
* 登录 POST
*/
public String login(Map<String, String> headers, String body){
public AigcLoginRespVO login(Map<String, String> headers){
headers.put("Content-Type", "application/json");
headers.put("Pragma", "no-cache");
String login = llmBackendProperties.getLogin();
String res = HttpUtils.post(login, headers, body);
return res;
AigcLoginReqVO req = new AigcLoginReqVO(llmBackendProperties.getLoginUsername(), llmBackendProperties.getLoginPassword());
String res = HttpUtils.post(login, headers, JSON.toJSONString(req));
log.info("登录接口返回:{}", res);
AigcRespVO aigcRespVO = JSON.parseObject(res, AigcRespVO.class);
if (aigcRespVO.isSuccess() && aigcRespVO.getData() != null){
AigcLoginRespVO aigcLoginRespVO = JSON.parseObject(aigcRespVO.getData().toString(), AigcLoginRespVO.class);
headers.put("X-Token", aigcLoginRespVO.getToken());
AigcAccountRespVO aigcAccountRespVO = account(headers);
if (aigcAccountRespVO != null && CollUtil.isNotEmpty(aigcAccountRespVO.getTenants())) {
aigcLoginRespVO.setTenantId(aigcAccountRespVO.getTenants().get(0).getId());
headers.put("X-Tenant-Id", aigcLoginRespVO.getTenantId());
log.info(" login:{}", aigcAccountRespVO);
return aigcLoginRespVO;
}
}
return null;
}
public AigcAccountRespVO account(Map<String, String> headers){
String account = llmBackendProperties.getAccount();
String res = HttpUtils.get(account, headers);
log.info(" account:{}", res);
AigcRespVO aigcRespVO = JSON.parseObject(res, AigcRespVO.class);
if (aigcRespVO.isSuccess() && aigcRespVO.getData() != null){
AigcAccountRespVO aigcAccountRespVO = JSON.parseObject(aigcRespVO.getData().toString(), AigcAccountRespVO.class);
log.info(" account:{}", aigcAccountRespVO);
return aigcAccountRespVO;
}
return null;
}
/**

View File

@ -0,0 +1,34 @@
package cn.iocoder.yudao.module.llm.service.http.vo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class AigcAccountRespVO {
// 租户列表由于JSON中是一个数组所以这里用List<Tenant>来表示
private List<Tenant> tenants;
// 电子邮件地址
private String email;
// 昵称
private String nickname;
// 语言设置
private String language;
// 嵌套的Tenant类用于表示租户信息
@Data
@AllArgsConstructor
@NoArgsConstructor
public static class Tenant {
// 租户ID
private String id;
// 租户名称
private String name;
}
}

View File

@ -0,0 +1,14 @@
package cn.iocoder.yudao.module.llm.service.http.vo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class AigcLoginReqVO {
private String username;
private String password;
}

View File

@ -0,0 +1,15 @@
package cn.iocoder.yudao.module.llm.service.http.vo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class AigcLoginRespVO {
private String token;
private String username;
private String tenantId;
}

View File

@ -0,0 +1,17 @@
package cn.iocoder.yudao.module.llm.service.http.vo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class AigcRespVO {
private boolean success;
private int code;
private Object data;
private String message;
private String traceId;
}

View File

@ -0,0 +1,27 @@
package cn.iocoder.yudao.module.llm.service.http.vo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;
@Data
@ToString
@AllArgsConstructor
@NoArgsConstructor
public class FineTuningCreateVO {
private String scenario = "faq";
private String fileId = "48fac97c-5a69-4fde-9f77-86f4de2e91eb";
private String baseModel;
private int trainEpoch;
private String suffix;
private String remark;
private int trainBatchSize;
private int evalBatchSize;
private int accumulationSteps;
private int procPerNode;
private double learningRate;
private int modelMaxLength;
private boolean lora;
}

View File

@ -0,0 +1,45 @@
package cn.iocoder.yudao.module.llm.service.http.vo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class FineTuningFileListRespVO {
private boolean success;
private int code;
private ListData data;
private String message;
private String traceId;
// 嵌套在顶层类中的 Data
@Data
@AllArgsConstructor
@NoArgsConstructor
public static class ListData {
private List<FaqFile> list;
private int total;
}
// 嵌套在 Data 类中的 FaqFile
@Data
@AllArgsConstructor
@NoArgsConstructor
public static class FaqFile {
private int size;
private String createdAt;
private String fileId;
private String filename;
private String purpose;
private String fileType;
private int tenantId;
private String s3Url;
private int lineCount;
private int tokenCount;
}
}

View File

@ -235,9 +235,14 @@ llm:
# 大模型列表 GET
models_list: http://localhost:8123/api/models
# 登录 POST
login: http://localhost:8123/login
login: http://aigc.xhllm.xinnuojinzhi.com/api/auth/login
account: http://aigc.xhllm.xinnuojinzhi.com/api/auth/account
login_username: admin
login_password: admin
# 创建微调任务 POST
finetuning_create: http://localhost:8123/api/finetuning
finetuning_create: http://aigc.xhllm.xinnuojinzhi.com/api/finetuning
# 微调文件列表 GET
finetuning_file_list: http://aigc.xhllm.xinnuojinzhi.com/api/files?purpose=fine-tune
#### 大模型对话
# 基础模型列表 GET

View File

@ -278,9 +278,14 @@ llm:
# 大模型列表 GET
models_list: http://localhost:8123/api/models
# 登录 POST
login: http://localhost:8123/login
login: http://aigc.xhllm.xinnuojinzhi.com/api/auth/login
account: http://aigc.xhllm.xinnuojinzhi.com/api/auth/account
login_username: admin
login_password: admin
# 创建微调任务 POST
finetuning_create: http://localhost:8123/api/finetuning
finetuning_create: http://aigc.xhllm.xinnuojinzhi.com/api/finetuning
# 微调文件列表 GET
finetuning_file_list: http://aigc.xhllm.xinnuojinzhi.com/api/files?purpose=fine-tune
#### 大模型对话
# 模型列表 GET