hao
commit
fdf0704618
|
@ -0,0 +1,38 @@
|
|||
target/
|
||||
!.mvn/wrapper/maven-wrapper.jar
|
||||
!**/src/main/**/target/
|
||||
!**/src/test/**/target/
|
||||
|
||||
### IntelliJ IDEA ###
|
||||
.idea/modules.xml
|
||||
.idea/jarRepositories.xml
|
||||
.idea/compiler.xml
|
||||
.idea/libraries/
|
||||
*.iws
|
||||
*.iml
|
||||
*.ipr
|
||||
|
||||
### Eclipse ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
.sts4-cache
|
||||
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/.nb-gradle/
|
||||
build/
|
||||
!**/src/main/**/build/
|
||||
!**/src/test/**/build/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
||||
|
||||
### Mac OS ###
|
||||
.DS_Store
|
|
@ -0,0 +1,8 @@
|
|||
# 默认忽略的文件
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# 基于编辑器的 HTTP 客户端请求
|
||||
/httpRequests/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
|
@ -0,0 +1,14 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||
<component name="MavenProjectsManager">
|
||||
<option name="originalFiles">
|
||||
<list>
|
||||
<option value="$PROJECT_DIR$/pom.xml" />
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
|
@ -0,0 +1,108 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>com.bwie</groupId>
|
||||
<artifactId>adminHao10</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-api</artifactId>
|
||||
<version>5.10.0-M1</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-configuration-processor</artifactId>
|
||||
<optional>true</optional>
|
||||
<version>2.7.8</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-all</artifactId>
|
||||
<version>5.8.18</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
<version>2.7.8</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>fastjson</artifactId>
|
||||
<version>1.2.67</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.java-websocket</groupId>
|
||||
<artifactId>Java-WebSocket</artifactId>
|
||||
<version>1.3.8</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.squareup.okhttp3</groupId>
|
||||
<artifactId>okhttp</artifactId>
|
||||
<version>4.9.3</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.24</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-log4j12</artifactId>
|
||||
<version>1.7.30</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<version>5.1.32</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mybatis.spring.boot</groupId>
|
||||
<artifactId>mybatis-spring-boot-starter</artifactId>
|
||||
<version>2.3.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-aop</artifactId>
|
||||
<version>2.7.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.json</groupId>
|
||||
<artifactId>json</artifactId>
|
||||
<version>20210307</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-codec</groupId>
|
||||
<artifactId>commons-codec</artifactId>
|
||||
<version>1.15</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.amazonaws</groupId>
|
||||
<artifactId>aws-java-sdk-s3</artifactId>
|
||||
<version>1.12.68</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.amazonaws</groupId>
|
||||
<artifactId>aws-java-sdk-core</artifactId>
|
||||
<version>1.12.68</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,12 @@
|
|||
package com.bwie;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class WorkApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(WorkApplication.class);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package com.bwie.annotation;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* 接口幂等性校验注解
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.METHOD)
|
||||
public @interface Idempotent {
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
package com.bwie.aspect;
|
||||
|
||||
import com.bwie.annotation.Idempotent;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* 切面进行幂等性实现
|
||||
*/
|
||||
public class IdempotentAspect {
|
||||
|
||||
@Around("@annotation(idempotent)")
|
||||
public Object independent(ProceedingJoinPoint joinPoint, Idempotent idempotent) {
|
||||
Object result=null;
|
||||
Map<String,Object> map=new ConcurrentHashMap<String,Object>();
|
||||
String id = generateId(joinPoint.getArgs());
|
||||
try {
|
||||
if (map.containsKey(id)){
|
||||
System.out.println("不要重复提交请求");
|
||||
return map.get(id);
|
||||
}
|
||||
result= joinPoint.proceed();
|
||||
} catch (Throwable throwable) {
|
||||
throwable.printStackTrace();
|
||||
}
|
||||
map.put(id,result);
|
||||
return result;
|
||||
}
|
||||
|
||||
private String generateId(Object[] args){
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
for (Object arg : args) {
|
||||
stringBuilder.append(arg.hashCode());
|
||||
}
|
||||
return stringBuilder.toString();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
package com.bwie.common;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Builder
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class MsgDTO {
|
||||
|
||||
private String role;
|
||||
/**
|
||||
* 消息内容
|
||||
*/
|
||||
private String content;
|
||||
/**
|
||||
* 响应结果字段:结果序号,取值为[0,10]; 当前为保留字段,开发者可忽略
|
||||
*/
|
||||
private Integer index;
|
||||
|
||||
public static final String ROLE_USER = "user";
|
||||
public static final String ROLE_ASSISTANT = "assistant";
|
||||
|
||||
public static MsgDTO createUserMsg(String content) {
|
||||
return new MsgDTO(ROLE_USER, content, null);
|
||||
}
|
||||
|
||||
public static MsgDTO createAssistantMsg(String content) {
|
||||
return new MsgDTO(ROLE_ASSISTANT, content, null);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,75 @@
|
|||
package com.bwie.common;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author DongZl
|
||||
* @description: 响应信息主体
|
||||
*/
|
||||
@Data
|
||||
public class Result<T> implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
/**
|
||||
* 成功
|
||||
*/
|
||||
public static final int SUCCESS = 200;
|
||||
/**
|
||||
* 失败
|
||||
*/
|
||||
public static final int FAIL = 500;
|
||||
/**
|
||||
* 返回状态码
|
||||
*/
|
||||
private int code;
|
||||
/**
|
||||
* 响应信息
|
||||
*/
|
||||
private String msg;
|
||||
/**
|
||||
* 响应数据
|
||||
*/
|
||||
private T data;
|
||||
|
||||
public static <T> Result<T> success() {
|
||||
return restResult(null, SUCCESS, "操作成功");
|
||||
}
|
||||
|
||||
public static <T> Result<T> success(T data) {
|
||||
return restResult(data, SUCCESS, "操作成功");
|
||||
}
|
||||
|
||||
public static <T> Result<T> success(T data, String msg) {
|
||||
return restResult(data, SUCCESS, msg);
|
||||
}
|
||||
|
||||
public static <T> Result<T> error() {
|
||||
return restResult(null, FAIL, "操作失败");
|
||||
}
|
||||
|
||||
public static <T> Result<T> error(String msg) {
|
||||
return restResult(null, FAIL, msg);
|
||||
}
|
||||
|
||||
public static <T> Result<T> error(T data) {
|
||||
return restResult(data, FAIL, "操作失败");
|
||||
}
|
||||
|
||||
public static <T> Result<T> error(T data, String msg) {
|
||||
return restResult(data, FAIL, msg);
|
||||
}
|
||||
|
||||
public static <T> Result<T> error(int code, String msg) {
|
||||
return restResult(null, code, msg);
|
||||
}
|
||||
|
||||
private static <T> Result<T> restResult(T data, int code, String msg) {
|
||||
Result<T> apiResult = new Result<T>();
|
||||
apiResult.setCode(code);
|
||||
apiResult.setData(data);
|
||||
apiResult.setMsg(msg);
|
||||
return apiResult;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
package com.bwie.common.request;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class LoginRequest {
|
||||
private String userName;
|
||||
private String userPwd;
|
||||
}
|
|
@ -0,0 +1,93 @@
|
|||
package com.bwie.common.request;
|
||||
|
||||
/**
|
||||
* @author 冯凯
|
||||
* @version 1.0
|
||||
* @description: TODO
|
||||
* @date 2023/9/29 13:56
|
||||
*/
|
||||
|
||||
import com.bwie.common.MsgDTO;
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 请求参数
|
||||
* 对应生成的 JSON 结构参考 resources/demo-json/request.json
|
||||
*/
|
||||
@NoArgsConstructor
|
||||
@Data
|
||||
public class RequestDTO {
|
||||
|
||||
@JsonProperty("header")
|
||||
private HeaderDTO header;
|
||||
@JsonProperty("parameter")
|
||||
private ParameterDTO parameter;
|
||||
@JsonProperty("payload")
|
||||
private PayloadDTO payload;
|
||||
|
||||
@NoArgsConstructor
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public static class HeaderDTO {
|
||||
/**
|
||||
* 应用appid,从开放平台控制台创建的应用中获取
|
||||
*/
|
||||
@JSONField(name = "app_id")
|
||||
private String appId;
|
||||
/**
|
||||
* 每个用户的id,用于区分不同用户,最大长度32
|
||||
*/
|
||||
@JSONField(name = "uid")
|
||||
private String uid;
|
||||
}
|
||||
|
||||
@NoArgsConstructor
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public static class ParameterDTO {
|
||||
private ChatDTO chat;
|
||||
|
||||
@NoArgsConstructor
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public static class ChatDTO {
|
||||
/**
|
||||
* 指定访问的领域,general指向V1.5版本 generalv2指向V2版本。注意:不同的取值对应的url也不一样!
|
||||
*/
|
||||
@JsonProperty("domain")
|
||||
private String domain;
|
||||
/**
|
||||
* 核采样阈值。用于决定结果随机性,取值越高随机性越强即相同的问题得到的不同答案的可能性越高
|
||||
*/
|
||||
@JsonProperty("temperature")
|
||||
private Float temperature;
|
||||
/**
|
||||
* 模型回答的tokens的最大长度
|
||||
*/
|
||||
@JSONField(name = "max_tokens")
|
||||
private Integer maxTokens;
|
||||
}
|
||||
}
|
||||
|
||||
@NoArgsConstructor
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public static class PayloadDTO {
|
||||
@JsonProperty("message")
|
||||
private MessageDTO message;
|
||||
|
||||
@NoArgsConstructor
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public static class MessageDTO {
|
||||
@JsonProperty("text")
|
||||
private List<MsgDTO> text;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,112 @@
|
|||
package com.bwie.common.response;
|
||||
|
||||
import com.bwie.common.MsgDTO;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 返回参数
|
||||
* 对应生成的 JSON 结构参考 resources/demo-json/response.json
|
||||
*/
|
||||
@NoArgsConstructor
|
||||
@Data
|
||||
public class ResponseDTO {
|
||||
|
||||
@JsonProperty("header")
|
||||
private HeaderDTO header;
|
||||
@JsonProperty("payload")
|
||||
private PayloadDTO payload;
|
||||
|
||||
@NoArgsConstructor
|
||||
@Data
|
||||
public static class HeaderDTO {
|
||||
/**
|
||||
* 错误码,0表示正常,非0表示出错
|
||||
*/
|
||||
@JsonProperty("code")
|
||||
private Integer code;
|
||||
/**
|
||||
* 会话是否成功的描述信息
|
||||
*/
|
||||
@JsonProperty("message")
|
||||
private String message;
|
||||
/**
|
||||
* 会话的唯一id,用于讯飞技术人员查询服务端会话日志使用,出现调用错误时建议留存该字段
|
||||
*/
|
||||
@JsonProperty("sid")
|
||||
private String sid;
|
||||
/**
|
||||
* 会话状态,取值为[0,1,2];0代表首次结果;1代表中间结果;2代表最后一个结果
|
||||
*/
|
||||
@JsonProperty("status")
|
||||
private Integer status;
|
||||
}
|
||||
|
||||
@NoArgsConstructor
|
||||
@Data
|
||||
public static class PayloadDTO {
|
||||
@JsonProperty("choices")
|
||||
private ChoicesDTO choices;
|
||||
/**
|
||||
* 在最后一次结果返回
|
||||
*/
|
||||
@JsonProperty("usage")
|
||||
private UsageDTO usage;
|
||||
|
||||
@NoArgsConstructor
|
||||
@Data
|
||||
public static class ChoicesDTO {
|
||||
/**
|
||||
* 文本响应状态,取值为[0,1,2]; 0代表首个文本结果;1代表中间文本结果;2代表最后一个文本结果
|
||||
*/
|
||||
@JsonProperty("status")
|
||||
private Integer status;
|
||||
/**
|
||||
* 返回的数据序号,取值为[0,9999999]
|
||||
*/
|
||||
@JsonProperty("seq")
|
||||
private Integer seq;
|
||||
/**
|
||||
* 响应文本
|
||||
*/
|
||||
@JsonProperty("text")
|
||||
private List<MsgDTO> text;
|
||||
|
||||
}
|
||||
|
||||
@NoArgsConstructor
|
||||
@Data
|
||||
public static class UsageDTO {
|
||||
@JsonProperty("text")
|
||||
private TextDTO text;
|
||||
|
||||
@NoArgsConstructor
|
||||
@Data
|
||||
public static class TextDTO {
|
||||
/**
|
||||
* 保留字段,可忽略
|
||||
*/
|
||||
@JsonProperty("question_tokens")
|
||||
private Integer questionTokens;
|
||||
/**
|
||||
* 包含历史问题的总tokens大小
|
||||
*/
|
||||
@JsonProperty("prompt_tokens")
|
||||
private Integer promptTokens;
|
||||
/**
|
||||
* 回答的tokens大小
|
||||
*/
|
||||
@JsonProperty("completion_tokens")
|
||||
private Integer completionTokens;
|
||||
/**
|
||||
* prompt_tokens和completion_tokens的和,也是本次交互计费的tokens大小
|
||||
*/
|
||||
@JsonProperty("total_tokens")
|
||||
private Integer totalTokens;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,154 @@
|
|||
package com.bwie.component;
|
||||
|
||||
import com.bwie.common.MsgDTO;
|
||||
import com.bwie.common.request.RequestDTO;
|
||||
import com.bwie.config.XfXhConfig;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import okhttp3.*;
|
||||
import org.java_websocket.WebSocket;
|
||||
import org.java_websocket.WebSocketListener;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.crypto.Mac;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class XfXhStreamClient {
|
||||
|
||||
/**
|
||||
* @author fst
|
||||
*/
|
||||
@Resource
|
||||
private XfXhConfig xfXhConfig;
|
||||
|
||||
@Value("${xfxh.QPS}")
|
||||
private int connectionTokenCount;
|
||||
|
||||
/**
|
||||
* 获取令牌
|
||||
*/
|
||||
public static int GET_TOKEN_STATUS = 0;
|
||||
/**
|
||||
* 归还令牌
|
||||
*/
|
||||
public static int BACK_TOKEN_STATUS = 1;
|
||||
|
||||
/**
|
||||
* 操作令牌
|
||||
*
|
||||
* @param status 0-获取令牌 1-归还令牌
|
||||
* @return 是否操作成功
|
||||
*/
|
||||
public synchronized boolean operateToken(int status) {
|
||||
if (status == GET_TOKEN_STATUS) {
|
||||
// 获取令牌
|
||||
if (connectionTokenCount != 0) {
|
||||
// 说明还有令牌,将令牌数减一
|
||||
connectionTokenCount -= 1;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
// 放回令牌
|
||||
connectionTokenCount += 1;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送消息
|
||||
*
|
||||
* @param uid 每个用户的id,用于区分不同用户
|
||||
* @param msgList 发送给大模型的消息,可以包含上下文内容
|
||||
* @return 获取websocket连接,以便于我们在获取完整大模型回复后手动关闭连接
|
||||
*/
|
||||
public WebSocket sendMsg(String uid, List<MsgDTO> msgList, WebSocketListener listener) {
|
||||
// 获取鉴权url
|
||||
String authUrl = this.getAuthUrl();
|
||||
// 鉴权方法生成失败,直接返回 null
|
||||
if (authUrl == null) {
|
||||
return null;
|
||||
}
|
||||
OkHttpClient okHttpClient = new OkHttpClient.Builder().build();
|
||||
// 将 https/http 连接替换为 ws/wss 连接
|
||||
String url = authUrl.replace("http://", "ws://").replace("https://", "wss://");
|
||||
Request request = new Request.Builder().url(url).build();
|
||||
// 建立 wss 连接
|
||||
WebSocket webSocket = okHttpClient.newWebSocket(request, listener);
|
||||
// 组装请求参数
|
||||
RequestDTO requestDTO = getRequestParam(uid, msgList);
|
||||
// 发送请求
|
||||
webSocket.send(JSONObject.toJSONString(requestDTO));
|
||||
return webSocket;
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成鉴权方法,具体实现不用关心,这是讯飞官方定义的鉴权方式
|
||||
*
|
||||
* @return 鉴权访问大模型的路径
|
||||
*/
|
||||
public String getAuthUrl() {
|
||||
try {
|
||||
URL url = new URL(xfXhConfig.getHostUrl());
|
||||
// 时间
|
||||
SimpleDateFormat format = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z", Locale.US);
|
||||
format.setTimeZone(TimeZone.getTimeZone("GMT"));
|
||||
String date = format.format(new Date());
|
||||
// 拼接
|
||||
String preStr = "host: " + url.getHost() + "\n" +
|
||||
"date: " + date + "\n" +
|
||||
"GET " + url.getPath() + " HTTP/1.1";
|
||||
// SHA256加密
|
||||
Mac mac = Mac.getInstance("hmacsha256");
|
||||
SecretKeySpec spec = new SecretKeySpec(xfXhConfig.getApiSecret().getBytes(StandardCharsets.UTF_8), "hmacsha256");
|
||||
mac.init(spec);
|
||||
|
||||
byte[] hexDigits = mac.doFinal(preStr.getBytes(StandardCharsets.UTF_8));
|
||||
// Base64加密
|
||||
String sha = Base64.getEncoder().encodeToString(hexDigits);
|
||||
// 拼接
|
||||
String authorizationOrigin = String.format("api_key=\"%s\", algorithm=\"%s\", headers=\"%s\", signature=\"%s\"", xfXhConfig.getApiKey(), "hmac-sha256", "host date request-line", sha);
|
||||
// 拼接地址
|
||||
HttpUrl httpUrl = Objects.requireNonNull(HttpUrl.parse("https://" + url.getHost() + url.getPath())).newBuilder().
|
||||
addQueryParameter("authorization", Base64.getEncoder().encodeToString(authorizationOrigin.getBytes(StandardCharsets.UTF_8))).
|
||||
addQueryParameter("date", date).
|
||||
addQueryParameter("host", url.getHost()).
|
||||
build();
|
||||
|
||||
return httpUrl.toString();
|
||||
} catch (Exception e) {
|
||||
log.error("鉴权方法中发生错误:" + e.getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取请求参数
|
||||
*
|
||||
* @param uid 每个用户的id,用于区分不同用户
|
||||
* @param msgList 发送给大模型的消息,可以包含上下文内容
|
||||
* @return 请求DTO,该 DTO 转 json 字符串后生成的格式参考 resources/demo-json/request.json
|
||||
*/
|
||||
public RequestDTO getRequestParam(String uid, List<MsgDTO> msgList) {
|
||||
RequestDTO requestDTO = new RequestDTO();
|
||||
requestDTO.setHeader(new RequestDTO.HeaderDTO(xfXhConfig.getAppId(), uid));
|
||||
requestDTO.setParameter(new RequestDTO.ParameterDTO(new RequestDTO.ParameterDTO.ChatDTO(xfXhConfig.getDomain(), xfXhConfig.getTemperature(), xfXhConfig.getMaxTokens())));
|
||||
requestDTO.setPayload(new RequestDTO.PayloadDTO(new RequestDTO.PayloadDTO.MessageDTO(msgList)));
|
||||
return requestDTO;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
package com.bwie.config;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
@Configuration
|
||||
public class CorsConfig implements WebMvcConfigurer {
|
||||
|
||||
public void addCorsMappings(CorsRegistry registry) {
|
||||
registry.addMapping("/test/sendQuestion")
|
||||
.allowedOrigins("http://localhost:9528")
|
||||
.allowedMethods("GET", "POST")
|
||||
.allowCredentials(true)
|
||||
.maxAge(3600);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
package com.bwie.config;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
|
||||
@Configuration
|
||||
@ConfigurationProperties(prefix = "xfxh")
|
||||
@Data
|
||||
public class XfXhConfig {
|
||||
|
||||
|
||||
/**
|
||||
* 服务引擎使用 讯飞星火认知大模型V2.0,如果使用 V1.5 需要将 hostUrl 修改为 https://spark-api.xf-yun.com/v1.1/chat
|
||||
*/
|
||||
private String hostUrl;
|
||||
/**
|
||||
* 发送请求时指定的访问领域,如果是 V1.5版本 设置为 general,如果是 V2版本 设置为 generalv2
|
||||
*/
|
||||
private String domain;
|
||||
/**
|
||||
* 核采样阈值。用于决定结果随机性,取值越高随机性越强即相同的问题得到的不同答案的可能性越高。取值 [0,1]
|
||||
*/
|
||||
private Float temperature;
|
||||
/**
|
||||
* 模型回答的tokens的最大长度,V1.5取值为[1,4096],V2.0取值为[1,8192]。
|
||||
*/
|
||||
private Integer maxTokens;
|
||||
/**
|
||||
* 大模型回复问题的最大响应时长,单位 s
|
||||
*/
|
||||
private Integer maxResponseTime;
|
||||
/**
|
||||
* 用于权限验证,从服务接口认证信息中获取
|
||||
*/
|
||||
private String appId;
|
||||
/**
|
||||
* 用于权限验证,从服务接口认证信息中获取
|
||||
*/
|
||||
private String apiKey;
|
||||
/**
|
||||
* 用于权限验证,从服务接口认证信息中获取
|
||||
*/
|
||||
private String apiSecret;
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,95 @@
|
|||
package com.bwie.controller;
|
||||
|
||||
import com.bwie.common.MsgDTO;
|
||||
import com.bwie.component.XfXhStreamClient;
|
||||
import com.bwie.config.XfXhConfig;
|
||||
import com.bwie.listener.XfXhWebSocketListener;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.java_websocket.WebSocket;
|
||||
import org.java_websocket.WebSocketListener;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Collections;
|
||||
import java.util.UUID;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/test")
|
||||
@Slf4j
|
||||
public class ChatController {
|
||||
|
||||
|
||||
@Resource
|
||||
private XfXhStreamClient xfXhStreamClient;
|
||||
|
||||
@Resource
|
||||
private XfXhConfig xfXhConfig;
|
||||
|
||||
|
||||
/**
|
||||
* 发送问题
|
||||
*
|
||||
* @param question 问题
|
||||
* @return 星火大模型的回答
|
||||
*/
|
||||
@GetMapping("/sendQuestion")
|
||||
public String sendQuestion(@RequestParam("question") String question) {
|
||||
// 如果是无效字符串,则不对大模型进行请求
|
||||
if (StrUtil.isBlank(question)) {
|
||||
return "无效问题,请重新输入";
|
||||
}
|
||||
// 获取连接令牌
|
||||
if (!xfXhStreamClient.operateToken(XfXhStreamClient.GET_TOKEN_STATUS)) {
|
||||
return "当前大模型连接数过多,请稍后再试";
|
||||
}
|
||||
|
||||
// 创建消息对象
|
||||
MsgDTO msgDTO = MsgDTO.createUserMsg(question);
|
||||
// 创建监听器
|
||||
XfXhWebSocketListener listener = new XfXhWebSocketListener();
|
||||
// XfXhWebSocketListener xfXhWebSocketListener = new XfXhWebSocketListener();
|
||||
// 发送问题给大模型,生成 websocket 连接
|
||||
|
||||
WebSocket webSocket = xfXhStreamClient.sendMsg(UUID.randomUUID().toString().substring(0, 10), Collections.singletonList(msgDTO), (WebSocketListener) listener);
|
||||
|
||||
if (webSocket == null) {
|
||||
// 归还令牌
|
||||
xfXhStreamClient.operateToken(XfXhStreamClient.BACK_TOKEN_STATUS);
|
||||
return "系统内部错误,请联系管理员";
|
||||
}
|
||||
try {
|
||||
int count = 0;
|
||||
// 为了避免死循环,设置循环次数来定义超时时长
|
||||
int maxCount = xfXhConfig.getMaxResponseTime() * 5;
|
||||
while (count <= maxCount) {
|
||||
Thread.sleep(200);
|
||||
if (listener.isWsCloseFlag()) {
|
||||
break;
|
||||
}
|
||||
count++;
|
||||
}
|
||||
if (count > maxCount) {
|
||||
return "大模型响应超时,请联系管理员";
|
||||
}
|
||||
// 响应大模型的答案
|
||||
System.out.println(listener.getAnswer().toString());
|
||||
return listener.getAnswer().toString();
|
||||
} catch (InterruptedException e) {
|
||||
log.error("错误:" + e.getMessage());
|
||||
return "系统内部错误,请联系管理员";
|
||||
} finally {
|
||||
// 关闭 websocket 连接
|
||||
webSocket.close(1000, "");
|
||||
// 归还令牌
|
||||
xfXhStreamClient.operateToken(XfXhStreamClient.BACK_TOKEN_STATUS);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
package com.bwie.controller;
|
||||
|
||||
|
||||
import com.bwie.common.Result;
|
||||
import com.bwie.common.request.LoginRequest;
|
||||
import com.bwie.service.impl.UserServiceImpl;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
public class UserController {
|
||||
@Autowired
|
||||
private UserServiceImpl userService;
|
||||
|
||||
/**
|
||||
* 登录
|
||||
* @param loginRequest
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("login")
|
||||
public Result login(@RequestBody LoginRequest loginRequest){
|
||||
return userService.login(loginRequest);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,121 @@
|
|||
package com.bwie.duojiyun;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.InvalidKeyException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.crypto.Mac;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
|
||||
import org.json.JSONObject;
|
||||
import org.apache.commons.codec.binary.Hex;
|
||||
|
||||
/**
|
||||
* 多吉云API接口
|
||||
*/
|
||||
public class DogGetApi {
|
||||
|
||||
|
||||
// 普通 API 请使用这个方法
|
||||
public static JSONObject dogeAPIGet(String apiPath, Map<String, String> params) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for(Map.Entry<String, String> hm : params.entrySet()){
|
||||
try {
|
||||
sb.append(URLEncoder.encode(hm.getKey(), String.valueOf(StandardCharsets.UTF_8))).append('=').append(URLEncoder.encode(hm.getValue(), String.valueOf(StandardCharsets.UTF_8))).append("&");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
String bodyText = sb.toString().replace("&$", "");
|
||||
try {
|
||||
return dogeAPIGet(apiPath, bodyText, false);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
// 要求请求内容 Body 是一个 JSON 的 API,请使用这个方法
|
||||
public static JSONObject dogeAPIGet(String apiPath, JSONObject params) {
|
||||
String bodyText = params.toString();
|
||||
try {
|
||||
return dogeAPIGet(apiPath, bodyText, true);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
// 无参数 API
|
||||
public static JSONObject dogeAPIGet(String apiPath) {
|
||||
try {
|
||||
return dogeAPIGet(apiPath, "", true);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public static JSONObject dogeAPIGet(String apiPath, String paramsText, Boolean jsonMode) throws IOException{
|
||||
// 这里返回值类型是 JSONObject,你也可以根据你的具体情况使用不同的 JSON 库并修改最下方 JSON 处理代码
|
||||
|
||||
// 这里替换为你的多吉云永久 AccessKey 和 SecretKey,可在用户中心 - 密钥管理中查看
|
||||
// 请勿在客户端暴露 AccessKey 和 SecretKey,那样恶意用户将获得账号完全控制权
|
||||
String accessKey = "kjd189189u981kj";
|
||||
String secretKey = "ada91871ns1jc9711jkn981d";
|
||||
|
||||
String signStr = apiPath + "\n" + paramsText;
|
||||
String sign = "";
|
||||
try {
|
||||
Mac mac = Mac.getInstance("HmacSHA1");
|
||||
mac.init(new SecretKeySpec(secretKey.getBytes(), "HmacSHA1"));
|
||||
sign = new String(new Hex().encode(mac.doFinal(signStr.getBytes())), StandardCharsets.UTF_8); // 这里 Hex 来自 org.apache.commons.codec.binary.Hex
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException(e.getMessage());
|
||||
} catch (InvalidKeyException e) {
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException(e.getMessage());
|
||||
}
|
||||
String authorization = "TOKEN " + accessKey + ':' + sign;
|
||||
|
||||
URL u = new URL("https://api.dogecloud.com" + apiPath);
|
||||
HttpURLConnection conn = (HttpURLConnection) u.openConnection();
|
||||
conn.setDoOutput(true);
|
||||
conn.setRequestMethod("POST");
|
||||
conn.setRequestProperty( "Content-Type", jsonMode ? "application/json" : "application/x-www-form-urlencoded");
|
||||
conn.setRequestProperty( "Authorization", authorization);
|
||||
conn.setRequestProperty( "Content-Length", String.valueOf(paramsText.length()));
|
||||
OutputStream os = conn.getOutputStream();
|
||||
os.write(paramsText.getBytes());
|
||||
os.flush();
|
||||
os.close();
|
||||
StringBuilder retJSON = new StringBuilder();
|
||||
if(conn.getResponseCode() == HttpURLConnection.HTTP_OK){
|
||||
String readLine = "";
|
||||
try (BufferedReader responseReader=new BufferedReader(new InputStreamReader(conn.getInputStream(), StandardCharsets.UTF_8))) {
|
||||
while((readLine=responseReader.readLine())!=null){
|
||||
retJSON.append(readLine).append("\n");
|
||||
}
|
||||
responseReader.close();
|
||||
}
|
||||
JSONObject ret = new JSONObject(retJSON.toString());
|
||||
if (ret.getInt("code") != 200) {
|
||||
System.err.println("{\"error\":\"API 返回错误:" + ret.getString("msg") + "\"}");
|
||||
} else {
|
||||
JSONObject output = new JSONObject();
|
||||
JSONObject data = ret.getJSONObject("data");
|
||||
return data;
|
||||
}
|
||||
} else {
|
||||
System.err.println("{\"error\":\"网络错误:" + conn.getResponseCode() + "\"}");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
package com.bwie.duojiyun;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import static com.bwie.duojiyun.DogGetApi.dogeAPIGet;
|
||||
|
||||
|
||||
public class DuoJiYunUtil {
|
||||
|
||||
//用来调用多吉云API获取秘钥
|
||||
public static JSONObject getCredentials() {
|
||||
JSONObject body = new JSONObject();
|
||||
body.put("channel", "OSS_FULL");
|
||||
body.append("scopes", "*"); // 要操作的存储空间名称,注意不是 s3Bucket 值,也可以设置为 *
|
||||
|
||||
JSONObject data = dogeAPIGet("/auth/tmp_token.json", body);
|
||||
JSONObject credentials = data.getJSONObject("Credentials");
|
||||
return credentials;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
package com.bwie.duojiyun;
|
||||
import com.amazonaws.auth.AWSStaticCredentialsProvider;
|
||||
import com.amazonaws.auth.BasicSessionCredentials;
|
||||
import com.amazonaws.client.builder.AwsClientBuilder;
|
||||
import com.amazonaws.services.s3.AmazonS3;
|
||||
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
|
||||
import com.amazonaws.services.s3.model.PutObjectResult;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import static com.bwie.duojiyun.DogGetApi.dogeAPIGet;
|
||||
|
||||
public class S3 {
|
||||
|
||||
public static AmazonS3 initS3(JSONObject credentials){
|
||||
BasicSessionCredentials awsCredentials = new BasicSessionCredentials(credentials.getString("accessKeyId"), credentials.getString("secretAccessKey"), credentials.getString("sessionToken"));
|
||||
AmazonS3 s3 = AmazonS3ClientBuilder.standard()
|
||||
.withCredentials(new AWSStaticCredentialsProvider(awsCredentials))
|
||||
.withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(
|
||||
"https://cos.ap-shanghai.myqcloud.com", // 修改为多吉云控制台存储空间 SDK 参数中的 s3Endpoint
|
||||
"automatic"))
|
||||
.build();
|
||||
return s3;
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
JSONObject data = dogeAPIGet("/oss/bucket/list.json");
|
||||
JSONArray buckets = data.getJSONArray("buckets");
|
||||
for (int i = 0 ; i < buckets.length(); i++) {
|
||||
System.out.println(buckets.getJSONObject(i).toString());
|
||||
}
|
||||
|
||||
JSONObject credentials = DuoJiYunUtil.getCredentials();
|
||||
AmazonS3 s3 = initS3(credentials);
|
||||
PutObjectResult putObjectResult = s3.putObject("s-sh-6719-fst-198781691", "666.png", new File("D:\\fst\\111\\118981998299818921.png"));
|
||||
String string = putObjectResult.toString();
|
||||
System.out.println(string);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
package com.bwie.listener;
|
||||
|
||||
import com.bwie.common.MsgDTO;
|
||||
import com.bwie.common.response.ResponseDTO;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import okhttp3.Response;
|
||||
import okhttp3.WebSocket;
|
||||
import okhttp3.WebSocketListener;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@Slf4j
|
||||
public class XfXhWebSocketListener extends WebSocketListener {
|
||||
private StringBuilder answer = new StringBuilder();
|
||||
|
||||
private boolean wsCloseFlag = false;
|
||||
|
||||
public StringBuilder getAnswer() {
|
||||
return answer;
|
||||
}
|
||||
|
||||
public boolean isWsCloseFlag() {
|
||||
return wsCloseFlag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onOpen(@NotNull WebSocket webSocket, @NotNull Response response) {
|
||||
super.onOpen(webSocket, response);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMessage(@NotNull WebSocket webSocket, @NotNull String text) {
|
||||
super.onMessage(webSocket, text);
|
||||
// 将大模型回复的 JSON 文本转为 ResponseDTO 对象
|
||||
ResponseDTO responseData = JSONObject.parseObject(text, ResponseDTO.class);
|
||||
// 如果响应数据中的 header 的 code 值不为 0,则表示响应错误
|
||||
if (responseData.getHeader().getCode() != 0) {
|
||||
// 日志记录
|
||||
log.error("发生错误,错误码为:" + responseData.getHeader().getCode() + "; " + "信息:" + responseData.getHeader().getMessage());
|
||||
// 设置回答
|
||||
this.answer = new StringBuilder("大模型响应错误,请稍后再试");
|
||||
// 关闭连接标识
|
||||
wsCloseFlag = true;
|
||||
return;
|
||||
}
|
||||
// 将回答进行拼接
|
||||
for (MsgDTO msgDTO : responseData.getPayload().getChoices().getText()) {
|
||||
this.answer.append(msgDTO.getContent());
|
||||
}
|
||||
// 对最后一个文本结果进行处理
|
||||
if (2 == responseData.getHeader().getStatus()) {
|
||||
wsCloseFlag = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@NotNull WebSocket webSocket, @NotNull Throwable t, @Nullable Response response) {
|
||||
super.onFailure(webSocket, t, response);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClosed(@NotNull WebSocket webSocket, int code, @NotNull String reason) {
|
||||
super.onClosed(webSocket, code, reason);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
package com.bwie.mapper;
|
||||
|
||||
import com.bwie.common.request.LoginRequest;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Mapper
|
||||
@Component
|
||||
public interface UserMapper {
|
||||
LoginRequest login(LoginRequest loginRequest);
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
package com.bwie.service;
|
||||
|
||||
|
||||
import com.bwie.common.Result;
|
||||
import com.bwie.common.request.LoginRequest;
|
||||
|
||||
public interface UserService {
|
||||
Result login(LoginRequest loginRequest);
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
package com.bwie.service.impl;
|
||||
|
||||
import com.bwie.annotation.Idempotent;
|
||||
import com.bwie.common.Result;
|
||||
import com.bwie.common.request.LoginRequest;
|
||||
import com.bwie.mapper.UserMapper;
|
||||
import com.bwie.service.UserService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class UserServiceImpl implements UserService {
|
||||
@Autowired
|
||||
private UserMapper userMapper;
|
||||
|
||||
/**
|
||||
* |登录
|
||||
* @param loginRequest
|
||||
* @return
|
||||
*/
|
||||
@Idempotent
|
||||
public Result login(LoginRequest loginRequest) {
|
||||
LoginRequest loginRequest1 = userMapper.login(loginRequest);
|
||||
if (loginRequest1==null){
|
||||
return Result.error("账号密码错误");
|
||||
}
|
||||
return Result.success();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package com.bwie.test;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* 算法
|
||||
*/
|
||||
public class Test01 {
|
||||
@Test
|
||||
public int canJump(int[] nums) {
|
||||
int maxIndex = 0; // 每次跳跃后的最大边界
|
||||
int step = 0; // 记录跳跃步数
|
||||
int end = 0; // 每一次搜完一层后更新end,并且将步数加1,直到可以跳到最后一格
|
||||
for (int i = 0; i < nums.length - 1; i++) {
|
||||
if (maxIndex >= i) {
|
||||
maxIndex = Math.max(maxIndex, i + nums[i]); // 找到下次可以到达的最远边界。
|
||||
if (i == end) { // 如果已经搜完了这一层,就将步数加1,并更新end的位置。
|
||||
end = maxIndex;
|
||||
step++;
|
||||
}
|
||||
}
|
||||
}
|
||||
return step;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
|
||||
server:
|
||||
port: 8080
|
||||
spring:
|
||||
datasource:
|
||||
driver-class-name: com.mysql.jdbc.Driver
|
||||
url: jdbc:mysql://localhost:3306/chat?useUnicode=true&characterEncoding=utf8
|
||||
username: root
|
||||
password: 3121
|
||||
name: defaultDataSource
|
||||
mybatis:
|
||||
mapper-locations: mapper/*xml
|
||||
mybatis:
|
||||
configuration:
|
||||
map-underscore-to-camel-case: true
|
||||
|
||||
xfxh:
|
||||
# 服务引擎使用 讯飞星火认知大模型V2.0,如果使用 V1.5 需要将 hostUrl 修改为 https://spark-api.xf-yun.com/v1.1/chat
|
||||
hostUrl: https://spark-api.xf-yun.com/v2.1/chat
|
||||
# 发送请求时指定的访问领域,如果是 V1.5版本 设置为 general,如果是 V2版本 设置为 generalv2
|
||||
domain: generalv2
|
||||
# 核采样阈值。用于决定结果随机性,取值越高随机性越强即相同的问题得到的不同答案的可能性越高。取值 [0,1]
|
||||
temperature: 0.5
|
||||
# 模型回答的tokens的最大长度,V1.5取值为[1,4096],V2.0取值为[1,8192]。
|
||||
maxTokens: 2048
|
||||
# 大模型回复问题的最大响应时长,单位 s
|
||||
maxResponseTime: 30
|
||||
# 允许同时连接大模型的 websocket 数,如果是普通(免费)用户为 2,超过这个数连接响应会报错,具体参考官网。
|
||||
QPS: 2
|
||||
# 用于权限验证,从服务接口认证信息中获取
|
||||
appId: 3a5er24h
|
||||
# 用于权限验证,从服务接口认证信息中获取
|
||||
apiKey: d2hu6f5ace8fdea0982a0eaff658408dh
|
||||
# 用于权限验证,从服务接口认证信息中获取
|
||||
apiSecret: Cst3AJIxEjDyCKQ0MTdiOQIyKIdlLOAi
|
|
@ -0,0 +1,10 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.bwie.mapper.UserMapper">
|
||||
|
||||
<select id="login" resultType="com.bwie.common.request.LoginRequest">
|
||||
select *from t_user where user_name=#{userName} and user_pwd=#{userPwd}
|
||||
</select>
|
||||
</mapper>
|
Loading…
Reference in New Issue