|
@@ -0,0 +1,71 @@
|
|
|
+package com.fdkankan.fusion.common.util;
|
|
|
+
|
|
|
+import com.theokanning.openai.completion.chat.ChatCompletionChoice;
|
|
|
+import com.theokanning.openai.completion.chat.ChatCompletionRequest;
|
|
|
+import com.theokanning.openai.completion.chat.ChatMessage;
|
|
|
+import com.theokanning.openai.completion.chat.UserMessage;
|
|
|
+import com.theokanning.openai.service.OpenAiService;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+
|
|
|
+import java.io.IOException;
|
|
|
+import java.time.Duration;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author Xiewj
|
|
|
+ * @date 2024/10/11
|
|
|
+ */
|
|
|
+public class Openai {
|
|
|
+ public static void main(String[] args) throws IOException {
|
|
|
+ // gptVision("https://4dkankan.oss-cn-shenzhen.aliyuncs.com/images/imagesg5LNCydH6k/pan/high/7c84b1610aec4ee6095f1fa76ad6236c.png","http://192.168.9.61:30000/v1/");
|
|
|
+ gptVision("https://4dkankan.oss-cn-shenzhen.aliyuncs.com/images/imagesg5LNCydH6k/pan/high/7c84b1610aec4ee6095f1fa76ad6236c.png","http://192.168.9.61:30000/v1/",null);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public static String gptVision(String imgPath,String httpUrl,String text) throws IOException {
|
|
|
+ OpenAiService openAiService1 = new OpenAiService("", Duration.ofSeconds(120), httpUrl);
|
|
|
+ final List<ChatMessage> messages = new ArrayList<>();
|
|
|
+ if(StringUtils.isBlank(text)){
|
|
|
+ text = "任务指令:根据提供的户型图,识别并描述其结构及房间详情。请按照上北、下南、左西、右东的方向进行定位。\n" +
|
|
|
+ "\n" +
|
|
|
+ "输出格式要求:\n" +
|
|
|
+ "不能使用Markdown(MD)格式。\n" +
|
|
|
+ "结构清晰,易于理解。\n" +
|
|
|
+ "请遵循以下具体步骤:\n" +
|
|
|
+ "\n" +
|
|
|
+ "整体描述:\n" +
|
|
|
+ "1. 概述:首先给出整个户型的结构概述,简要描述户型。对于无法明确识别房间名的房间,可以采用代码形式表示。\n" +
|
|
|
+ "\n" +
|
|
|
+ "详细描述:\n" +
|
|
|
+ "1. 单个房间描述:接下来,针对每个房间单独一段进行描述。每段开头以房间名称开始,接着说明该房间位于图片的相对位置,以及房间内可见的具体家具数量和类型。注意,仅需描述实际识别到的家具,不要使用诸如“等”这样的词汇来泛指其他可能存在的物品。\n" +
|
|
|
+ "\n" +
|
|
|
+ "示例模板:\n" +
|
|
|
+ "整体描述:“这是一个${房间数}室${客厅数}厅${卫生间数}卫的户型。”\n" +
|
|
|
+ "房间描述:“${房间名称}:位于户型图${坐标方位}${房间名}通过${连接方式}与${房间名}相连,放置了${家具数量}个${家具类型}家具...”\n" +
|
|
|
+ "\n" +
|
|
|
+ "注意事项:\n" +
|
|
|
+ "确保输出的整体描述数据和房间数量对应上,室排除厨房数量。\n" +
|
|
|
+ "确保所有信息基于提供的户型图准确无误地提取。\n" +
|
|
|
+ "描述时保持语言简洁明了,直接传达关键信息。\n" +
|
|
|
+ "\n" +
|
|
|
+ "请确保您的描述符合上述要求,并尽可能提供详尽的信息。";
|
|
|
+ }
|
|
|
+ UserMessage imageMessage = UserMessage.builder().buildImageMessage(text, imgPath);
|
|
|
+
|
|
|
+
|
|
|
+ messages.add(imageMessage);
|
|
|
+ ChatCompletionRequest chatCompletionRequest = ChatCompletionRequest.builder()
|
|
|
+ .model("Qwen2-VL-7B")
|
|
|
+ //.model("qwen2-vl-instruct")
|
|
|
+ .messages(messages)
|
|
|
+ .temperature(0.06)
|
|
|
+ .topP(0.75)
|
|
|
+ .maxTokens(1024)
|
|
|
+ .n(1)
|
|
|
+ .build();
|
|
|
+ ChatCompletionChoice choice = openAiService1.createChatCompletion(chatCompletionRequest).getChoices().get(0);
|
|
|
+ return choice.getMessage().getContent();
|
|
|
+ }
|
|
|
+
|
|
|
+}
|