|
|
|
@ -21,6 +21,8 @@ import java.util.Map;
|
|
|
|
|
@Slf4j
|
|
|
|
|
@Service
|
|
|
|
|
public class LLMExtractServiceImpl implements LLMExtractService {
|
|
|
|
|
private static final String VAR_NAME_SOURCE_TEXT = "source_text";
|
|
|
|
|
private static final String VAR_NAME_ATTR_DEFINE = "attr_define";
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private OllamaChatClient ollamaChatClient;
|
|
|
|
@ -37,7 +39,7 @@ public class LLMExtractServiceImpl implements LLMExtractService {
|
|
|
|
|
5. 有可能很大概率是没有标题的。
|
|
|
|
|
|
|
|
|
|
文本原文:
|
|
|
|
|
{ocr_txt}
|
|
|
|
|
{source_text}
|
|
|
|
|
输出json格式:{"title":"*****"},如果没有明显标题:{"title":""}。
|
|
|
|
|
|
|
|
|
|
回溯你输出的结果,确保你的输出结果符合json格式。
|
|
|
|
@ -50,7 +52,7 @@ public class LLMExtractServiceImpl implements LLMExtractService {
|
|
|
|
|
// 遍历ocrExtractDtoList,调用接口提取标题
|
|
|
|
|
LLMExtractDtoList.forEach(ocrExtractDto -> {
|
|
|
|
|
HashMap<String, String> paramMap = new HashMap<>();
|
|
|
|
|
paramMap.put("ocr_txt", ocrExtractDto.getText());
|
|
|
|
|
paramMap.put(VAR_NAME_SOURCE_TEXT, ocrExtractDto.getText());
|
|
|
|
|
String template = "提取下面文本中前40个字中明显的标题:\n" +
|
|
|
|
|
"### 注意事项:\n" +
|
|
|
|
|
"1. 将结果以JSON格式返回。不需要进行解释。\n" +
|
|
|
|
@ -61,7 +63,7 @@ public class LLMExtractServiceImpl implements LLMExtractService {
|
|
|
|
|
"6. 有可能很大概率是没有标题的。\n" +
|
|
|
|
|
"\n" +
|
|
|
|
|
"文本原文:\n" +
|
|
|
|
|
"{ocr_txt}\n" +
|
|
|
|
|
"{source_text}\n" +
|
|
|
|
|
"输出json格式:{{\"title\":\"*****\"}},如果没有明显标题:{{\"title\":\"\"}}。\n" +
|
|
|
|
|
"\n" +
|
|
|
|
|
"回溯你输出的结果,确保你的输出结果符合json格式。";
|
|
|
|
@ -109,7 +111,7 @@ public class LLMExtractServiceImpl implements LLMExtractService {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
源文本:
|
|
|
|
|
{ocr_txt}
|
|
|
|
|
{source_text}
|
|
|
|
|
|
|
|
|
|
属性定义:
|
|
|
|
|
{attr_define}
|
|
|
|
@ -117,7 +119,7 @@ public class LLMExtractServiceImpl implements LLMExtractService {
|
|
|
|
|
### 注意事项:
|
|
|
|
|
1. 将结果以JSON格式返回。不需要进行解释。
|
|
|
|
|
2. 如果某字段提取不到,则返回""。
|
|
|
|
|
3. 日期格式为yyyy-MM-dd,浮点型格式返回保留两位小数。
|
|
|
|
|
3. 日期格式为yyyy-MM-dd,数字格式返回保留两位小数。
|
|
|
|
|
4. 值为文本类型的数据,尽量使用原文中的文字。
|
|
|
|
|
5. 只可以使用原文中的文字,不可以自行添加内容。
|
|
|
|
|
|
|
|
|
@ -143,8 +145,8 @@ public class LLMExtractServiceImpl implements LLMExtractService {
|
|
|
|
|
}
|
|
|
|
|
requirementBuilder.append("}");
|
|
|
|
|
String prompt = StrUtil.format(LLMExtractDto.getPrompt(), Map.of(
|
|
|
|
|
"attr_define", requirementBuilder.toString(),
|
|
|
|
|
"ocr_txt", LLMExtractDto.getText()
|
|
|
|
|
VAR_NAME_ATTR_DEFINE, requirementBuilder.toString(),
|
|
|
|
|
VAR_NAME_SOURCE_TEXT, LLMExtractDto.getText()
|
|
|
|
|
));
|
|
|
|
|
log.info("属性提取请求\n:{}", prompt);
|
|
|
|
|
ChatResponse call = ollamaChatClient.call(new Prompt(new UserMessage(prompt)));
|
|
|
|
|