更新时间:2024-11-21 GMT+08:00
分享

配置多轮对话能力(Python SDK)

支持上下文记忆的多轮对话。

  • 初始化
    from pangukitsappdev.skill.conversation_skill import ConversationSkill
    from pangukitsappdev.api.llms.factory import LLMs
    skill = ConversationSkill(LLMs.of("pangu"))
  • 问答
    from pangukitsappdev.memory.redis_message_history import RedisMessageHistory
    from langchain.memory import ConversationBufferWindowMemory
    # 定义存储策略
    skill.set_memory(ConversationBufferWindowMemory(k=3, chat_memory=RedisMessageHistory()))
    answer = skill.execute("中国首都是哪个城市?")
    print(answer)
    assert "北京" in answer
    answer = skill.execute("它有什么好玩的地方?")
    print(answer)
    assert "故宫" in answer

相关文档