Files

1 line
5.4 KiB
JSON

{"repo": "bronyazk/notebook", "files": {"noteapp-backend/src/main/java/com/example/project/service/llm/DeepSeekHttpClient.java": {"fa524da97840ecf57309191011eeadb772ffb5fd": {"t": 1785746125.9609902, "n": 2934, "h": "d8dc668597bf581f", "c": "package com.example.project.service.llm;\n\nimport lombok.RequiredArgsConstructor;\nimport org.springframework.http.MediaType;\nimport org.springframework.stereotype.Component;\nimport org.springframework.web.client.RestClient;\nimport org.springframework.web.client.RestClientResponseException;\nimport com.example.project.common.ex.BusinessException;\n\nimport java.util.HashMap;\nimport java.util.List;\nimport java.util.Map;\n\n@Component\n@RequiredArgsConstructor\npublic class DeepSeekHttpClient implements DeepSeekClient {\n\n private final DeepSeekProperties properties;\n private final RestClient restClient = RestClient.create();\n\n @Override\n public String summarize(String prompt) {\n String url = properties.getBaseUrl();\n if (url == null || url.isBlank()) {\n url = \"https://api.deepseek.com/v1/chat/completions\";\n }\n\n Map<String, Object> message = new HashMap<>();\n message.put(\"role\", \"user\");\n message.put(\"content\", prompt);\n\n Map<String, Object> body = new HashMap<>();\n body.put(\"model\", properties.getModel());\n body.put(\"messages\", List.of(message));\n body.put(\"temperature\", 0.2);\n\n Map<?, ?> response;\n try {\n RestClient.RequestBodySpec requestSpec = restClient.post()\n .uri(url)\n .contentType(MediaType.APPLICATION_JSON);\n if (properties.getApiKey() != null && !properties.getApiKey().isEmpty()) {\n requestSpec = requestSpec.header(\"Authorization\", \"Bearer \" + properties.getApiKey())\n .header(\"X-API-Key\", properties.getApiKey());\n }\n response = requestSpec\n .body(body)\n .retrieve()\n .body(Map.class);\n } catch (RestClientResponseException e) {\n int status = e.getRawStatusCode();\n String bodyText = e.getResponseBodyAsString();\n if (status == 401) {\n throw new BusinessException(\"DeepSeek 认证失败,请检查 API Key 是否正确或是否有访问权限\");\n }\n String msg = \"DeepSeek HTTP错误: status=\" + status + \", body=\" + bodyText;\n throw new RuntimeException(msg, e);\n }\n\n try {\n List<?> choices = (List<?>) response.get(\"choices\");\n if (choices != null && !choices.isEmpty()) {\n Object first = choices.get(0);\n if (first instanceof Map<?, ?> firstMap) {\n Object messageObj = firstMap.get(\"message\");\n if (messageObj instanceof Map<?, ?> msgMap) {\n Object content = msgMap.get(\"content\");\n if (content != null) {\n return content.toString().trim();\n }\n }\n }\n }\n } catch (Exception ignored) {}\n\n return \"提炼失败,未获取到有效结果\";\n }\n}\n\n\n"}}, "noteapp-backend/target/classes/application.yml": {"fa524da97840ecf57309191011eeadb772ffb5fd": {"t": 1785746945.1894464, "n": 798, "h": "37e394dfdf82a26a", "c": "spring:\n datasource:\n url: jdbc:mysql://localhost:3306/demo?useSSL=true&serverTimezone=UTC&characterEncoding=utf8&allowPublicKeyRetrieval=true\n username: root\n password: 123456\n jackson:\n serialization:\n WRITE_DATES_AS_TIMESTAMPS: false\n\nserver:\n port: 8080\n\nspringdoc:\n swagger-ui:\n path: /swagger-ui.html # Swagger UI 访问路径\n tags-sorter: alpha # 按字母顺序排序标签\n operations-sorter: alpha # 按字母顺序排序接口\n api-docs:\n path: /v3/api-docs # OpenAPI 文档的 JSON 路径\n default-produces-media-type: application/json # 默认响应类型\n default-consumes-media-type: application/json # 默认请求类型\n\n# DeepSeek 配置(OpenAI 兼容接口)\ndeepseek:\n base-url: \"https://api.deepseek.com/v1/chat/completions\"\n api-key: \"${DEEPSEEK_API_KEY:sk-64ba3bd1e1b04331a066c331f6c6aab6}\"\n model: \"deepseek-chat\"\n"}}, "noteapp-backend/src/main/resources/application.yml": {"fa524da97840ecf57309191011eeadb772ffb5fd": {"t": 1785746953.439744, "n": 798, "h": "37e394dfdf82a26a", "c": "spring:\n datasource:\n url: jdbc:mysql://localhost:3306/demo?useSSL=true&serverTimezone=UTC&characterEncoding=utf8&allowPublicKeyRetrieval=true\n username: root\n password: 123456\n jackson:\n serialization:\n WRITE_DATES_AS_TIMESTAMPS: false\n\nserver:\n port: 8080\n\nspringdoc:\n swagger-ui:\n path: /swagger-ui.html # Swagger UI 访问路径\n tags-sorter: alpha # 按字母顺序排序标签\n operations-sorter: alpha # 按字母顺序排序接口\n api-docs:\n path: /v3/api-docs # OpenAPI 文档的 JSON 路径\n default-produces-media-type: application/json # 默认响应类型\n default-consumes-media-type: application/json # 默认请求类型\n\n# DeepSeek 配置(OpenAI 兼容接口)\ndeepseek:\n base-url: \"https://api.deepseek.com/v1/chat/completions\"\n api-key: \"${DEEPSEEK_API_KEY:sk-64ba3bd1e1b04331a066c331f6c6aab6}\"\n model: \"deepseek-chat\"\n"}}}}