Updated Display to wait for Ollama to return before continuing Updated GeniusTools.java to reflect correctly after "The Great Refector" Temporarly comented out things from API after making Ollama be more threaded pending correction and expantion
59 lines
2.5 KiB
Java
59 lines
2.5 KiB
Java
package me.neurodock.api.controllers;
|
|
|
|
import io.swagger.v3.oas.annotations.responses.ApiResponses;
|
|
import me.neurodock.api.APIApplication;
|
|
import me.neurodock.api.condations.EnableIfNotDisplay;
|
|
import me.neurodock.api.payload.request.NewQurryResponceHook;
|
|
import me.neurodock.ollama.OllamaMessage;
|
|
import me.neurodock.ollama.OllamaMessageRole;
|
|
import org.springframework.context.annotation.Conditional;
|
|
import org.springframework.http.ResponseEntity;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
@Conditional(EnableIfNotDisplay.class)
|
|
@RestController
|
|
@RequestMapping("/v1/message")
|
|
public class Message {
|
|
|
|
private final APIApplication apiApplication;
|
|
|
|
public Message(APIApplication apiApplication) {
|
|
this.apiApplication = apiApplication;
|
|
}
|
|
|
|
@GetMapping("/query")
|
|
public ResponseEntity<String> query(@RequestParam(name = "query", required = true) String query) {
|
|
if (query == null || query.isEmpty()) {
|
|
return ResponseEntity.badRequest().body("Query cannot be null or empty");
|
|
}
|
|
Thread t = new Thread(() -> {
|
|
apiApplication.getCore().getOllamaObject().addMessage(new OllamaMessage(OllamaMessageRole.USER, query));
|
|
//apiApplication.getCore().handleResponse(apiApplication.getCore().qurryOllama());
|
|
});
|
|
t.start();
|
|
return ResponseEntity.ok("Query received");
|
|
}
|
|
|
|
@PostMapping("/addResponseHook")
|
|
@ApiResponses(value = {
|
|
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "200", description = "Response hook added successfully"),
|
|
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "400", description = "Invalid request data"),
|
|
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "500", description = "Internal server error")
|
|
})
|
|
public ResponseEntity<String> addResponseHook(@RequestBody NewQurryResponceHook request) {
|
|
if (request.getUrl() == null || request.getUrl().isEmpty()) {
|
|
return ResponseEntity.badRequest().body("URL cannot be null or empty");
|
|
}
|
|
|
|
try {
|
|
apiApplication.addQurryResponseHook(request);
|
|
|
|
return ResponseEntity.ok("Response hook added successfully: " + request.getUrl());
|
|
}catch (IllegalArgumentException e) {
|
|
return ResponseEntity.badRequest().body("Invalid request data: " + e.getMessage());
|
|
} catch (Exception e) {
|
|
return ResponseEntity.status(500).body("Internal server error: " + e.getMessage());
|
|
}
|
|
}
|
|
}
|