소스 수정
This commit is contained in:
@@ -25,13 +25,19 @@ public class ToolResponseGuardrailService {
|
||||
public String validateAndWrap(ToolMetadata metadata, String requestId, JsonNode data) {
|
||||
validateData(metadata.getName(), data);
|
||||
|
||||
ObjectNode response = json.createObjectNode();
|
||||
response.put("success", true);
|
||||
response.put("toolName", metadata.getName());
|
||||
response.put("requestId", requestId);
|
||||
response.put("source", "registered-tool-server");
|
||||
response.set("data", data);
|
||||
response.set("answerPolicy", answerPolicy());
|
||||
ObjectNode response;
|
||||
if (data.isObject() && data.has("success") && data.has("data")) {
|
||||
response = ((ObjectNode) data).deepCopy();
|
||||
response.set("answerPolicy", answerPolicy());
|
||||
} else {
|
||||
response = json.createObjectNode();
|
||||
response.put("success", true);
|
||||
response.put("toolName", metadata.getName());
|
||||
response.put("requestId", requestId);
|
||||
response.put("source", "registered-tool-server");
|
||||
response.set("data", data);
|
||||
response.set("answerPolicy", answerPolicy());
|
||||
}
|
||||
|
||||
try {
|
||||
return json.writerWithDefaultPrettyPrinter().writeValueAsString(response);
|
||||
|
||||
@@ -65,9 +65,18 @@ public class ChatController {
|
||||
error -> {
|
||||
log.error("[Real AI Chat] 스트리밍 중 에러 발생", error);
|
||||
try {
|
||||
emitter.send("\n[에러 발생: " + error.getMessage() + "]");
|
||||
String errorMsg = error.getMessage();
|
||||
if (errorMsg != null && (errorMsg.contains("timeout") || errorMsg.contains("OpenAIIoException"))) {
|
||||
emitter.send("\n\n⚠️ **요청 시간이 초과되었습니다.** (현재 여러 개의 도구를 분석하느라 모델의 응답이 지연되었습니다. 해당하는 도구가 없거나 너무 복잡한 요청일 수 있습니다.)");
|
||||
} else if (errorMsg != null && errorMsg.contains("503")) {
|
||||
emitter.send("\n\n⚠️ **AI 모델 서버 혼잡 (503)**: 현재 AI 모델을 제공하는 서버에 일시적으로 접속자가 많아 지연이 발생하고 있습니다. 잠시 후 다시 시도해 주세요.");
|
||||
} else if (errorMsg != null && errorMsg.contains("429")) {
|
||||
emitter.send("\n\n⚠️ **API 사용량 초과 (429)**: 현재 사용 중인 Gemini API(무료 티어)의 일일 또는 분당 요청 한도를 초과했습니다. 잠시 후 다시 시도하시거나 API 플랜을 확인해 주세요.");
|
||||
} else {
|
||||
emitter.send("\n[에러 발생: " + errorMsg + "]");
|
||||
}
|
||||
} catch (Exception ignore) {}
|
||||
emitter.completeWithError(error);
|
||||
emitter.complete(); // 클라이언트 측에서 네트워크 에러로 처리하지 않도록 정상 종료
|
||||
},
|
||||
() -> {
|
||||
log.info("[Real AI Chat] 스트리밍 완료");
|
||||
|
||||
@@ -73,13 +73,18 @@ public class McpRouterController {
|
||||
try {
|
||||
Object result = executeService.execute(payload, tenantId);
|
||||
|
||||
io.shinhanlife.axhub.biz.mcp.adapter.dto.JsonRpcResponse response = new io.shinhanlife.axhub.biz.mcp.adapter.dto.JsonRpcResponse();
|
||||
response.setJsonrpc("2.0");
|
||||
response.setId(payload.containsKey("id") ? String.valueOf(payload.get("id")) : UUID.randomUUID().toString());
|
||||
response.setResult(result);
|
||||
|
||||
try {
|
||||
log.info("[MCP Gateway -> Admin UI] 동적 툴 실행 결과 반환: {}", objectMapper.writeValueAsString(result));
|
||||
log.info("[MCP Gateway -> Admin UI] 동적 툴 실행 결과 반환: {}", objectMapper.writeValueAsString(response));
|
||||
} catch (Exception ex) {
|
||||
log.info("[MCP Gateway -> Admin UI] 동적 툴 실행 결과 반환: {}", result);
|
||||
log.info("[MCP Gateway -> Admin UI] 동적 툴 실행 결과 반환: {}", response);
|
||||
}
|
||||
|
||||
return ResponseEntity.ok(result);
|
||||
return ResponseEntity.ok(response);
|
||||
} catch (SecurityException se) {
|
||||
log.warn(" [보안 차단] 권한 오류: {}", se.getMessage());
|
||||
return ResponseEntity.status(403).body(Map.of("error", se.getMessage()));
|
||||
|
||||
@@ -138,9 +138,8 @@ public class ExecuteService {
|
||||
// Apply Output Guardrail
|
||||
String wrappedResponse = responseGuardrail.validateAndWrap(metadata, context.requestId(), (com.fasterxml.jackson.databind.JsonNode) result);
|
||||
|
||||
// Format the result
|
||||
ToolExecutionResult formattedResult = resultFormatter.fromRawResponse(metadata.getName(), wrappedResponse);
|
||||
result = formattedResult;
|
||||
// Format the result (Restore legacy raw format as Map/List for backward compatibility)
|
||||
result = objectMapper.readValue(wrappedResponse, Object.class);
|
||||
}
|
||||
|
||||
long elapsedMillis = elapsedMillis(startedAt);
|
||||
|
||||
@@ -42,7 +42,7 @@ mcp.max-response-bytes-from-tool=5242880
|
||||
mcp.tool-registry-sync-interval-millis=5000
|
||||
|
||||
# Spring AI OpenAI / Gemini API Config
|
||||
spring.ai.openai.api-key=AIzaSyB4fAgAjF9lL4CiiH4yMevD9qE6wMyWZO0
|
||||
spring.ai.openai.api-key=AQ.Ab8RN6KFZggsQf8iooY1v_3h3vp2TIjiYB54dV4Yay3vVKEMtg
|
||||
spring.ai.openai.base-url=https://generativelanguage.googleapis.com/v1beta/openai/
|
||||
spring.ai.openai.chat.options.model=gemini-flash-latest
|
||||
spring.ai.openai.chat.options.temperature=0.3
|
||||
|
||||
Reference in New Issue
Block a user