Skip to content

Conversation

@onlykillerf
Copy link

我修改了第八章 记忆与检索.md ,用原本的HelloAgentsLLM,得到的结果才是0记忆功能的,为记忆功能必要性提供支撑。

源代码执行结果:
你好,张三!很高兴知道你正在学习Python。如果你已经掌握了基础语法,接下来可以考虑学习一些更高级的主题,比如:
xxxxxxx
你有什么特定的方向或问题想要探讨吗?
当然记得,张三!你提到你已经掌握了Python的基础语法。xxxxxxx

因为执行的智能体为SimpleAgent,run方法中会添加历史信息(记忆功能):
# 添加历史消息
for msg in self._history:
messages.append({"role": msg.role, "content": msg.content})

    # 添加当前用户消息
    messages.append({"role": "user", "content": input_text})

我修改后的代码:

第七章的Agent使用方式

from dotenv import load_dotenv
from hello_agents import HelloAgentsLLM
load_dotenv()

创建LLM实例

llm = HelloAgentsLLM()

第一次对话

messages1 = [
{"role": "system", "content": "你是一个学习助手"},
{"role": "user", "content": "我叫张三,正在学习Python,目前掌握了基础语法"}
]

print("第一次对话:")
response1 = "".join(llm.think(messages1))
print(f"完整回复: {response1}")

第二次对话

messages2 = [
{"role": "user", "content": "你还记得我的学习进度吗?"}
]

print("\n第二次对话:")
response2 = "".join(llm.think(messages2))
print(f"完整回复: {response2}")


此时回答才完全不具备记忆功能:
第一次对话:
🧠 正在调用 gpt-4o-mini 模型...
✅ 大语言模型响应成功:
你好,张三!很高兴你在学习Python。如果你已经掌握了基础语法,接下来可以尝试一些更高级的主题,比如:xxxxx
如果你有任何具体的问题或者想要深入了解的主题,随时告诉我!

第二次对话:
🧠 正在调用 gpt-4o-mini 模型...
✅ 大语言模型响应成功:
抱歉,我无法记住之前的对话或用户的个人信息。不过,我可以帮助你了解学习进度或提供相关的学习建议。如果你能告诉我你的学习内容或进度,我会尽力帮助你!

Process finished with exit code 0





…. in the 第八章 记忆与检索.md~ file

Copy link
Author

@onlykillerf onlykillerf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

去除print(f"完整回复: {response1}")和print(f"完整回复: {response2}")的冗余代码,HelloAgentsLLM基类中think方法已经可以输出回复了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant