12 changed files with 9 additions and 135 deletions
-
5CLAUDE.md
-
1DEPLOY.md
-
4README.md
-
57src/main/java/com/wok/supportbot/app/ProductInfoApp.java
-
2src/main/java/com/wok/supportbot/config/ChatModelFactory.java
-
1src/main/java/com/wok/supportbot/config/ModelConfigLoader.java
-
17src/main/java/com/wok/supportbot/controller/AiController.java
-
2src/main/java/com/wok/supportbot/entity/AiModelConfig.java
-
14src/main/java/com/wok/supportbot/entity/ProductInfo.java
-
4src/main/java/com/wok/supportbot/service/AiModelConfigService.java
-
5src/main/resources/static/components/ModelConfigManager.js
-
32src/test/java/com/wok/supportbot/SupportBotApplicationTests.java
@ -1,57 +0,0 @@ |
|||||
package com.wok.supportbot.app; |
|
||||
|
|
||||
import com.wok.supportbot.advisor.MyLoggerAdvisor; |
|
||||
import com.wok.supportbot.config.ChatModelFactory; |
|
||||
import com.wok.supportbot.entity.ProductInfo; |
|
||||
import lombok.extern.slf4j.Slf4j; |
|
||||
import org.springframework.ai.chat.client.ChatClient; |
|
||||
import org.springframework.ai.chat.client.advisor.MessageChatMemoryAdvisor; |
|
||||
import org.springframework.ai.chat.memory.ChatMemory; |
|
||||
import org.springframework.ai.chat.memory.InMemoryChatMemoryRepository; |
|
||||
import org.springframework.ai.chat.memory.MessageWindowChatMemory; |
|
||||
import org.springframework.stereotype.Component; |
|
||||
|
|
||||
/** |
|
||||
* 电商商品信息抽取助手App - 支持多提供商动态切换 |
|
||||
*/ |
|
||||
@Component |
|
||||
@Slf4j |
|
||||
public class ProductInfoApp { |
|
||||
|
|
||||
private final ChatModelFactory chatModelFactory; |
|
||||
|
|
||||
private static final String SYSTEM_PROMPT = "你是一名电商商品信息抽取助手," + |
|
||||
"请从用户提供的商品网页内容中提取标题(title)、描述(description)、价格(price)、评分(rating)、评论数(reviewCount)、品牌(brand)、分类(category)等字段。" + |
|
||||
"请严格按照JSON格式返回,不要带任何解释和多余内容。"; |
|
||||
|
|
||||
public ProductInfoApp(ChatModelFactory chatModelFactory) { |
|
||||
this.chatModelFactory = chatModelFactory; |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 商品信息结构化抽取 |
|
||||
* @param rawContent 爬取的商品网页内容 |
|
||||
* @return 结构化的商品信息对象 |
|
||||
*/ |
|
||||
public ProductInfo extractProductInfo(String rawContent) { |
|
||||
ChatMemory chatMemory = MessageWindowChatMemory.builder() |
|
||||
.chatMemoryRepository(new InMemoryChatMemoryRepository()) |
|
||||
.build(); |
|
||||
ChatClient chatClient = ChatClient.builder(chatModelFactory.getChatModel("PRODUCT_EXTRACT")) |
|
||||
.defaultSystem(SYSTEM_PROMPT) |
|
||||
.defaultAdvisors( |
|
||||
MessageChatMemoryAdvisor.builder(chatMemory).build(), |
|
||||
new MyLoggerAdvisor() |
|
||||
) |
|
||||
.build(); |
|
||||
|
|
||||
ProductInfo productInfo = chatClient |
|
||||
.prompt() |
|
||||
.system(SYSTEM_PROMPT) |
|
||||
.user(rawContent) |
|
||||
.call() |
|
||||
.entity(ProductInfo.class); |
|
||||
log.info("Extracted product info: {}", productInfo); |
|
||||
return productInfo; |
|
||||
} |
|
||||
} |
|
||||
@ -1,14 +0,0 @@ |
|||||
package com.wok.supportbot.entity; |
|
||||
|
|
||||
import lombok.Data; |
|
||||
|
|
||||
@Data |
|
||||
public class ProductInfo { |
|
||||
private String title; |
|
||||
private String description; |
|
||||
private String price; |
|
||||
private String rating; |
|
||||
private Integer reviewCount; |
|
||||
private String brand; |
|
||||
private String category; |
|
||||
} |
|
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue