This commit is contained in:
tangzh 2025-04-24 20:11:59 +08:00
parent d05fd60438
commit 8ab0fc242e
11 changed files with 37 additions and 202 deletions

View File

@ -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/)

View File

@ -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)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 521 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 168 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 146 KiB

View File

@ -5,8 +5,8 @@
<groupId>sincon.laogao</groupId> <groupId>sincon.laogao</groupId>
<artifactId>EasyDeepSeek</artifactId> <artifactId>EasyDeepSeek</artifactId>
<version>0.0.1-SNAPSHOT</version> <version>0.0.1-SNAPSHOT</version>
<name>aiDemoApi</name> <name>EasyDeepSeek</name>
<description>aiDemoApi</description> <description>EasyDeepSeek</description>
<properties> <properties>
<java.version>1.8</java.version> <java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

View File

@ -1,9 +1,13 @@
package sincon.laogao.deepseek.config; package sincon.laogao.deepseek.config;
import org.apache.tomcat.util.http.fileupload.FileUtils;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry; 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 org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import java.net.URL;
@Configuration @Configuration
public class CorsConfig implements WebMvcConfigurer { public class CorsConfig implements WebMvcConfigurer {
@Override @Override
@ -15,4 +19,16 @@ public class CorsConfig implements WebMvcConfigurer {
.allowCredentials(true) .allowCredentials(true)
.maxAge(3600); .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);
}
} }

View File

@ -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;
}
}

View File

@ -0,0 +1,3 @@
deepseek:
key: sk-06507623fbc
url: https://api.deepseek.com/v1/chat/completions

View File

@ -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() {
}
}

View File

