parent
d7425679a2
commit
5004788c89
Binary file not shown.
@ -1,81 +0,0 @@
|
|||||||
package com.dsideal.Res.Util;
|
|
||||||
|
|
||||||
import cn.hutool.http.HttpRequest;
|
|
||||||
import cn.hutool.http.HttpResponse;
|
|
||||||
import cn.hutool.json.JSONObject;
|
|
||||||
import cn.hutool.json.JSONUtil;
|
|
||||||
|
|
||||||
public class CallDeepSeek {
|
|
||||||
private static final String API_KEY = "sk-44ae895eeb614aa1a9c6460579e322f1"; // 请替换为您的API KEY
|
|
||||||
private static final String API_URL = "https://api.deepseek.com/v1/chat/completions";
|
|
||||||
|
|
||||||
public static void callDeepSeekStream(String prompt, SSEListener listener) {
|
|
||||||
new Thread(() -> {
|
|
||||||
try {
|
|
||||||
JSONObject json = new JSONObject();
|
|
||||||
json.set("model", "deepseek-chat");
|
|
||||||
json.set("messages", JSONUtil.parseArray(
|
|
||||||
"[{\"role\":\"user\",\"content\":\"" + prompt + "\"}]"
|
|
||||||
));
|
|
||||||
json.set("stream", true); // 启用流式响应
|
|
||||||
|
|
||||||
HttpRequest request = HttpRequest.post(API_URL)
|
|
||||||
.header("Content-Type", "application/json")
|
|
||||||
.header("Authorization", "Bearer " + API_KEY)
|
|
||||||
.header("Accept", "text/event-stream") // SSE支持
|
|
||||||
.body(json.toString());
|
|
||||||
|
|
||||||
HttpResponse response = request.execute();
|
|
||||||
if (response.isOk()) {
|
|
||||||
// 处理流式响应
|
|
||||||
String[] lines = response.body().split("\\r?\\n");
|
|
||||||
for (String line : lines) {
|
|
||||||
if (line.startsWith("data:")) {
|
|
||||||
String data = line.substring(5).trim();
|
|
||||||
if (!data.equals("[DONE]")) {
|
|
||||||
listener.onData(data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
listener.onComplete();
|
|
||||||
} else {
|
|
||||||
listener.onError("API请求失败: " + response.getStatus());
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
listener.onError(e.getMessage());
|
|
||||||
}
|
|
||||||
}).start();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
callDeepSeekStream("你好", new SSEListener() {
|
|
||||||
@Override
|
|
||||||
public void onData(String data) {
|
|
||||||
System.out.println("收到数据: " + data);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onComplete() {
|
|
||||||
System.out.println("流式传输完成");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onError(String error) {
|
|
||||||
System.err.println("错误: " + error);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// 保持主线程运行
|
|
||||||
try {
|
|
||||||
Thread.sleep(30000); // 等待30秒
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public interface SSEListener {
|
|
||||||
void onData(String data);
|
|
||||||
void onComplete();
|
|
||||||
void onError(String error);
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,2 @@
|
|||||||
|
select tsl.person_id,tsl.person_name,tsl.mz,tdm.mz_name,tsl.xb,tdx.xb_name from t_sys_loginperson as tsl inner join t_dm_mz as tdm on tsl.mz=tdm.mz_id
|
||||||
|
inner join t_dm_xb as tdx on tsl.xb=tdx.xb_id
|
@ -0,0 +1,2 @@
|
|||||||
|
select tsl.person_id,tsl.person_name,tsl.mz,tdm.mz_name,tsl.xb,tdx.xb_name from t_sys_loginperson as tsl inner join t_dm_mz as tdm on tsl.mz=tdm.mz_id
|
||||||
|
inner join t_dm_xb as tdx on tsl.xb=tdx.xb_id
|
Loading…
Reference in new issue