ChatGPT Memory: How does it work ?

PHPz
Release: 2024-08-26 21:36:32
Original
929 people have browsed it

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"), });
Copy after login

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; }, }); };
Copy after login

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, });
Copy after login

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.

The above is the detailed content of ChatGPT Memory: How does it work ?. For more information, please follow other related articles on the PHP Chinese website!

source:dev.to
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!