@ -137,7 +137,7 @@
font-size: 14px; font-size: 14px;
line-height: 1.5; line-height: 1.5;
display: inline-block; display: inline-block;
max-width: 70%; max-width: 90%;
word-break: break-word; word-break: break-word;
} }
@ -382,7 +382,7 @@
<!-- 登录遮罩层 --> <!-- 登录遮罩层 -->
<div class="login-overlay" id="loginOverlay"> <div class="login-overlay" id="loginOverlay">
<div class="login-container"> <div class="login-container">
<img src="http://tc.mcshare.cn/LightPicture/2025/01/dfcd0cc85c45a6af.png" alt="Logo" class="login-logo"> <img src="http://localhost:8080/dpskimg/logo.png" alt="Logo" class="login-logo">
<input type="password" class="login-input" id="passwordInput" placeholder="请输入访问密码" autocomplete="off"> <input type="password" class="login-input" id="passwordInput" placeholder="请输入访问密码" autocomplete="off">
<button class="login-button" id="loginButton">进入系统</button> <button class="login-button" id="loginButton">进入系统</button>
<div class="login-error" id="loginError">密码错误,请重试</div> <div class="login-error" id="loginError">密码错误,请重试</div>
@ -395,21 +395,17 @@
<div class="chat-container"> <div class="chat-container">
<div class="chat-header"> <div class="chat-header">
<img src="http://tc.mcshare.cn/LightPicture/2025/01/dfcd0cc85c45a6af.png" alt="Logo" class="chat-logo"> <img src="http://localhost:8080/dpskimg/logo.png" alt="Logo" class="chat-logo">
</div> </div>
<div class="chat-sidebar"> <div class="chat-sidebar">
<div class="hot-topic"> <div class="hot-topic">
<div class="hot-topic-title">🔥 cmi插件如何使用</div> <div class="hot-topic-title">🔥 idea软件如何使用?</div>
<div class="hot-topic-desc">AI助手教你cmi插件如何使用</div> <div class="hot-topic-desc">将教会您如何使用idea软件</div>
</div> </div>
<div class="hot-topic"> <div class="hot-topic">
<div class="hot-topic-title">📚 ess插件如何使用?</div> <div class="hot-topic-title">💡 什么是JAVA</div>
<div class="hot-topic-desc">将教会您如何使用ess插件</div> <div class="hot-topic-desc">对JAVA进行详解</div>
</div>
<div class="hot-topic">
<div class="hot-topic-title">💡 什么是VPS</div>
<div class="hot-topic-desc">对VPS进行详解</div>
</div> </div>
<div class="hot-topic"> <div class="hot-topic">
<div class="hot-topic-title">🌟 如何搭建一个基础服务端?</div> <div class="hot-topic-title">🌟 如何搭建一个基础服务端?</div>
@ -419,19 +415,17 @@
<div class="hot-topic-title">🔍 我的世界宝可梦模组攻略?</div> <div class="hot-topic-title">🔍 我的世界宝可梦模组攻略?</div>
<div class="hot-topic-desc">我的世界宝可梦科普解读</div> <div class="hot-topic-desc">我的世界宝可梦科普解读</div>
</div> </div>
</div> </div>
<div class="chat-messages" id="chatMessages"> <div class="chat-messages" id="chatMessages">
<div class="message ai-message"> <div class="message ai-message">
<div class="message-avatar"> <div class="message-avatar">
<img src="http://tc.mcshare.cn/LightPicture/2025/01/b9243274f819f28b.jpg" alt="AI" style="width: 100%; height: 100%; border-radius: 50%;"> <img src="http://localhost:8080/dpskimg/ai.png" alt="AI" style="width: 100%; height: 100%; border-radius: 50%;">
</div> </div>
<div> <div>
<div class="message-name">恭喜智能AI - 征途下士</div> <div class="message-name">智能AI - 小橙橙</div>
<div class="message-content"> <div class="message-content">
<p> 您好!我是华欣云AI助手。</p> <p> 您好!我是小橙橙AI助手。</p>
<p style="margin-top: 8px;">我可以帮您:</p> <p style="margin-top: 8px;">我可以帮您:</p>
<ul style="margin: 8px 0 0 20px;"> <ul style="margin: 8px 0 0 20px;">
<li>解决简单报错</li> <li>解决简单报错</li>
@ -439,7 +433,7 @@
<li>提供编程帮助</li> <li>提供编程帮助</li>
<li>甚至您可以让我给您进行插件的基础问题解答.</li> <li>甚至您可以让我给您进行插件的基础问题解答.</li>
</ul> </ul>
<p style="margin-top: 8px;">感谢您对华欣云的支持,祝您生活愉快!</p> <p style="margin-top: 8px;">感谢您的支持,祝您生活愉快!</p>
</div> </div>
</div> </div>
</div> </div>
@ -468,13 +462,13 @@
messageDiv.innerHTML = ` messageDiv.innerHTML = `
<div class="message-avatar"> <div class="message-avatar">
${isUser ? ${isUser ?
'<img src="https://api.dicebear.com/7.x/avataaars/svg?seed=user" alt="用户" style="width: 100%; height: 100%; border-radius: 50%;">' : '<img src="http://localhost:8080/dpskimg/user.png" alt="用户" style="width: 100%; height: 100%; border-radius: 50%;">' :
'<img src="http://tc.mcshare.cn/LightPicture/2025/01/b9243274f819f28b.jpg" alt="AI" style="width: 100%; height: 100%; border-radius: 50%;">' '<img src="http://localhost:8080/dpskimg/ai.png" alt="AI" style="width: 100%; height: 100%; border-radius: 50%;">'
} }
</div> </div>
<div> <div>
<div class="message-name"> <div class="message-name">
${isUser ? '恭喜娱乐客户' : '恭喜智能AI - 征途下士'} ${isUser ? '客户' : '智能AI - 小橙橙'}
</div> </div>
<div class="message-content"> <div class="message-content">
${content} ${content}
@ -503,12 +497,11 @@
loadingMessage.className = 'message ai-message'; loadingMessage.className = 'message ai-message';
loadingMessage.innerHTML = ` loadingMessage.innerHTML = `
<div class="message-avatar"> <div class="message-avatar">
<img src="http://tc.mcshare.cn/LightPicture/2025/01/b9243274f819f28b.jpg" alt="AI" style="width: 100%; height: 100%; border-radius: 50%;"> <img src="http://localhost:8080/dpskimg/ai.png" alt="AI" style="width: 100%; height: 100%; border-radius: 50%;">
</div> </div>
<div> <div>
<div class="message-name">恭喜智能AI - 征途下士</div> <div class="message-name">智能AI - 小橙橙</div>
<div class="message-content"> <div class="message-content">
<p>索引中..</p>
<p>请稍等..</p> <p>请稍等..</p>
</div> </div>
</div> </div>