diff --git a/README.en.md b/README.en.md deleted file mode 100644 index 204dcfc..0000000 --- a/README.en.md +++ /dev/null @@ -1,38 +0,0 @@ -# EasyDeepSeek - -#### Description -DeepSeek 是一个基于 Java 后端和 HTML 前端的简单对话系统,旨在模拟基本的人机交互。该项目采用 Java 语言实现服务端逻辑,通过 HTTP 请求实现前后端的简单数据交互,前端部分由 HTML 构建,完成用户界面的展示和输入交互。 - -这是一个轻量级入门项目,适合用于学习前后端交互的基础知识,或者作为更复杂系统开发的起点。 - -#### Software Architecture -Software architecture description - -#### Installation - -1. xxxx -2. xxxx -3. xxxx - -#### Instructions - -1. xxxx -2. xxxx -3. xxxx - -#### Contribution - -1. Fork the repository -2. Create Feat_xxx branch -3. Commit your code -4. Create Pull Request - - -#### Gitee Feature - -1. You can use Readme\_XXX.md to support different languages, such as Readme\_en.md, Readme\_zh.md -2. Gitee blog [blog.gitee.com](https://blog.gitee.com) -3. Explore open source project [https://gitee.com/explore](https://gitee.com/explore) -4. The most valuable open source project [GVP](https://gitee.com/gvp) -5. The manual of Gitee [https://gitee.com/help](https://gitee.com/help) -6. The most popular members [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/) diff --git a/README.md b/README.md deleted file mode 100644 index 88ddb34..0000000 --- a/README.md +++ /dev/null @@ -1,41 +0,0 @@ -项目特性: - -Java 后台: - -使用 Java 实现服务端接口,简洁高效。 -提供简单的 API,支持前端通过请求获取对话响应。 -可扩展性强,方便后续增加更多功能。 -HTML 前端: - -使用纯 HTML 构建用户界面,界面简洁,易于理解。 -支持用户输入消息并实时展示系统响应。 -与后端通过 AJAX 或简单表单请求进行交互。 -轻量级设计: - -代码结构简单,学习成本低。 -无需复杂配置,开箱即用。 - - -功能描述: - -用户可以通过前端页面输入对话内容。 -后端接收用户请求并返回响应文本(模拟对话)。 -响应结果实时展示在前端页面上。 - -部署方式: - -后端(Java): - -修改API_KEY 更正为你自己的deepseek key即可~ - -使用 Maven 构建项目。 -启动服务端程序(如通过 java -jar 或 IDE 运行)。 -前端(HTML): -html中修改correctPassword为访问密码~ -将 index.html 直接放置在浏览器中打开,或通过简单的 Web 服务器(如 Nginx 或本地 HTTP 服务)运行。 -确保前端与后端的 API 地址一致。 - - -![输入图片说明](img1737686325969.jpg) -![输入图片说明](img1737686388820.jpg) -![输入图片说明](img1737686454002.jpg) \ No newline at end of file diff --git a/img1737686325969.jpg b/img1737686325969.jpg deleted file mode 100644 index 59b2c6e..0000000 Binary files a/img1737686325969.jpg and /dev/null differ diff --git a/img1737686388820.jpg b/img1737686388820.jpg deleted file mode 100644 index b823a2f..0000000 Binary files a/img1737686388820.jpg and /dev/null differ diff --git a/img1737686454002.jpg b/img1737686454002.jpg deleted file mode 100644 index 1595e1f..0000000 Binary files a/img1737686454002.jpg and /dev/null differ diff --git a/pom.xml b/pom.xml index 5bd0335..eb8a0fa 100644 --- a/pom.xml +++ b/pom.xml @@ -5,8 +5,8 @@ sincon.laogao EasyDeepSeek 0.0.1-SNAPSHOT - aiDemoApi - aiDemoApi + EasyDeepSeek + EasyDeepSeek 1.8 UTF-8 diff --git a/src/main/java/sincon/laogao/deepseek/config/CorsConfig.java b/src/main/java/sincon/laogao/deepseek/config/CorsConfig.java index fb5b8ce..2e13e42 100644 --- a/src/main/java/sincon/laogao/deepseek/config/CorsConfig.java +++ b/src/main/java/sincon/laogao/deepseek/config/CorsConfig.java @@ -1,9 +1,13 @@ package sincon.laogao.deepseek.config; +import org.apache.tomcat.util.http.fileupload.FileUtils; import org.springframework.context.annotation.Configuration; import org.springframework.web.servlet.config.annotation.CorsRegistry; +import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; +import java.net.URL; + @Configuration public class CorsConfig implements WebMvcConfigurer { @Override @@ -15,4 +19,16 @@ public class CorsConfig implements WebMvcConfigurer { .allowCredentials(true) .maxAge(3600); } + + /** + * 静态资源映射 + */ + @Override + public void addResourceHandlers(ResourceHandlerRegistry registry) { + ClassLoader classLoader = FileUtils.class.getClassLoader(); + URL url = classLoader.getResource(""); + String path = url.getPath(); + path = path.replace("/target/classes/", "/src/main/resources/static/dpskimg/"); + registry.addResourceHandler("/ai/**").addResourceLocations("file:" + path); + } } \ No newline at end of file diff --git a/src/main/java/sincon/laogao/deepseek/controller/easyAiController.java b/src/main/java/sincon/laogao/deepseek/controller/easyAiController.java deleted file mode 100644 index a7c6451..0000000 --- a/src/main/java/sincon/laogao/deepseek/controller/easyAiController.java +++ /dev/null @@ -1,85 +0,0 @@ -package sincon.laogao.deepseek.controller; - -import okhttp3.MediaType; -import okhttp3.OkHttpClient; -import okhttp3.Request; -import okhttp3.Response; -import okhttp3.ResponseBody; -import org.json.JSONArray; -import org.json.JSONObject; -import org.springframework.web.bind.annotation.*; - -import java.io.IOException; -import java.util.concurrent.TimeUnit; - -@RestController -@RequestMapping("/ai") -public class easyAiController { - private static final String API_KEY = "sk-2d525ebc32ba41cd8e57064332480226"; - private static final String BASE_URL = "https://api.deepseek.com"; - private static final OkHttpClient client = new OkHttpClient.Builder() - .connectTimeout(30, TimeUnit.SECONDS) - .readTimeout(30, TimeUnit.SECONDS) - .writeTimeout(30, TimeUnit.SECONDS) - .build(); - - - @PostMapping("/msg") - public String createEvent(@RequestBody String req) { - String response = ""; - try { - response = createChatCompletion(false,req); - } catch (IOException e) { - e.printStackTrace(); - } catch (Exception e) { - throw new RuntimeException(e); - } - - return response; - } - private static String createChatCompletion(boolean streamFlag, String next) throws Exception { - - String url = BASE_URL + "/v1/chat/completions"; - - JSONArray messages = new JSONArray() - .put(new JSONObject().put("role", "system").put("content", ",你是一名我的世界资深技术,你参与过mojang我的世界开发," + - "也自己搭建过我的世界java服务器,同时熟悉所有MineCraft的插件,并能准确的识别报错和提供指导,希望你准确无误的回答我的问题," + - "并且不能回复超过500字!")) -// .put(new JSONObject().put("role", "user").put("content", "Hello! How can I assist you today? \uD83D\uDE0A")); - .put(new JSONObject().put("role", "user").put("content", next)); - - JSONObject jsonBody = new JSONObject() - .put("model", "deepseek-chat") - .put("messages", messages) - .put("stream", streamFlag); - - okhttp3.RequestBody body = okhttp3.RequestBody.create( - jsonBody.toString(), - MediaType.get("application/json; charset=utf-8") - ); - - Request request = new Request.Builder() - .url(url) - .header("Authorization", "Bearer " + API_KEY) - .post(body) - .build(); - Response response = client.newCall(request).execute(); - if(!streamFlag) { - if (!response.isSuccessful()) throw new IOException("Unexpected code " + response); - - ResponseBody responseBody = response.body(); - if (responseBody != null) { - JSONObject jsonResponse = new JSONObject(responseBody.string()); - return jsonResponse.getJSONArray("choices") - .getJSONObject(0) - .getJSONObject("message") - .getString("content"); - } - }else{ - - } - - return null; - } - -} diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml new file mode 100644 index 0000000..2f8ec9b --- /dev/null +++ b/src/main/resources/application.yml @@ -0,0 +1,3 @@ +deepseek: + key: sk-06507623fbc + url: https://api.deepseek.com/v1/chat/completions \ No newline at end of file diff --git a/src/test/java/sincon/laogao/deepseek/EasyDeepSeekApplicationTests.java b/src/test/java/sincon/laogao/deepseek/EasyDeepSeekApplicationTests.java deleted file mode 100644 index 86e268e..0000000 --- a/src/test/java/sincon/laogao/deepseek/EasyDeepSeekApplicationTests.java +++ /dev/null @@ -1,13 +0,0 @@ -package sincon.laogao.deepseek; - -import org.junit.jupiter.api.Test; -import org.springframework.boot.test.context.SpringBootTest; - -@SpringBootTest -class EasyDeepSeekApplicationTests { - - @Test - void contextLoads() { - } - -} diff --git a/static/index.html b/static/index.html index 7f7e435..ba072d6 100644 --- a/static/index.html +++ b/static/index.html @@ -137,7 +137,7 @@ font-size: 14px; line-height: 1.5; display: inline-block; - max-width: 70%; + max-width: 90%; word-break: break-word; } @@ -382,7 +382,7 @@