parent
482a2629d0
commit
6e4d1365de
@ -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,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
|
||||
</component>
|
||||
</project>
|
@ -0,0 +1,50 @@
|
||||
package com.learning.newdemo.controller;
|
||||
|
||||
|
||||
import com.learning.newdemo.common.Result;
|
||||
import com.learning.newdemo.service.WxArgumentService;
|
||||
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;
|
||||
|
||||
private String topic;
|
||||
|
||||
private String stance;
|
||||
|
||||
@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("立论主题或者内容为空");
|
||||
}
|
||||
|
||||
try {
|
||||
String argument = wxArgumentService.getArgument(topic, stance);
|
||||
if (argument == null) {
|
||||
return Result.error("立论获取失败");
|
||||
}
|
||||
|
||||
Map<String, Object> data = new HashMap<>();
|
||||
data.put("argument", argument);
|
||||
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,150 @@
|
||||
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.*;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class WxArgumentServiceImpl implements WxArgumentService {
|
||||
|
||||
// 依赖注入
|
||||
private final RestTemplate restTemplate;
|
||||
|
||||
// 使用@Value注解注入配置属性
|
||||
@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.stop}")
|
||||
private String stop;
|
||||
|
||||
@Value("${ai.argument.body.stream}")
|
||||
private boolean stream;
|
||||
|
||||
@Value("${ai.argument.body.stream_options}")
|
||||
private String streamOptions;
|
||||
|
||||
@Value("${ai.argument.body.temperature}")
|
||||
private double temperature;
|
||||
|
||||
@Value("${ai.argument.body.top_p}")
|
||||
private double topP;
|
||||
|
||||
@Value("${ai.argument.body.tools}")
|
||||
private String tools;
|
||||
|
||||
@Value("${ai.argument.body.tool_choice}")
|
||||
private String toolChoice;
|
||||
|
||||
@Value("${ai.argument.body.logprobs}")
|
||||
private boolean logprobs;
|
||||
|
||||
@Value("${ai.argument.body.top_logprobs}")
|
||||
private String topLogprobs;
|
||||
|
||||
@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 = String.format(
|
||||
"{"
|
||||
+ "\"messages\": ["
|
||||
+ "{"
|
||||
+ "\"role\": \"%s\","
|
||||
+ "\"content\": \"%s\""
|
||||
+ "},"
|
||||
+ "{"
|
||||
+ "\"role\": \"%s\","
|
||||
+ "\"content\": \"%s\\n我的立场是%s\""
|
||||
+ "}"
|
||||
+ "],"
|
||||
+ "\"model\": \"%s\","
|
||||
+ "\"frequency_penalty\": %d,"
|
||||
+ "\"max_tokens\": %d,"
|
||||
+ "\"presence_penalty\": %d,"
|
||||
+ "\"response_format\": {"
|
||||
+ "\"type\": \"%s\""
|
||||
+ "},"
|
||||
+ "\"stop\": %s,"
|
||||
+ "\"stream\": %b,"
|
||||
+ "\"stream_options\": %s,"
|
||||
+ "\"temperature\": %f,"
|
||||
+ "\"top_p\": %f,"
|
||||
+ "\"tools\": %s,"
|
||||
+ "\"tool_choice\": \"%s\","
|
||||
+ "\"logprobs\": %b,"
|
||||
+ "\"top_logprobs\": %s"
|
||||
+ "}",
|
||||
roleSys,
|
||||
contentSys,
|
||||
roleUser,
|
||||
topic,
|
||||
stance,
|
||||
model,
|
||||
frequencyPenalty,
|
||||
maxTokens,
|
||||
presencePenalty,
|
||||
responseFormatType,
|
||||
stop,
|
||||
stream,
|
||||
streamOptions,
|
||||
temperature,
|
||||
topP,
|
||||
tools,
|
||||
toolChoice,
|
||||
logprobs,
|
||||
topLogprobs
|
||||
);
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
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