chore: import upstream snapshot with attribution

This commit is contained in:
wehub-resource-sync
2026-07-13 13:31:35 +08:00
commit c275ba2868
13613 changed files with 2980806 additions and 0 deletions
@@ -0,0 +1,5 @@
# Server configuration
server.port=8087
# Application name
spring.application.name=ContentSafetyCalculator
Binary file not shown.

After

Width:  |  Height:  |  Size: 72 KiB

@@ -0,0 +1,40 @@
@startuml Content Safety Calculator Flow
!theme plain
title Content Safety Calculator - Sequence Diagram
actor User
participant "Web App" as WebApp
participant "Content Safety Service" as SafetyService
participant "Azure Content Safety API" as AzureAPI
participant "Bot" as Bot
participant "MCP Server" as McpServer
== User Input and Safety Flow ==
User -> WebApp: Submit calculation prompt
WebApp -> SafetyService: Process prompt
SafetyService -> AzureAPI: Check prompt safety
AzureAPI --> SafetyService: Safety result
alt Prompt is safe
SafetyService -> Bot: Process safe prompt
Bot -> McpServer: Execute calculation
McpServer --> Bot: Calculation result
Bot --> SafetyService: Bot response
SafetyService -> AzureAPI: Check response safety
AzureAPI --> SafetyService: Response safety result
alt Response is safe
SafetyService --> WebApp: Safe prompt and safe response
WebApp --> User: Display calculation and safety info
else Response is unsafe
SafetyService --> WebApp: Safe prompt but unsafe response
WebApp --> User: Display warning
end
else Prompt is unsafe
SafetyService --> WebApp: Unsafe prompt
WebApp --> User: Display warning
end
@enduml
@@ -0,0 +1,38 @@
```mermaid
sequenceDiagram
actor User
participant WebApp as Web App<br/>(ContentSafetyController)
participant SafetyService as Content Safety Service
participant AzureAPI as Azure Content Safety API
participant LangChain as LangChain4j
participant McpClient as MCP Client
participant McpServer as MCP Calculator Server<br/>(Port 8080)
participant CalcService as Calculator Service
%% User Interaction
User->>WebApp: Enter calculation prompt
WebApp->>WebApp: Create PromptRequest
%% Content Safety Check
WebApp->>SafetyService: processPrompt(prompt)
SafetyService->>AzureAPI: analyzeText(prompt)
AzureAPI-->>SafetyService: AnalyzeTextResult
SafetyService->>SafetyService: Check if content is safe<br/>(severity < 2 for all categories)
%% Processing Flow - Safe Content
alt Content is safe
SafetyService->>LangChain: Pass prompt to Bot.chat()
LangChain->>McpClient: Process prompt
McpClient->>McpServer: Call appropriate calculator tool via SSE
McpServer->>CalcService: Execute calculation<br/>(add, subtract, multiply, etc.)
CalcService-->>McpServer: Calculation result
McpServer-->>McpClient: Tool execution result
McpClient-->>LangChain: Tool result
LangChain-->>SafetyService: Bot response
SafetyService-->>WebApp: Return result map<br/>{isSafe: "true", botResponse: result, safetyResult: details}
WebApp-->>User: Display calculation result and safety info
else Content is unsafe
SafetyService-->>WebApp: Return result map<br/>{isSafe: "false", safetyResult: details}
WebApp-->>User: Display safety warning<br/>(without calculation)
end
```
@@ -0,0 +1,87 @@
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Content Safety Calculator</title>
<style>
body {
font-family: Arial, sans-serif;
line-height: 1.6;
margin: 0;
padding: 20px;
background-color: #f5f5f5;
}
.container {
max-width: 800px;
margin: 0 auto;
background-color: #fff;
padding: 20px;
border-radius: 5px;
box-shadow: 0 0 10px rgba(0,0,0,0.1);
}
h1 {
color: #333;
margin-bottom: 20px;
}
form {
margin-top: 20px;
}
label {
display: block;
margin-bottom: 8px;
font-weight: bold;
}
textarea {
width: 100%;
padding: 10px;
border: 1px solid #ddd;
border-radius: 4px;
resize: vertical;
min-height: 100px;
font-family: inherit;
}
button {
background-color: #4CAF50;
color: white;
padding: 10px 15px;
border: none;
border-radius: 4px;
cursor: pointer;
margin-top: 10px;
font-size: 16px;
}
button:hover {
background-color: #45a049;
}
.info {
margin-top: 20px;
padding: 15px;
background-color: #e6f7ff;
border-left: 4px solid #1890ff;
}
</style>
</head>
<body>
<div class="container">
<h1>Content Safety Calculator</h1>
<div class="info">
<p>Enter a prompt to perform calculations. The system will check if your content is safe before processing it.</p>
<p>Examples of safe prompts:</p>
<ul>
<li>"Calculate the sum of 24.5 and 17.3"</li>
<li>"What is 125 multiplied by 7?"</li>
<li>"Show me the help for the calculator service"</li>
</ul>
</div>
<form action="#" th:action="@{/process}" th:object="${promptRequest}" method="post">
<label for="prompt">Enter your prompt:</label>
<textarea id="prompt" name="prompt" th:field="*{prompt}" required></textarea>
<button type="submit">Submit</button>
</form>
</div>
</body>
</html>
@@ -0,0 +1,94 @@
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Content Safety Result</title>
<style>
body {
font-family: Arial, sans-serif;
line-height: 1.6;
margin: 40px;
background-color: #f5f5f5;
}
.container {
max-width: 800px;
margin: 0 auto;
background-color: #fff;
padding: 20px;
border-radius: 5px;
box-shadow: 0 0 10px rgba(0,0,0,0.1);
}
.card {
border: 1px solid #ddd;
border-radius: 8px;
padding: 20px;
margin-bottom: 20px;
background-color: #f9f9f9;
}
.safe {
background-color: #d4edda;
border-color: #c3e6cb;
}
.unsafe {
background-color: #f8d7da;
border-color: #f5c6cb;
}
.section {
margin-bottom: 20px;
}
h1, h2 {
color: #333;
}
pre {
background-color: #f5f5f5;
padding: 10px;
border-radius: 5px;
overflow-x: auto;
white-space: pre-wrap;
word-wrap: break-word;
}
.btn {
display: inline-block;
background-color: #007bff;
color: white;
padding: 10px 15px;
text-decoration: none;
border-radius: 5px;
margin-top: 20px;
}
</style>
</head>
<body>
<div class="container">
<h1>Content Safety Check Results</h1>
<div class="section">
<h2>Your Prompt</h2>
<pre th:text="${promptRequest.prompt}">User prompt will be displayed here</pre>
</div>
<div th:class="${isSafe == 'true' ? 'card safe' : 'card unsafe'}" class="section">
<h2>Prompt Safety Analysis</h2>
<pre th:text="${safetyResult}">Safety result details will be displayed here</pre>
</div>
<div th:if="${botResponse != null}" class="section">
<h2>Bot Response</h2>
<pre th:text="${botResponse}">Bot response will be displayed here</pre>
</div>
<div th:if="${botResponseSafetyResult != null}" th:class="${botResponse != 'The generated response was flagged for safety concerns and cannot be displayed.' ? 'card safe' : 'card unsafe'}" class="section">
<h2>Bot Response Safety Analysis</h2>
<pre th:text="${botResponseSafetyResult}"></pre>
</div>
<div th:if="${error != null}" class="section">
<h2>Error</h2>
<pre th:text="${error}">Error message will be displayed here</pre>
</div>
<a href="/" class="btn">Try Another Prompt</a>
</div>
</body>
</html>