更新时间:2024-11-21 GMT+08:00
配置多轮对话能力(Java SDK)
支持上下文记忆的多轮对话。
- 初始化。
import com.huaweicloud.pangu.dev.sdk.api.llms.LLMs; import com.huaweicloud.pangu.dev.sdk.api.skill.Skills; import com.huaweicloud.pangu.dev.sdk.skill.ConversationSkill; ConversationSkill skill = Skills.newConversationSkill(LLMs.of(LLMs.PANGU));
- 问答。
import com.huaweicloud.pangu.dev.sdk.memory.messagehistory.ChatMessageHistory; import com.huaweicloud.pangu.dev.sdk.memory.ConversationBufferMemory; import com.huaweicloud.pangu.dev.sdk.api.memory.config.MemoryStoreConfig; import org.junit.jupiter.api.Assertions; // 定义存储策略 skill.setMemory(new ConversationBufferMemory(MemoryStoreConfig.builder().windowSize(3).messageHistory(new ChatMessageHistory()).build())); String answer = skill.execute("中国首都是哪个城市?"); System.out.println(answer); Assertions.assertTrue(answer.contains("北京")); answer = skill.execute("它有什么好玩的地方?"); System.out.println(answer); Assertions.assertTrue(answer.contains("故宫"));
父主题: 配置Skill(Java SDK)