feat(BaiduGPTManager):优化图片描述功能并添加翻译功能

- 更新图片转文本的提示语,要求更详细的描述
- 添加将英文结果翻译成中文的功能
- 优化翻译提示语,确保准确翻译
- 更新版本号至 QQBot v.1.7.9.1
-调整日志设置的加载顺序
This commit is contained in:
Yutou 2025-02-04 18:00:07 +08:00
parent 1041dfa909
commit 09305ae824
2 changed files with 5 additions and 13 deletions

View File

@ -10,17 +10,15 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication @SpringBootApplication
public class QQBotApplication { public class QQBotApplication {
public static final String version = "QQBot v.1.7.8"; public static final String version = "QQBot v.1.7.9.1";
public static void main(String[] args) { public static void main(String[] args) {
System.out.println("version = " + version); System.out.println("version = " + version);
SpringApplication.run(QQBotApplication.class, args); SpringApplication.run(QQBotApplication.class, args);
NapCatApi.setLog(true);
RedisTools.initRedisPoolSub(); RedisTools.initRedisPoolSub();
QQBotManager.getInstance(); QQBotManager.getInstance();
val log = ConfigTools.load(ConfigTools.CONFIG, ConfigTools.QQ_LOG, Boolean.class); val log = ConfigTools.load(ConfigTools.CONFIG, ConfigTools.QQ_LOG, Boolean.class,true);
NapCatApi.setLog(log); NapCatApi.setLog(log);
//1
} }
} }

View File

@ -190,17 +190,11 @@ public class BaiduGPTManager {
// 调用图像转文本的API // 调用图像转文本的API
Image2TextResponse response = qianfan.image2Text() Image2TextResponse response = qianfan.image2Text()
.image(base64) .image(base64)
.prompt("分析图片,如果图中有文本则加上文本内容") .prompt("请描述这张图片中的主要内容和细节,以及它们之间的关系\n")
.execute(); .execute();
String translationPrompt = "将以下英文内容严格翻译为简体中文不要解释、不要添加额外内容保留专业术语和名称如Star Wars保持英文\n" + response.getResult();
// 获取API返回的结果 // 获取API返回的结果
String result = response.getResult(); return sendMessage("bot",translationPrompt).getContent();
// 如果结果不是中文通过sendMessage函数尝试将其翻译成中文
result = sendMessage("bot", "你是一个语言翻译专家,如果这段内容不是中文,请翻译成中文,如果已经是中文则不需要翻译:" + result).getContent();
// 返回最终的中文描述结果
return result;
} catch (Exception e) { } catch (Exception e) {
// 异常处理记录错误日志 // 异常处理记录错误日志
Log.e(e); Log.e(e);