ChatGPT 内存:它是如何工作的?

PHPz
发布: 2024-08-26 21:36:32
原创
929 人浏览过

ChatGPT Memory: How does it work ?

Ever wished your AI could remember that you prefer short, direct answers? Or that you like more detailed responses on certain topics? AI memory makes this possible, allowing the system to recall your preferences and adapt across different conversations.

At LLMChat, we've been working on building AI chat experiences that feel more intuitive—by making AI smarter, but also more personal. One of the key ways we've done this is by giving AI the ability toremember.

How AI Memory Works

AI memory stores user-specific information to personalize future interactions. It leverages afunction-calling approach, triggering specific actions when new information needs to be added, updated, or removed. For example, if you tell the AI you prefer concise answers, it remembers that and adjusts its responses in future chats.

Here's the schema we use for managing memory:

const memoryToolSchema = z.object({ memory: z.array( z.string().describe("Key information about the user") ).describe("New info to be added or updated"), question: z.string().describe("The user's request"), });
登录后复制

The Memory Function in Action

Let's look at the core of our AI memory system. When new information is provided, such as user preferences, our DynamicStructuredTool ensures that the AI updates or adds the necessary details dynamically. Here's a glimpse of how it works:

const memoryFunction = (context: ToolExecutionContext) => { return new DynamicStructuredTool({ name: "memory", description: "Manages user preferences and adapts interactions...", schema: memoryToolSchema, func: async ({ memory, question }) => { const existingMemories = context.preferences?.memories || []; const chain = RunnableSequence.from([ PromptTemplate.fromTemplate(` User request: "{question}" New info: {new_memory} Existing memories: {existing_memory} Update memories: 1. Update existing details 2. Remove if necessary 3. Add new unique memories`), context.model, memoryParser, ]); const response = await chain.invoke({ new_memory: memory.join("\n"), existing_memory: existingMemories.join("\n"), question: question, }); context.updatePreferences?.({ memories: response.memories }); return question; }, }); };
登录后复制

This function ensures that the AI continuously adapts to user preferences, making every interaction feel tailored and more relevant.

Why Memory Matters

AI memory enhances user experiences by making interactions more personalized. Whether it's remembering how you like your answers, tracking ongoing projects, or knowing your preferences, memory allows AI to operate more intelligently. It also gives users control—allowing them to manage what's remembered, update preferences, or clear everything if needed.

// Example: Updating user preferences in real-time context.updatePreferences?.({ memories: response.memories, });
登录后复制

Conclusion

Memory makes AI more than just a tool—it becomes a companion that adapts to you. By using a function-calling approach, we've unlocked new possibilities for dynamic and personalized conversations. At LLMChat, we're excited about how memory can transform AI interactions, making them smarter and more human-like.

以上是ChatGPT 内存:它是如何工作的?的详细内容。更多信息请关注PHP中文网其他相关文章!

来源:dev.to
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!