|
@@ -1,5 +1,23 @@
|
|
|
+/*
|
|
|
+ * Project: LangChat
|
|
|
+ * Author: TyCoding
|
|
|
+ *
|
|
|
+ * Licensed under the GNU Affero General Public License, Version 3 (the "License");
|
|
|
+ * you may not use this file except in compliance with the License.
|
|
|
+ * You may obtain a copy of the License at
|
|
|
+ *
|
|
|
+ * https://www.gnu.org/licenses/agpl-3.0.html
|
|
|
+ *
|
|
|
+ * Unless required by applicable law or agreed to in writing, software
|
|
|
+ * distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
+ * See the License for the specific language governing permissions and
|
|
|
+ * limitations under the License.
|
|
|
+ */
|
|
|
+
|
|
|
package cn.tycoding.langchat.client.controller;
|
|
|
|
|
|
+import cn.hutool.core.lang.Dict;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import cn.tycoding.langchat.biz.entity.AigcOss;
|
|
|
import cn.tycoding.langchat.biz.service.AigcOssService;
|
|
@@ -16,14 +34,20 @@ import cn.tycoding.langchat.common.utils.R;
|
|
|
import cn.tycoding.langchat.common.utils.StreamEmitter;
|
|
|
import cn.tycoding.langchat.core.consts.ModelConst;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.http.MediaType;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
+import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyEmitter;
|
|
|
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
|
|
|
|
|
|
+import java.io.IOException;
|
|
|
+
|
|
|
/**
|
|
|
* @author tycoding
|
|
|
* @since 2024/1/30
|
|
|
*/
|
|
|
+@Slf4j
|
|
|
@RequestMapping("/client")
|
|
|
@RestController
|
|
|
@AllArgsConstructor
|
|
@@ -33,6 +57,32 @@ public class ClientChatEndpoint {
|
|
|
private final AigcOssService aigcOssService;
|
|
|
private final ClientEmbeddingService clientEmbeddingService;
|
|
|
|
|
|
+ @PostMapping("/test")
|
|
|
+ public Object test(@RequestBody Object obj) {
|
|
|
+ log.info("x: {}", obj);
|
|
|
+ return Dict.create().set("message", "你好呀").set("threadId", "111");
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/test2")
|
|
|
+ public Object test2(@RequestBody Object obj) throws InterruptedException, IOException {
|
|
|
+ log.info("Received: {}", obj);
|
|
|
+ ResponseBodyEmitter emitter = new ResponseBodyEmitter();
|
|
|
+
|
|
|
+ new Thread(() -> {
|
|
|
+ try {
|
|
|
+ for (int i = 0; i < 10; i++) {
|
|
|
+ emitter.send("Data: " + i + "\n", MediaType.TEXT_PLAIN);
|
|
|
+ Thread.sleep(1000);
|
|
|
+ }
|
|
|
+ emitter.complete();
|
|
|
+ } catch (Exception e) {
|
|
|
+ emitter.completeWithError(e);
|
|
|
+ }
|
|
|
+ }).start();
|
|
|
+
|
|
|
+ return emitter;
|
|
|
+ }
|
|
|
+
|
|
|
@ClientPerm
|
|
|
@PostMapping("/chat")
|
|
|
public Object chat(@RequestBody ChatReq req) {
|