Implementation:A616567126 GPT WEB JAVA KimiController
| Knowledge Sources | |
|---|---|
| Domains | AI_Chat, File_Processing |
| Last Updated | 2026-10-13 00:00 GMT |
Overview
Concrete REST controller for file-based AI chat using the Moonshot/Kimi API, enabling users to upload files and receive AI-generated content descriptions.
Description
The KimiController exposes a POST endpoint at `/kimi/kimi/chat` that accepts a file URL, uploads it to the Moonshot AI service, extracts file content, and sends a chat completion request asking the AI to describe and analyze the file content. It uses the `MoonshotAiService` for API calls and `AsyncService` for cleanup.
Usage
Import this controller when you need to provide file upload and AI-powered document understanding functionality. The endpoint accepts a `KimiStreamReq` with a file URL and returns a log ID for tracking the asynchronous chat response.
Code Reference
Source Location
- Repository: A616567126_GPT_WEB_JAVA
- File: src/main/java/com/intelligent/bot/api/kimi/KimiController.java
- Lines: 1-65
Signature
@RestController
@RequestMapping("/kimi")
public class KimiController {
@PostMapping(value = "/kimi/chat", name = "文件上传")
@AvoidRepeatRequest()
public B<JSONObject> kimiChat(@Validated @RequestBody KimiStreamReq req);
}
Import
import com.intelligent.bot.api.kimi.KimiController;
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| req | KimiStreamReq | Yes | Contains fileUrl, fileName, logId |
| req.fileUrl | String | Yes | URL of the file to analyze |
| req.fileName | String | No | Name of the file |
| req.logId | Long | No | Optional existing log ID |
Outputs
| Name | Type | Description |
|---|---|---|
| data.logId | Long | Log ID for tracking the chat response |
| status | int | Response status code (200 for success) |
Usage Examples
File Chat Request
// POST /kimi/kimi/chat
// Content-Type: application/json
// Authorization: Bearer <jwt-token>
{
"fileUrl": "https://example.com/document.pdf",
"fileName": "document.pdf",
"logId": null
}
// Response:
{
"status": 200,
"message": "操作成功",
"data": {
"logId": 1234567890
}
}
Controller Flow
// 1. Get random API key from pool
String secretKey = InitUtil.getRandomKey(2);
// 2. Create message log
Long logId = messageLogService.createMessageId(req.getLogId(), req.getFileUrl(), null, 2, req.getFileName());
// 3. Upload file to Moonshot AI
File file = FileUtil.createFile(req.getFileUrl());
String result = moonshotAiService.uploadFile(file, secretKey);
// 4. Extract file content
String fileContent = moonshotAiService.getFileContent(fileId, secretKey);
// 5. Send chat request with file content as system message
moonshotAiService.chat("moonshot-v1-8k", messageList, secretKey, logId, userId);