2.0
This commit is contained in:
parent
7d7802acb8
commit
4d0b72c0a0
|
@ -37,7 +37,7 @@ public class ApiController {
|
||||||
return openAiService.processImage(path.toFile());
|
return openAiService.processImage(path.toFile());
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping("/timeChange")
|
@GetMapping("/timeChange")
|
||||||
public ResponseEntity<String> timeChange(@RequestParam("time") String time) {
|
public ResponseEntity<String> timeChange(@RequestParam("time") String time) {
|
||||||
return openAiService.timeChange(time);
|
return openAiService.timeChange(time);
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,6 @@ public class WebSocketServer {
|
||||||
public void onOpen(Session session) throws IOException {
|
public void onOpen(Session session) throws IOException {
|
||||||
sessionList.add(session);
|
sessionList.add(session);
|
||||||
log.info("有新用户加入聊天,当前在线人数为{}", sessionList.size());
|
log.info("有新用户加入聊天,当前在线人数为{}", sessionList.size());
|
||||||
sendAllSession("二级");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@OnMessage
|
@OnMessage
|
||||||
|
@ -46,7 +45,7 @@ public class WebSocketServer {
|
||||||
/*
|
/*
|
||||||
* 发消息给客户端
|
* 发消息给客户端
|
||||||
* */
|
* */
|
||||||
public void sendAllSession(String message){
|
public static void sendAllSession(String message){
|
||||||
|
|
||||||
try {
|
try {
|
||||||
for (Session session : sessionList) {
|
for (Session session : sessionList) {
|
||||||
|
|
|
@ -23,6 +23,7 @@ public class InterceptorConfig implements WebMvcConfigurer {
|
||||||
excludePath.add("/apiSend");
|
excludePath.add("/apiSend");
|
||||||
excludePath.add("/timeChange");
|
excludePath.add("/timeChange");
|
||||||
excludePath.add("/timeGet");
|
excludePath.add("/timeGet");
|
||||||
|
excludePath.add("/images/**");//图片
|
||||||
registry.addInterceptor(tokenInterceptor)//注册拦截器
|
registry.addInterceptor(tokenInterceptor)//注册拦截器
|
||||||
.addPathPatterns("/**")//拦截所有请求
|
.addPathPatterns("/**")//拦截所有请求
|
||||||
.excludePathPatterns(excludePath);//添加拦截白名单
|
.excludePathPatterns(excludePath);//添加拦截白名单
|
||||||
|
|
|
@ -2,6 +2,7 @@ package com.example.aitest.service.impl;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.example.aitest.controller.websocket.WebSocketServer;
|
||||||
import com.example.aitest.service.ApiService;
|
import com.example.aitest.service.ApiService;
|
||||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||||
import org.apache.http.client.methods.HttpPost;
|
import org.apache.http.client.methods.HttpPost;
|
||||||
|
@ -31,7 +32,7 @@ public class ApiServiceImpl implements ApiService {
|
||||||
// 构建请求体
|
// 构建请求体
|
||||||
JSONObject content = new JSONObject();
|
JSONObject content = new JSONObject();
|
||||||
content.put("type", "text");
|
content.put("type", "text");
|
||||||
content.put("text", "请你对该图片的人物行为进行分析");
|
content.put("text", "你现在是一个带有警报系统的人类安全分析监控,只分析我上传的图片中的人物的动作、神态、在做什么?是否有生命危险,判断后给出警报等级:一级警报、二级警报、三级警报。在你的回答的最后,需要有一个括号,括号中包含判断出的警报等级");
|
||||||
|
|
||||||
JSONObject imageContent = new JSONObject();
|
JSONObject imageContent = new JSONObject();
|
||||||
imageContent.put("type", "image_url");
|
imageContent.put("type", "image_url");
|
||||||
|
@ -63,6 +64,16 @@ public class ApiServiceImpl implements ApiService {
|
||||||
JSONObject jsonResponse = JSON.parseObject(responseBody);
|
JSONObject jsonResponse = JSON.parseObject(responseBody);
|
||||||
jsonResponse.put("imgUrl", imageFile.getName());
|
jsonResponse.put("imgUrl", imageFile.getName());
|
||||||
System.out.println(jsonResponse.toJSONString());
|
System.out.println(jsonResponse.toJSONString());
|
||||||
|
if (jsonResponse.toJSONString().contains("一级警报")) {
|
||||||
|
WebSocketServer.sendAllSession("一级");
|
||||||
|
jsonResponse.put("grade", "一级");
|
||||||
|
} else if (jsonResponse.toJSONString().contains("二级警报")) {
|
||||||
|
WebSocketServer.sendAllSession("二级");
|
||||||
|
jsonResponse.put("grade", "二级");
|
||||||
|
} else {
|
||||||
|
WebSocketServer.sendAllSession("三级");
|
||||||
|
jsonResponse.put("grade", "三级");
|
||||||
|
}
|
||||||
return jsonResponse;
|
return jsonResponse;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|
|
@ -2,11 +2,9 @@ spring:
|
||||||
application:
|
application:
|
||||||
name: AITest
|
name: AITest
|
||||||
redis:
|
redis:
|
||||||
|
|
||||||
port: 6379
|
port: 6379
|
||||||
# password: ob666666
|
|
||||||
host: 49.233.248.140
|
|
||||||
password: aB3cDeF9
|
password: aB3cDeF9
|
||||||
|
host: 49.233.248.140
|
||||||
datasource:
|
datasource:
|
||||||
username: root
|
username: root
|
||||||
password: 3534957771fb4925
|
password: 3534957771fb4925
|
||||||
|
|
|
@ -18,19 +18,19 @@ class AiTestApplicationTests {
|
||||||
private static final String API_SECRET_KEY = "sk-zk23dcb27bb18e67d9ea0d749ed62f8088a667936c4c0682";
|
private static final String API_SECRET_KEY = "sk-zk23dcb27bb18e67d9ea0d749ed62f8088a667936c4c0682";
|
||||||
private static final String BASE_URL = "https://api.zhizengzeng.com/v1/chat/completions";
|
private static final String BASE_URL = "https://api.zhizengzeng.com/v1/chat/completions";
|
||||||
|
|
||||||
@Test
|
// @Test
|
||||||
void contextLoads() {
|
void contextLoads() {
|
||||||
CloseableHttpClient httpClient = HttpClients.createDefault();
|
CloseableHttpClient httpClient = HttpClients.createDefault();
|
||||||
System.out.println("进入processImage");
|
System.out.println("进入processImage");
|
||||||
// 构建请求体
|
// 构建请求体
|
||||||
JSONObject content = new JSONObject();
|
JSONObject content = new JSONObject();
|
||||||
content.put("type", "text");
|
content.put("type", "text");
|
||||||
content.put("text", "请你对该图片的人物行为进行分析");
|
content.put("text", "你现在是一个带有警报系统的人类安全分析监控,只分析我上传的图片中的人物的动作、神态、在做什么?是否有生命危险,判断后给出警报等级:一级警报、二级警报、三级警报。在你的回答的最后,需要有一个括号,括号中包含判断出的警报等级");
|
||||||
|
|
||||||
JSONObject imageContent = new JSONObject();
|
JSONObject imageContent = new JSONObject();
|
||||||
imageContent.put("type", "image_url");
|
imageContent.put("type", "image_url");
|
||||||
JSONObject imageUrl = new JSONObject();
|
JSONObject imageUrl = new JSONObject();
|
||||||
imageUrl.put("url", "http://124.71.135.249:8081/images/avatar/1718618415826.jpg");
|
imageUrl.put("url", "http://49.233.248.140:8081/images/1720169434341.jpg");
|
||||||
imageContent.put("image_url", imageUrl);
|
imageContent.put("image_url", imageUrl);
|
||||||
|
|
||||||
JSONObject message = new JSONObject();
|
JSONObject message = new JSONObject();
|
||||||
|
@ -40,7 +40,7 @@ class AiTestApplicationTests {
|
||||||
JSONObject requestBodyJson = new JSONObject();
|
JSONObject requestBodyJson = new JSONObject();
|
||||||
requestBodyJson.put("model", "gpt-4o");
|
requestBodyJson.put("model", "gpt-4o");
|
||||||
requestBodyJson.put("messages", new JSONObject[]{message});
|
requestBodyJson.put("messages", new JSONObject[]{message});
|
||||||
requestBodyJson.put("max_tokens", 300);
|
requestBodyJson.put("max_tokens", 100);
|
||||||
|
|
||||||
StringEntity requestEntity = new StringEntity(requestBodyJson.toJSONString(), ContentType.APPLICATION_JSON);
|
StringEntity requestEntity = new StringEntity(requestBodyJson.toJSONString(), ContentType.APPLICATION_JSON);
|
||||||
|
|
||||||
|
@ -55,6 +55,7 @@ class AiTestApplicationTests {
|
||||||
// Parse the JSON response
|
// Parse the JSON response
|
||||||
String responseBody = new String(response.getEntity().getContent().readAllBytes());
|
String responseBody = new String(response.getEntity().getContent().readAllBytes());
|
||||||
JSONObject jsonResponse = JSON.parseObject(responseBody);
|
JSONObject jsonResponse = JSON.parseObject(responseBody);
|
||||||
|
System.out.println(jsonResponse.toJSONString());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@ import java.security.NoSuchAlgorithmException;
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
public class MD5Test {
|
public class MD5Test {
|
||||||
|
|
||||||
@Test
|
// @Test
|
||||||
public void test() throws NoSuchAlgorithmException {
|
public void test() throws NoSuchAlgorithmException {
|
||||||
MessageDigest md5 = MessageDigest.getInstance("MD5");
|
MessageDigest md5 = MessageDigest.getInstance("MD5");
|
||||||
md5.update("ob666666".getBytes());
|
md5.update("ob666666".getBytes());
|
||||||
|
|
|
@ -6,7 +6,7 @@ import org.springframework.boot.test.context.SpringBootTest;
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
public class WebsocketTest {
|
public class WebsocketTest {
|
||||||
|
|
||||||
@Test
|
// @Test
|
||||||
public void test() {
|
public void test() {
|
||||||
System.out.println("Test");
|
System.out.println("Test");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue