盘古大模型 PANGULARGEMODELS-多轮对话

时间:2024-09-05 14:59:04

多轮对话

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

  • 初始化
    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
support.huaweicloud.com/ugobs-obs-pangulm/zh-cn_topic_0000001718463489.html