废话不多说,直接上演示图:
可以使用下载离线安装包,安装速度快:
https://lingma.aliyun.com/lingma/download
我的IntelliJ IDEA 是社区版:
https://www.jetbrains.com.cn/idea/download/download-thanks.html
--------------------------------------------------------
PS1: JFinal 项目中 调用 DeepSeek 大模型:
<dependency> <groupId>io.github.pig-mesh.ai</groupId> <artifactId>deepseek4j-core</artifactId> <version>1.4.3</version> </dependency>
public static void main(String[] args) { DeepSeekClient.Builder conf = DeepSeekClient.builder(); conf.baseUrl = "https://ai.gitee.com/v1/"; conf.model = "DeepSeek-R1"; //https://ai.gitee.com/serverless-api?model=DeepSeek-R1 conf.openAiApiKey = "登录自己码云上面链接里获取令牌,粘贴到这里"; DeepSeekClient client = conf.build(); Flux<ChatCompletionResponse> flux = client.chatFluxCompletion("你好 deepseek"); // 订阅并打印每个 ChatCompletionResponse 对象。 flux.subscribe(System.out::println); // JF Controller 里面可使用Sse实现打字效果。 // SseEmitter sseEmitter = new SseEmitter(getResponse()); // sseEmitter.sendMessage(data); // sseEmitter.complete(); // renderNull(); }
------------
PS2 :简单http请求返回结果的:
private static String send() { String jsonInputString = """ { "model": "deepseek-chat", "messages": [ {"role": "user", "content": "给我1句励志语句,不要返回其他内容。"} ], "stream": false }"""; try (HttpClient httpClient = HttpClient.newHttpClient()) { HttpRequest request = HttpRequest.newBuilder() .uri(URI.create("https://api.deepseek.com/chat/completions")) .header("Content-Type", "application/json") .header("Authorization", "Bearer " + AppConfig.getOpenAiApiKey()) .POST(HttpRequest.BodyPublishers.ofString(jsonInputString, StandardCharsets.UTF_8)) .build(); HttpResponse<String> response = httpClient.send(request, HttpResponse.BodyHandlers.ofString()); if (response.statusCode() == 200) { String body = response.body(); String content = JSONUtil.parseObj(body).getJSONArray("choices").getJSONObject(0) .getJSONObject("message").getStr("content"); return content.trim(); } } catch (Exception e) { e.printStackTrace(); } return ""; }