首頁 > web前端 > js教程 > ChatGPT 記憶體:它是如何運作的?

ChatGPT 記憶體:它是如何運作的?

PHPz
發布: 2024-08-26 21:36:32
原創
1242 人瀏覽過

ChatGPT Memory: How does it work ?

是否曾經希望你的人工智慧能夠記住你更喜歡簡短、直接的答案?還是您喜歡對某些主題進行更詳細的答覆?人工智慧記憶使這成為可能,讓系統回憶您的偏好並適應不同的對話。

在 LLMChat,我們一直致力於透過讓 AI 更聰明、更個人化來打造更直覺的 AI 聊天體驗。我們實現這一目標的關鍵方法之一是賦予人工智慧記住的能力。

人工智慧記憶的工作原理

人工智慧記憶體儲存用戶特定的訊息,以個性化未來的互動。它利用函數呼叫方法,在需要新增、更新或刪除新資訊時觸發特定操作。例如,如果您告訴人工智慧您更喜歡簡潔的答案,它會記住這一點並在以後的聊天中調整其回應。

這是我們用來管理記憶體的模式:

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"),
});
登入後複製

記憶功能的作用

讓我們來看看人工智慧記憶系統的核心。當提供新資訊(例如使用者偏好)時,我們的 DynamicStructuredTool 可確保 AI 動態更新或新增必要的詳細資訊。下面是它的工作原理的一瞥:

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;
    },
  });
};
登入後複製

此功能可確保 AI 不斷適應使用者偏好,讓每次互動都感覺量身定制且更相關。

為什麼記憶很重要

人工智慧記憶透過使互動更加個人化來增強使用者體驗。無論是記住您喜歡的答案、追蹤正在進行的項目,還是了解您的偏好,記憶都可以讓人工智慧更聰明地運作。它還為用戶提供了控制權,讓他們可以管理記住的內容、更新偏好設定或根據需要清除所有內容。

// Example: Updating user preferences in real-time
context.updatePreferences?.({
  memories: response.memories,
});
登入後複製

結論

記憶讓人工智慧不僅僅是一個工具——它成為一個適應你的伴侶。透過使用函數呼叫方法,我們為動態和個人化對話開啟了新的可能性。在 LLMChat,我們對記憶如何改變 AI 互動方式感到興奮,讓它們變得更聰明、更像人類。

以上是ChatGPT 記憶體:它是如何運作的?的詳細內容。更多資訊請關注PHP中文網其他相關文章!

本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板