commit
c7319a564d
@ -0,0 +1,124 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="Palette2">
|
||||||
|
<group name="Swing">
|
||||||
|
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
|
||||||
|
</item>
|
||||||
|
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.svg" removable="false" auto-create-binding="false" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
|
||||||
|
<initial-values>
|
||||||
|
<property name="text" value="Button" />
|
||||||
|
</initial-values>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
||||||
|
<initial-values>
|
||||||
|
<property name="text" value="RadioButton" />
|
||||||
|
</initial-values>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
||||||
|
<initial-values>
|
||||||
|
<property name="text" value="CheckBox" />
|
||||||
|
</initial-values>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
|
||||||
|
<initial-values>
|
||||||
|
<property name="text" value="Label" />
|
||||||
|
</initial-values>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||||
|
<preferred-size width="150" height="-1" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||||
|
<preferred-size width="150" height="-1" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||||
|
<preferred-size width="150" height="-1" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||||
|
<preferred-size width="150" height="50" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||||
|
<preferred-size width="150" height="50" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||||
|
<preferred-size width="150" height="50" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||||
|
<preferred-size width="150" height="50" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
|
||||||
|
<preferred-size width="150" height="50" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||||
|
<preferred-size width="150" height="50" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
||||||
|
<preferred-size width="200" height="200" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
||||||
|
<preferred-size width="200" height="200" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
|
||||||
|
<preferred-size width="-1" height="20" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
|
||||||
|
</item>
|
||||||
|
</group>
|
||||||
|
</component>
|
||||||
|
</project>
|
@ -0,0 +1,86 @@
|
|||||||
|
package com.learning.newdemo.controller;
|
||||||
|
|
||||||
|
|
||||||
|
import com.learning.newdemo.common.Result;
|
||||||
|
import com.learning.newdemo.service.WxArgumentService;
|
||||||
|
import com.learning.newdemo.service.WxReviewService;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("api/ai")
|
||||||
|
public class WxAIController {
|
||||||
|
@Autowired
|
||||||
|
private WxArgumentService wxArgumentService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private WxReviewService wxReviewService;
|
||||||
|
|
||||||
|
private String topic;
|
||||||
|
|
||||||
|
private String stance;
|
||||||
|
|
||||||
|
private String content;
|
||||||
|
|
||||||
|
@PostMapping("/argument")
|
||||||
|
public Result<Map<String, Object>> getArgument(@RequestBody Map<String, String> params){
|
||||||
|
topic = params.get("topic");
|
||||||
|
stance = params.get("stance");
|
||||||
|
|
||||||
|
|
||||||
|
if(topic == null || stance == null){
|
||||||
|
return Result.error("立论主题或者内容为空");
|
||||||
|
}
|
||||||
|
|
||||||
|
log.info("请求内容: {}", params);
|
||||||
|
|
||||||
|
try {
|
||||||
|
String argument = wxArgumentService.getArgument(topic, stance);
|
||||||
|
if (argument == null) {
|
||||||
|
return Result.error("立论获取失败");
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, Object> data = new HashMap<>();
|
||||||
|
data.put("argument", argument);
|
||||||
|
// 查看data
|
||||||
|
log.info("立论获取成功:{}", argument);
|
||||||
|
|
||||||
|
return Result.success(data);
|
||||||
|
}catch (Exception e){
|
||||||
|
log.error("立论获取失败", e);
|
||||||
|
return Result.error("立论获取失败:" + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/review")
|
||||||
|
public Result<Map<String, Object>> review(@RequestBody Map<String, String> params){
|
||||||
|
log.info("请求内容: {}", params);
|
||||||
|
|
||||||
|
content = params.get("content");
|
||||||
|
|
||||||
|
try {
|
||||||
|
String review = wxReviewService.getReview(content);
|
||||||
|
if (review == null) {
|
||||||
|
return Result.error("复盘获取失败");
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, Object> data = new HashMap<>();
|
||||||
|
data.put("review", review);
|
||||||
|
// 查看data
|
||||||
|
log.info("复盘获取成功:{}", review);
|
||||||
|
|
||||||
|
return Result.success(data);
|
||||||
|
}catch (Exception e){
|
||||||
|
log.error("复盘获取失败", e);
|
||||||
|
return Result.error("复盘获取失败:" + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
package com.learning.newdemo.service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 微信立论助手接口
|
||||||
|
*/
|
||||||
|
|
||||||
|
public interface WxArgumentService {
|
||||||
|
String getArgument(String topic, String stance);
|
||||||
|
}
|
@ -0,0 +1,5 @@
|
|||||||
|
package com.learning.newdemo.service;
|
||||||
|
|
||||||
|
public interface WxReviewService {
|
||||||
|
String getReview(String content);
|
||||||
|
}
|
@ -0,0 +1,95 @@
|
|||||||
|
package com.learning.newdemo.service.impl;
|
||||||
|
|
||||||
|
import com.learning.newdemo.service.WxArgumentService;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.http.HttpEntity;
|
||||||
|
import org.springframework.http.HttpHeaders;
|
||||||
|
import org.springframework.http.HttpMethod;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.web.client.RestTemplate;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@Slf4j
|
||||||
|
public class WxArgumentServiceImpl implements WxArgumentService {
|
||||||
|
|
||||||
|
private final RestTemplate restTemplate;
|
||||||
|
|
||||||
|
@Value("${ai.argument.header.Authorization}") private String authorizationHeader;
|
||||||
|
@Value("${ai.argument.body.message.role-sys}") private String roleSys;
|
||||||
|
@Value("${ai.argument.body.message.content-sys}") private String contentSys;
|
||||||
|
@Value("${ai.argument.body.message.role-user}") private String roleUser;
|
||||||
|
@Value("${ai.argument.body.model}") private String model;
|
||||||
|
@Value("${ai.argument.body.frequency_penalty}") private int frequencyPenalty;
|
||||||
|
@Value("${ai.argument.body.max_tokens}") private int maxTokens;
|
||||||
|
@Value("${ai.argument.body.presence_penalty}") private int presencePenalty;
|
||||||
|
@Value("${ai.argument.body.response_format}") private String responseFormatType;
|
||||||
|
@Value("${ai.argument.body.stream}") private boolean stream;
|
||||||
|
@Value("${ai.argument.body.temperature}") private double temperature;
|
||||||
|
@Value("${ai.argument.body.top_p}") private double topP;
|
||||||
|
@Value("${ai.argument.body.tool_choice}") private String toolChoice;
|
||||||
|
@Value("${ai.argument.body.logprobs}") private boolean logprobs;
|
||||||
|
@Value("${ai.argument.url}") private String url;
|
||||||
|
|
||||||
|
public WxArgumentServiceImpl(RestTemplate restTemplate) {
|
||||||
|
this.restTemplate = restTemplate;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getArgument(String topic, String stance) {
|
||||||
|
try {
|
||||||
|
HttpHeaders headers = new HttpHeaders();
|
||||||
|
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||||
|
headers.set("Authorization", authorizationHeader);
|
||||||
|
|
||||||
|
// 构建请求体,使用字符串拼接
|
||||||
|
String requestBody = "{"
|
||||||
|
+ "\"messages\": ["
|
||||||
|
+ "{"
|
||||||
|
+ "\"role\": \"" + roleSys + "\","
|
||||||
|
+ "\"content\": \"" + escapeJson(contentSys) + "\""
|
||||||
|
+ "},"
|
||||||
|
+ "{"
|
||||||
|
+ "\"role\": \"" + roleUser + "\","
|
||||||
|
+ "\"content\": \"" + escapeJson(topic + ",我的立场是" + stance) + "\""
|
||||||
|
+ "}"
|
||||||
|
+ "],"
|
||||||
|
+ "\"model\": \"" + model + "\","
|
||||||
|
+ "\"frequency_penalty\": " + frequencyPenalty + ","
|
||||||
|
+ "\"max_tokens\": " + maxTokens + ","
|
||||||
|
+ "\"presence_penalty\": " + presencePenalty + ","
|
||||||
|
+ "\"response_format\": {\"type\": \"" + responseFormatType + "\"},"
|
||||||
|
+ "\"stop\": null,"
|
||||||
|
+ "\"stream\": " + stream + ","
|
||||||
|
+ "\"stream_options\": null,"
|
||||||
|
+ "\"temperature\": " + temperature + ","
|
||||||
|
+ "\"top_p\": " + topP + ","
|
||||||
|
+ "\"tools\": null,"
|
||||||
|
+ "\"tool_choice\": \"" + toolChoice + "\","
|
||||||
|
+ "\"logprobs\": " + logprobs + ","
|
||||||
|
+ "\"top_logprobs\": null"
|
||||||
|
+ "}";
|
||||||
|
|
||||||
|
log.info("请求体:{}", requestBody);
|
||||||
|
|
||||||
|
HttpEntity<String> requestEntity = new HttpEntity<>(requestBody, headers);
|
||||||
|
ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.POST, requestEntity, String.class);
|
||||||
|
return response.getBody();
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("向AI获取立论失败", e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 工具方法:转义 JSON 字符串中的特殊字符
|
||||||
|
private String escapeJson(String input) {
|
||||||
|
if (input == null) return "";
|
||||||
|
return input.replace("\\", "\\\\")
|
||||||
|
.replace("\"", "\\\"")
|
||||||
|
.replace("\n", "\\n")
|
||||||
|
.replace("\r", "\\r")
|
||||||
|
.replace("\t", "\\t");
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,91 @@
|
|||||||
|
package com.learning.newdemo.service.impl;
|
||||||
|
|
||||||
|
import com.learning.newdemo.service.WxReviewService;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.http.*;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.web.client.RestTemplate;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@Slf4j
|
||||||
|
public class WxReviewServiceImpl implements WxReviewService {
|
||||||
|
|
||||||
|
private final RestTemplate restTemplate;
|
||||||
|
|
||||||
|
@Value("${ai.argument.header.Authorization}") private String authorizationHeader;
|
||||||
|
@Value("${ai.argument.body.message.role-sys}") private String roleSys;
|
||||||
|
@Value("${ai.review.body.message.content-sys}") private String contentSys;
|
||||||
|
@Value("${ai.argument.body.message.role-user}") private String roleUser;
|
||||||
|
@Value("${ai.argument.body.model}") private String model;
|
||||||
|
@Value("${ai.argument.body.frequency_penalty}") private int frequencyPenalty;
|
||||||
|
@Value("${ai.argument.body.max_tokens}") private int maxTokens;
|
||||||
|
@Value("${ai.argument.body.presence_penalty}") private int presencePenalty;
|
||||||
|
@Value("${ai.argument.body.response_format}") private String responseFormatType;
|
||||||
|
@Value("${ai.argument.body.stream}") private boolean stream;
|
||||||
|
@Value("${ai.argument.body.temperature}") private double temperature;
|
||||||
|
@Value("${ai.argument.body.top_p}") private double topP;
|
||||||
|
@Value("${ai.argument.body.tool_choice}") private String toolChoice;
|
||||||
|
@Value("${ai.argument.body.logprobs}") private boolean logprobs;
|
||||||
|
@Value("${ai.argument.url}") private String url;
|
||||||
|
|
||||||
|
public WxReviewServiceImpl(RestTemplate restTemplate) {
|
||||||
|
this.restTemplate = restTemplate;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getReview(String content) {
|
||||||
|
try {
|
||||||
|
HttpHeaders headers = new HttpHeaders();
|
||||||
|
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||||
|
headers.set("Authorization", authorizationHeader);
|
||||||
|
|
||||||
|
// 构建请求体,使用字符串拼接
|
||||||
|
String requestBody = "{"
|
||||||
|
+ "\"messages\": ["
|
||||||
|
+ "{"
|
||||||
|
+ "\"role\": \"" + roleSys + "\","
|
||||||
|
+ "\"content\": \"" + escapeJson(contentSys) + "\""
|
||||||
|
+ "},"
|
||||||
|
+ "{"
|
||||||
|
+ "\"role\": \"" + roleUser + "\","
|
||||||
|
+ "\"content\": \"" + content + "\""
|
||||||
|
+ "}"
|
||||||
|
+ "],"
|
||||||
|
+ "\"model\": \"" + model + "\","
|
||||||
|
+ "\"frequency_penalty\": " + frequencyPenalty + ","
|
||||||
|
+ "\"max_tokens\": " + maxTokens + ","
|
||||||
|
+ "\"presence_penalty\": " + presencePenalty + ","
|
||||||
|
+ "\"response_format\": {\"type\": \"" + responseFormatType + "\"},"
|
||||||
|
+ "\"stop\": null,"
|
||||||
|
+ "\"stream\": " + stream + ","
|
||||||
|
+ "\"stream_options\": null,"
|
||||||
|
+ "\"temperature\": " + temperature + ","
|
||||||
|
+ "\"top_p\": " + topP + ","
|
||||||
|
+ "\"tools\": null,"
|
||||||
|
+ "\"tool_choice\": \"" + toolChoice + "\","
|
||||||
|
+ "\"logprobs\": " + logprobs + ","
|
||||||
|
+ "\"top_logprobs\": null"
|
||||||
|
+ "}";
|
||||||
|
|
||||||
|
log.info("请求体:{}", requestBody);
|
||||||
|
|
||||||
|
HttpEntity<String> requestEntity = new HttpEntity<>(requestBody, headers);
|
||||||
|
ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.POST, requestEntity, String.class);
|
||||||
|
return response.getBody();
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("向AI获取立论失败", e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 工具方法:转义 JSON 字符串中的特殊字符
|
||||||
|
private String escapeJson(String input) {
|
||||||
|
if (input == null) return "";
|
||||||
|
return input.replace("\\", "\\\\")
|
||||||
|
.replace("\"", "\\\"")
|
||||||
|
.replace("\n", "\\n")
|
||||||
|
.replace("\r", "\\r")
|
||||||
|
.replace("\t", "\\t");
|
||||||
|
}
|
||||||
|
}
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in new issue