/
akadnikov
/
CMIS_agent_Java
Обзор
Документация
Войти
/
akadnikov
/
CMIS_agent_Java
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
src/main/java/com/example/cmisagent/CMISAgentController.java
186 строк
7 KB
akadnikov
Initial commit
25 фев 2026, 23:17
Верифицирован
25 фев 2026, 23:17
882add4
Код
Авторство
О чём код?
package com.example.cmisagent; import com.example.cmisagent.model.*; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.Data; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; import java.util.List; import java.util.Map; /** * REST API контроллер для CMIS AI агента. */ @Slf4j @RestController @RequestMapping("/api/v1/cmis") @RequiredArgsConstructor @Tag(name = "CMIS Agent", description = "AI агент для работы с CMIS документами") public class CMISAgentController { private final CMISAgent agent; private final VectorSearchService vectorSearchService; private final QueryAnalyzerService queryAnalyzer; private final CMISAgentConfig config; // ------------------------------------------------------------------------- // Search // ------------------------------------------------------------------------- @PostMapping("/search") @Operation(summary = "Поиск документов", description = "Интеллектуальный поиск документов на естественном языке") public ResponseEntity<AgentResponse> search(@RequestBody SearchRequest request) { log.info("Search request: {}", request.getQuery()); try { QueryAnalysis analysis = request.isUseAnalysis() ? queryAnalyzer.analyze(request.getQuery()) : null; String answer = agent.search(request.getQuery()); return ResponseEntity.ok(AgentResponse.builder() .answer(answer) .analysis(analysis) .build()); } catch (Exception e) { log.error("Error processing search request", e); return ResponseEntity.internalServerError() .body(AgentResponse.builder() .answer("Ошибка обработки запроса: " + e.getMessage()) .build()); } } @PostMapping("/search/structured") @Operation(summary = "Структурированный поиск по метаданным") public ResponseEntity<List<DocumentInfo>> structuredSearch(@RequestBody SearchCriteria criteria) { log.info("Structured search: {}", criteria); // реализация через CMISService return ResponseEntity.ok(List.of()); } @PostMapping("/search/semantic") @Operation(summary = "Семантический поиск по содержанию") public ResponseEntity<List<SemanticSearchResult>> semanticSearch( @RequestParam String query, @RequestParam(defaultValue = "5") int topK) { log.info("Semantic search: query='{}', topK={}", query, topK); return ResponseEntity.ok(vectorSearchService.search(query, topK)); } // ------------------------------------------------------------------------- // Documents // ------------------------------------------------------------------------- @GetMapping("/documents/{documentId}/metadata") @Operation(summary = "Метаданные документа") public ResponseEntity<DocumentMetadata> getMetadata(@PathVariable String documentId) { log.info("Get metadata: {}", documentId); return ResponseEntity.ok(DocumentMetadata.builder().build()); } @GetMapping("/documents/{documentId}/content") @Operation(summary = "Содержимое документа") public ResponseEntity<DocumentContent> getContent(@PathVariable String documentId) { log.info("Get content: {}", documentId); return ResponseEntity.ok(DocumentContent.builder().build()); } // ------------------------------------------------------------------------- // Indexing // ------------------------------------------------------------------------- @PostMapping("/index/document/{documentId}") @Operation(summary = "Индексировать документ") public ResponseEntity<Void> indexDocument(@PathVariable String documentId) { vectorSearchService.indexDocument(documentId); return ResponseEntity.ok().build(); } @PostMapping("/index/all") @Operation(summary = "Индексировать все документы") public ResponseEntity<Map<String, Object>> indexAll() { vectorSearchService.indexAllDocuments(); return ResponseEntity.ok(Map.of("status", "started")); } @PostMapping("/index/clear") @Operation(summary = "Очистить индекс") public ResponseEntity<Void> clearIndex() { vectorSearchService.clearIndex(); return ResponseEntity.ok().build(); } @GetMapping("/index/stats") @Operation(summary = "Статистика индекса") public ResponseEntity<Map<String, Object>> getIndexStats() { return ResponseEntity.ok(vectorSearchService.getIndexStats()); } // ------------------------------------------------------------------------- // Agent management // ------------------------------------------------------------------------- @PostMapping("/agent/clear-history") @Operation(summary = "Очистить историю разговора") public ResponseEntity<Void> clearHistory() { agent.clearHistory(); return ResponseEntity.ok().build(); } // ------------------------------------------------------------------------- // Provider info // ------------------------------------------------------------------------- @GetMapping("/provider") @Operation(summary = "Информация об активном LLM-провайдере", description = "Возвращает текущего провайдера и модель. " + "Для смены провайдера измените LLM_PROVIDER и перезапустите приложение.") public ResponseEntity<ProviderInfo> getProviderInfo() { String model = switch (config.getLlmProvider()) { case ANTHROPIC -> config.getAnthropicModel(); case OPENAI -> config.getOpenaiModel(); case GIGACHAT -> config.getGigachatModel(); }; return ResponseEntity.ok(ProviderInfo.builder() .provider(config.getLlmProvider().name()) .model(model) .build()); } // ------------------------------------------------------------------------- // Health // ------------------------------------------------------------------------- @GetMapping("/health") @Operation(summary = "Проверка работоспособности сервиса") public ResponseEntity<Map<String, String>> health() { return ResponseEntity.ok(Map.of("status", "healthy")); } // ------------------------------------------------------------------------- // DTOs // ------------------------------------------------------------------------- @Data public static class SearchRequest { private String query; private boolean useAnalysis = true; } @Data @lombok.Builder public static class ProviderInfo { private String provider; private String model; } }