merge sphinx doc into master

This commit is contained in:
huangsen.huang 2024-09-01 16:49:21 +08:00 committed by jinli.yl
parent 430b4d8180
commit 28a3ec3dff
21 changed files with 213 additions and 677 deletions

View file

@ -2,9 +2,7 @@ English | [**中文**](./README_ZH.md)
# MemoryScope
<p align="left">
<img src="docs/images/logo_1.png" width="700px" alt="MemoryScope Logo">
</p>
![MemoryScope Logo](./docs/images/logo_1.png)
Equip your LLM chatbot with a powerful and flexible long term memory system.
@ -33,9 +31,8 @@ to form and update *insights*. Then, memory re-consolidation is performed to ens
among memory pieces are properly handled.
### Framework
<p align="left">
<img src="docs/images/framework.png" width="700px" alt="MemoryScope Framework">
</p>
![MemoryScope Logo](./docs/images/framework.png)
### Main Features

View file

@ -2,6 +2,7 @@
# MemoryScope
![MemoryScope Logo](./docs/images/logo_1.png)
<p align="left">
<img src="docs/images/logo.png" width="700px" alt="MemoryScope Logo">
</p>
@ -28,12 +29,25 @@
## 什么是MemoryScope
💾 记忆数据库:
- MemoryScope 配备了一个 *ElasticSearch (ES)* 向量数据库,用于存储系统中记录的所有记忆片段。
🛠️ 系统操作:
- 记忆检索:当用户输入对话,此操作返回语义相关的记忆片段。如果输入对话包含对时间的指涉,则同时返回相应时间中的记忆片段。
- 记忆巩固:此操作接收一批用户的输入对话,并从对话中提取重要的用户信息,将其作为 *observation* 形式的记忆片段存储在记忆数据库中。
- 反思与再巩固:每隔一段时间,此操作对新记录的 *observations* 进行反思,以形成和更新 *insight* 形式的记忆片段。然后执行记忆再巩固,
以确保记忆片段之间的矛盾和重复得到妥善处理。
### 框架
MemoryScope可以为LLM聊天机器人提供强大且灵活的长期记忆能力并提供了构建长期记忆能力的框架。
MemoryScope可以用于个人助理、情感陪伴等记忆场景通过长期记忆能力来不断学习记得用户的基础信息以及各种习惯和喜好使得用户在使用LLM时逐渐感受到一种“默契”。
<p align="left">
<img src="docs/images/framework.png" width="700px" alt="MemoryScope Framework">
</p>
![MemoryScope Logo](./docs/images/framework.png)
### 主要特点
### 长期记忆的框架:
💾 记忆数据库: MemoryScope配备了向量数据库(默认是*ElasticSearch*),用于存储系统中记录的所有记忆片段。

View file

@ -43,28 +43,13 @@
3. Run `docker-compose up` to build and launch the memory-scope cli interface.
## III. Install from PYPI [Linux only]
## III. Install from PyPI [Linux]
1. Install from pypi:
```bash
pip install memoryscope
```
2. test Chinese / Dashscope chat configuration:
```bash
export DASHSCOPE_API_KEY="sk-0000000000"
memoryscope --config_path=memoryscope/core/config/demo_config_zh.yaml
```
3. test English / OpenAI chat configuration:
```bash
export OPENAI_API_KEY="sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
python quick-start-demo.py --config_path=memoryscope/core/config/demo_config.yaml
```
```bash
pip install memoryscope
export DASHSCOPE_API_KEY="sk-0000000000"
memoryscope --config_path=memoryscope/core/config/demo_config_zh.yaml
```
## IV. Install from source [Linux only]
@ -78,7 +63,7 @@
vim memoryscope/core/config/demo_config_zh.yaml
```
2. Install
2. Install
```bash
pip install -e .
```

View file

@ -1,7 +1,41 @@
#!/bin/bash
cd docs/sphinx_doc
# remove build
rm -rf build/html/*
rm en/source/memoryscope*.rst
rm zh_CN/source/memoryscope*.rst
# copy related files
cd ../../
cp README.md docs/sphinx_doc/en/source/README.md
cp docs/installation.md docs/sphinx_doc/en/source/docs/installation.md
cp -r docs/images docs/sphinx_doc/en/source/docs/images
cp -r examples docs/sphinx_doc/en/source/examples
cp README_ZH.md docs/sphinx_doc/zh_CN/source/README.md
cp docs/installation_ZH.md docs/sphinx_doc/zh_CN/source/docs/installation.md
cp -r docs/images docs/sphinx_doc/zh_CN/source/docs/images
cp -r examples docs/sphinx_doc/zh_CN/source/examples
# build
cd docs/sphinx_doc
sphinx-apidoc -f -o en/source ../../memoryscope -t template -e
sphinx-apidoc -f -o zh_CN/source ../../memoryscope -t template -e
make clean all
# clear redundant files
make clean all
rm en/source/README.md
rm en/source/docs/installation.md
rm -rf en/source/docs/images
rm -rf en/source/examples
rm zh_CN/source/README.md
rm zh_CN/source/docs/installation.md
rm -rf zh_CN/source/docs/images
rm -rf zh_CN/source/examples

View file

@ -39,11 +39,12 @@ extensions = [
"sphinxcontrib.mermaid",
"myst_parser",
"sphinx.ext.autosectionlabel",
'sphinxcontrib.autodoc_pydantic'
"sphinxcontrib.autodoc_pydantic",
"nbsphinx"
]
autodoc_pydantic_model_show_json = True
autodoc_pydantic_settings_show_json = True
autodoc_pydantic_settings_show_json = True
# Prefix document path to section labels, otherwise autogenerated labels would
# look like 'heading' rather than 'path/to/file:heading'
@ -82,13 +83,16 @@ exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]
#
html_theme = "sphinx_rtd_theme"
# html_logo = "_static/logo.png"
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ["_static"]
html_theme_options = {
"navigation_depth": 10,
# "logo_only": True,
"navigation_depth": 4,
}
source_suffix = {

View file

@ -1,9 +1,5 @@
.. _api:
=============
API Reference
=============
MemoryScope API Documentation

View file

@ -6,25 +6,48 @@
:github_url: https://github.com/modelscope/memoryscope
MemoryScope Documentation
======================================
=========================
Welcome to MemoryScope Tutorial
-------------------------------
.. include:: tutorial/main.md
:parser: myst_parser.sphinx_
.. image:: docs/images/logo_1.png
:align: center
MemoryScope is a powerful and flexible long term memory system for LLM chatbots. It consists
of a memory database and three customizable system operations, which can be flexibly combined to provide
robust long term memory services for your LLM chatbot.
💾 Memory Database:
^^^^^^^^^^^^^^^^^^^^
- MemoryScope comes with an *ElasticSearch (ES)* vector database to store all the
memory pieces recorded in the system.
🛠️ System operations:
^^^^^^^^^^^^^^^^^^^^^
- Memory Retrieval: Upon arrival of a user query, this operation returns the semantically related memory pieces
and/or those from the corresponding time if the query involves reference to time.
- Memory Consolidation: This operation takes in a batch of user queries and returns important user information
extracted from the queries as consolidated *observations* to be stored in the memory database.
- Reflection and Re-consolidation: At regular intervals, this operation performs reflection upon newly recorded *observations*
to form and update *insights*. Then, memory re-consolidation is performed to ensure contradictions and repetitions
among memory pieces are properly handled.
.. toctree::
:maxdepth: 1
:glob:
:hidden:
:maxdepth: 2
:caption: MemoryScope Tutorial
tutorial/101-memoryscope.md
tutorial/102-installation.md
tutorial/103-example.md
About MemoryScope <README.md>
🚀 Installation <docs/installation.md>
Cli Client <examples/cli/README.md>
Simple Usages <examples/api/simple_usages_en.ipynb>
.. toctree::
:maxdepth: 6
:caption: MemoryScope API Reference
memoryscope
API <docs/api.rst>

View file

@ -1,116 +0,0 @@
(101-memoryscope-en)=
# About AgentScope
In this tutorial, we will provide an overview of AgentScope by answering
several questions, including what's AgentScope, what can AgentScope provide,
and why we should choose AgentScope. Let's get started!
## What is AgentScope?
AgentScope is a developer-centric multi-agent platform, which enables
developers to build their LLM-empowered multi-agent applications with less
effort.
With the advance of large language models, developers are able to build
diverse applications.
In order to connect LLMs to data and services and solve complex tasks,
AgentScope provides a series of development tools and components for ease of
development.
It features
- **usability**,
- **robustness**,
- **the support of multi-modal data**,
- **distributed deployment**.
## Key Concepts
### Message
Message is a carrier of information (e.g. instructions, multi-modal
data, and dialogue). In AgentScope, message is a Python dict subclass
with `name` and `content` as necessary fields, and `url` as an optional
field referring to additional resources.
### Agent
Agent is an autonomous entity capable of interacting with environment and
agents, and taking actions to change the environment. In AgentScope, an
agent takes message as input and generates corresponding response message.
### Service
Service refers to the functional APIs that enable agents to perform
specific tasks. In AgentScope, services are categorized into model API
services, which are channels to use the LLMs, and general API services,
which provide a variety of tool functions.
### Workflow
Workflow represents ordered sequences of agent executions and message
exchanges between agents, analogous to computational graphs in TensorFlow,
but with the flexibility to accommodate non-DAG structures.
## Why AgentScope?
**Exceptional usability for developers.**
AgentScope provides high usability for developers with flexible syntactic
sugars, ready-to-use components, and pre-built examples.
**Robust fault tolerance for diverse models and APIs.**
AgentScope ensures robust fault tolerance for diverse models, APIs, and
allows developers to build customized fault-tolerant strategies.
**Extensive compatibility for multi-modal application.**
AgentScope supports multi-modal data (e.g., files, images, audio and videos)
in both dialog presentation, message transmission and data storage.
**Optimized efficiency for distributed multi-agent operations.** AgentScope
introduces an actor-based distributed mechanism that enables centralized
programming of complex distributed workflows, and automatic parallel
optimization.
## How is AgentScope designed?
The architecture of AgentScope comprises three hierarchical layers. The
layers provide supports for multi-agent applications from different levels,
including elementary and advanced functionalities of a single agent
(**utility layer**), resources and runtime management (**manager and wrapper
layer**), and agent-level to workflow-level programming interfaces (**agent
layer**). AgentScope introduces intuitive abstractions designed to fulfill
the diverse functionalities inherent to each layer and simplify the
complicated interlayer dependencies when building multi-agent systems.
Furthermore, we offer programming interfaces and default mechanisms to
strengthen the resilience of multi-agent systems against faults within
different layers.
## AgentScope Code Structure
```bash
AgentScope
├── src
│ ├── agentscope
│ | ├── agents # Core components and implementations pertaining to agents.
│ | ├── memory # Structures for agent memory.
│ | ├── models # Interfaces for integrating diverse model APIs.
│ | ├── pipelines # Fundamental components and implementations for running pipelines.
│ | ├── rpc # Rpc module for agent distributed deployment.
│ | ├── service # Services offering functions independent of memory and state.
| | ├── web # WebUI used to show dialogs.
│ | ├── utils # Auxiliary utilities and helper functions.
│ | ├── message.py # Definitions and implementations of messaging between agents.
│ | ├── prompt.py # Prompt engineering module for model input.
│ | ├── ... ..
│ | ├── ... ..
├── scripts # Scripts for launching local Model API
├── examples # Pre-built examples of different applications.
├── docs # Documentation tool for API reference.
├── tests # Unittest modules for continuous integration.
├── LICENSE # The official licensing agreement for AgentScope usage.
└── setup.py # Setup script for installing.
├── ... ..
└── ... ..
```
[[Return to the top]](#101-memoryscope-en)

View file

@ -1,68 +0,0 @@
(102-installation-en)=
# Installation
To install AgentScope, you need to have Python 3.9 or higher installed. We recommend setting up a new virtual environment specifically for AgentScope:
## Create a Virtual Environment
### Using Conda
If you're using Conda as your package and environment management tool, you can create a new virtual environment with Python 3.9 using the following commands:
```bash
# Create a new virtual environment named 'agentscope' with Python 3.9
conda create -n agentscope python=3.9
# Activate the virtual environment
conda activate agentscope
```
### Using Virtualenv
Alternatively, if you prefer `virtualenv`, you can install it first (if it's not already installed) and then create a new virtual environment as shown:
```bash
# Install virtualenv if it is not already installed
pip install virtualenv
# Create a new virtual environment named 'agentscope' with Python 3.9
virtualenv agentscope --python=python3.9
# Activate the virtual environment
source agentscope/bin/activate # On Windows use `agentscope\Scripts\activate`
```
## Installing AgentScope
### Install with Pip
If you prefer to install AgentScope from Pypi, you can do so easily using `pip`:
```bash
# For centralized multi-agent applications
pip install agentscope --pre
# For distributed multi-agent applications
pip install agentscope[distribute] --pre # On Mac use `pip install agentscope\[distribute\] --pre`
```
### Install from Source
For users who prefer to install AgentScope directly from the source code, follow these steps to clone the repository and install the platform in editable mode:
**_Note: This project is under active development, it's recommended to install AgentScope from source._**
```bash
# Pull the source code from Github
git clone https://github.com/modelscope/agentscope.git
cd agentscope
# For centralized multi-agent applications
pip install -e .
# For distributed multi-agent applications
pip install -e .[distribute] # On Mac use `pip install -e .\[distribute\]`
```
**Note**: The `[distribute]` option installs additional dependencies required for distributed applications. Remember to activate your virtual environment before running these commands.
[[Return to the top]](#102-installation-en)

View file

@ -1,108 +0,0 @@
(103-start-en)=
# Quick Start
AgentScope is designed with a flexible communication mechanism.
In this tutorial, we will introduce the basic usage of AgentScope via a
simple standalone conversation between two agents (e.g. user and assistant
agents).
## Step1: Prepare Model
AgentScope decouples the deployment and invocation of models to better build multi-agent applications.
In terms of model deployment, users can use third-party model services such
as OpenAI API, Google Gemini API, HuggingFace/ModelScope Inference API, or
quickly deploy local open-source model services through the [scripts](https://github.com/modelscope/agentscope/blob/main/scripts/README.md) in
the repository.
While for model invocation, users should prepare a model configuration to specify the model service. Taking OpenAI Chat API as an example, the model configuration is like this:
```python
model_config = {
"config_name": "{config_name}", # A unique name for the model config.
"model_type": "openai_chat", # Choose from "openai_chat", "openai_dall_e", or "openai_embedding".
"model_name": "{model_name}", # The model identifier used in the OpenAI API, such as "gpt-3.5-turbo", "gpt-4", or "text-embedding-ada-002".
"api_key": "xxx", # Your OpenAI API key. If unset, the environment variable OPENAI_API_KEY is used.
"organization": "xxx", # Your OpenAI organization ID. If unset, the environment variable OPENAI_ORGANIZATION is used.
}
```
More details about model invocation, deployment and open-source models please refer to [Model](203-model-en) section.
After preparing the model configuration, you can register your configuration by calling the `init` method of AgentScope. Additionally, you can load multiple model configurations at once.
```python
import agentscope
# init once by passing a list of config dict
openai_cfg_dict = {
# ...
}
modelscope_cfg_dict = {
# ...
}
agentscope.init(model_configs=[openai_cfg_dict, modelscope_cfg_dict])
```
## Step2: Create Agents
Creating agents is straightforward in AgentScope. After initializing AgentScope with your model configurations (Step 1 above), you can then define each agent with its corresponding role and specific model.
```python
import agentscope
from agentscope.agents import DialogAgent, UserAgent
# read model configs
agentscope.init(model_configs="./openai_model_configs.json")
# Create a dialog agent and a user agent
dialogAgent = DialogAgent(name="assistant", model_config_name="gpt-4", sys_prompt="You are a helpful ai assistant")
userAgent = UserAgent()
```
**NOTE**: Please refer to [Customizing Your Own Agent](201-agent-en) for all available agents.
## Step3: Agent Conversation
"Message" is the primary means of communication between agents in AgentScope. They are Python dictionaries comprising essential fields like the actual `content` of this message and the sender's `name`. Optionally, a message can include a `url` to either a local file (image, video or audio) or website.
```python
from agentscope.message import Msg
# Example of a simple text message from Alice
message_from_alice = Msg("Alice", "Hi!")
# Example of a message from Bob with an attached image
message_from_bob = Msg("Bob", "What about this picture I took?", url="/path/to/picture.jpg")
```
To start a conversation between two agents, such as `dialog_agent` and `user_agent`, you can use the following loop. The conversation continues until the user inputs `"exit"` which terminates the interaction.
```python
x = None
while True:
x = dialogAgent(x)
x = userAgent(x)
# Terminate the conversation if the user types "exit"
if x.content == "exit":
print("Exiting the conversation.")
break
```
For a more advanced approach, AgentScope offers the option of using pipelines to manage the flow of messages between agents. The `sequentialpipeline` stands for sequential speech, where each agent receive message from last agent and generate its response accordingly.
```python
from agentscope.pipelines.functional import sequentialpipeline
# Execute the conversation loop within a pipeline structure
x = None
while x is None or x.content != "exit":
x = sequentialpipeline([dialog_agent, user_agent])
```
For more details about how to utilize pipelines for complex agent interactions, please refer to [Pipeline and MsgHub](202-pipeline-en).
[[Return to the top]](#103-start-en)

View file

@ -1,15 +0,0 @@
# Welcome to MemoryScope Tutorial
MemoryScope is an innovative multi-agent platform designed to empower developers to build multi-agent applications with ease, reliability, and high performance. It features three high-level capabilities:
- **Easy-to-Use**: Programming in pure Python with various prebuilt components for immediate use, suitable for developers or users with different levels of customization requirements.
- **High Robustness**: Supporting customized fault-tolerance controls and retry mechanisms to enhance application stability.
- **Actor-Based Distribution**: Enabling developers to build distributed multi-agent applications in a centralized programming manner for streamlined development.
## Tutorial Navigator
- [About MemoryScope](101-memoryscope.md)
- [Installation](102-installation.md)
- [Quick Start](103-example.md)

View file

@ -9,4 +9,5 @@ sphinx-autobuild
sphinx_rtd_theme
sphinxcontrib-mermaid
myst-parser
autodoc_pydantic
autodoc_pydantic
nbsphinx

View file

@ -39,11 +39,12 @@ extensions = [
"sphinxcontrib.mermaid",
"myst_parser",
"sphinx.ext.autosectionlabel",
'sphinxcontrib.autodoc_pydantic'
"sphinxcontrib.autodoc_pydantic",
"nbsphinx"
]
autodoc_pydantic_model_show_json = True
autodoc_pydantic_settings_show_json = True
autodoc_pydantic_settings_show_json = True
# Prefix document path to section labels, otherwise autogenerated labels would
# look like 'heading' rather than 'path/to/file:heading'
@ -82,12 +83,15 @@ exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]
#
html_theme = "sphinx_rtd_theme"
# html_logo = "_static/logo.png"
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ["_static"]
html_theme_options = {
# "logo_only": True,
"navigation_depth": 4,
}

View file

@ -6,24 +6,44 @@
:github_url: https://github.com/modelscope/memoryscope
MemoryScope 文档
======================================
=========================
欢迎浏览MemoryScope相关文档
-------------------------------
.. include:: tutorial/main.md
:parser: myst_parser.sphinx_
.. image:: ./docs/images/logo_1.png
:align: center
MemoryScope 是一个为LLM聊天机器人服务的强大且灵活的长期记忆系统。它由一个记忆数据库和三个可定制的系统操作组成这些操作可以灵活组合
为您的LLM聊天机器人提供强大的长期记忆服务。
💾 记忆数据库:
^^^^^^^^^^^^^
- MemoryScope 配备了一个 *ElasticSearch (ES)* 向量数据库,用于存储系统中记录的所有记忆片段。
🛠️ 系统操作:
^^^^^^^^^^^^
- 记忆检索:当用户输入对话,此操作返回语义相关的记忆片段。如果输入对话包含对时间的指涉,则同时返回相应时间中的记忆片段。
-
- 记忆巩固:此操作接收一批用户的输入对话,并从对话中提取重要的用户信息,将其作为 *observation* 形式的记忆片段存储在记忆数据库中。
-
- 反思与再巩固:每隔一段时间,此操作对新记录的 *observations* 进行反思,以形成和更新 *insight* 形式的记忆片段。然后执行记忆再巩固,
以确保记忆片段之间的矛盾和重复得到妥善处理。
.. toctree::
:maxdepth: 1
:glob:
:hidden:
:caption: MemoryScope Tutorial
:maxdepth: 2
:caption: MemoryScope 教程
tutorial/101-memoryscope.md
tutorial/102-installation.md
tutorial/103-example.md
关于MemoryScope <README.md>
🚀 安装 <docs/installation.md>
命令行 <examples/cli/README.md>
简例 <examples/api/simple_usages_cn.ipynb>
.. toctree::
:maxdepth: 4
:caption: MemoryScope API 文档
:maxdepth: 6
:caption: MemoryScope 接口
API <docs/api.rst>
api

View file

@ -1,7 +0,0 @@
(101-memoryscope-cn)=
# 关于memoryscope
TODO: 添加中文文档
[[Return to the top]](#101-memoryscope-cn)

View file

@ -1,7 +0,0 @@
(102-installation-cn)=
# 安装memoryscope
TODO: 添加中文文档
[[Return to the top]](#102-installation-cn)

View file

@ -1,6 +0,0 @@
(103-start-cn)=
# 如何使用
TODO: 添加中文
[[Return to the top]](#103-start-cn)

View file

@ -1,15 +0,0 @@
# 欢迎来到 MemoryScope 教程
AgentScope是一款全新的Multi-Agent框架专为应用开发者打造旨在提供高易用、高可靠的编程体验
- **高易用**AgentScope支持纯Python编程提供多种语法工具实现灵活的应用流程编排内置丰富的API服务Service以及应用样例供开发者直接使用。
- **高鲁棒**确保开发便捷性和编程效率的同时针对不同能力的大模型AgentScope提供了全面的重试机制、定制化的容错控制和面向Agent的异常处理以确保应用的稳定、高效运行
- **基于Actor的分布式机制**AgentScope设计了一种新的基于Actor的分布式机制实现了复杂分布式工作流的集中式编程和自动并行优化即用户可以使用中心化编程的方式完成分布式应用的流程编排同时能够零代价将本地应用迁移到分布式的运行环境中。
## 教程大纲
- [关于AgentScope](101-memoryscope.md)
- [安装](102-installation.md)
- [快速开始](103-example.md)

View file

@ -2,9 +2,7 @@
"cells": [
{
"cell_type": "markdown",
"metadata": {
"collapsed": false
},
"metadata": {},
"source": [
"# chat 和 service 接口的示例用法\n",
"这个笔记本展示了 MemoryScope 的 **chat** 和 **service** 接口的简单用法,以及它的主要功能。\n",
@ -14,9 +12,7 @@
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": false
},
"metadata": {},
"source": [
"## 初始化一个 MemoryScope 实例\n",
"首先,我们需要指定一个配置并初始化一个 MemoryScope 实例。\n",
@ -26,14 +22,8 @@
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"ExecuteTime": {
"end_time": "2024-08-02T14:42:19.303078Z",
"start_time": "2024-08-02T14:42:17.332785Z"
},
"collapsed": false
},
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import sys\n",
@ -59,9 +49,7 @@
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": false
},
"metadata": {},
"source": [
"## 聊天(不含记忆)\n",
"MemoryScope 配有默认的 chat 接口,因此开始聊天非常容易,就像使用任何大型语言模型聊天机器人一样。"
@ -69,14 +57,8 @@
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"ExecuteTime": {
"end_time": "2024-08-02T14:42:24.843842Z",
"start_time": "2024-08-02T14:42:19.304038Z"
},
"collapsed": false
},
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
@ -96,9 +78,7 @@
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": false
},
"metadata": {},
"source": [
"----\n",
"你可以选择进行含有或不含有多轮对话上下文的聊天。然而,由于尚未调用**记忆巩固**功能,系统中还没有任何记忆片段。"
@ -106,14 +86,8 @@
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"ExecuteTime": {
"end_time": "2024-08-02T14:42:33.777924Z",
"start_time": "2024-08-02T14:42:24.845133Z"
},
"collapsed": false
},
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
@ -136,9 +110,7 @@
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": false
},
"metadata": {},
"source": [
"## **记忆巩固**\n",
"现在,我们再聊多几句,然后尝试**记忆巩固**功能。"
@ -146,14 +118,8 @@
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"ExecuteTime": {
"end_time": "2024-08-02T14:42:52.517936Z",
"start_time": "2024-08-02T14:42:33.780200Z"
},
"collapsed": false
},
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
@ -183,14 +149,8 @@
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"ExecuteTime": {
"end_time": "2024-08-02T14:43:14.475175Z",
"start_time": "2024-08-02T14:42:52.518868Z"
},
"collapsed": false
},
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
@ -212,9 +172,7 @@
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": false
},
"metadata": {},
"source": [
"----\n",
"**记忆巩固**从用户的7条聊天消息中提取了3条 *observations* ,其余无效的信息被过滤掉了。\n",
@ -224,14 +182,8 @@
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"ExecuteTime": {
"end_time": "2024-08-02T14:43:57.226685Z",
"start_time": "2024-08-02T14:43:14.475977Z"
},
"collapsed": false
},
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
@ -283,14 +235,8 @@
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"ExecuteTime": {
"end_time": "2024-08-02T14:44:26.290389Z",
"start_time": "2024-08-02T14:43:57.227597Z"
},
"collapsed": false
},
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
@ -309,9 +255,7 @@
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": false
},
"metadata": {},
"source": [
"----\n",
"我们可以看到,**记忆巩固**成功过滤掉了虚假内容,并展示了良好的时间敏感性。\n",
@ -321,14 +265,8 @@
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"ExecuteTime": {
"end_time": "2024-08-02T14:44:57.748723Z",
"start_time": "2024-08-02T14:44:26.292543Z"
},
"collapsed": false
},
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
@ -370,14 +308,8 @@
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {
"ExecuteTime": {
"end_time": "2024-08-02T14:45:38.454853Z",
"start_time": "2024-08-02T14:44:57.750558Z"
},
"collapsed": false
},
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
@ -401,9 +333,7 @@
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": false
},
"metadata": {},
"source": [
"## **反思与再巩固**\n",
"现在,我们在系统中已经积累了足够多的新的 *observations* ,因此我们可以调用**反思与再巩固**功能,让我们看看会得到什么。"
@ -411,14 +341,8 @@
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {
"ExecuteTime": {
"end_time": "2024-08-02T14:45:52.599528Z",
"start_time": "2024-08-02T14:45:38.455556Z"
},
"collapsed": false
},
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
@ -447,9 +371,7 @@
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": false
},
"metadata": {},
"source": [
"## 低用户时延RT\n",
"\n",
@ -459,9 +381,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"import time\n",
@ -483,14 +403,8 @@
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {
"ExecuteTime": {
"end_time": "2024-08-02T14:46:08.814486Z",
"start_time": "2024-08-02T14:45:52.601688Z"
},
"collapsed": false
},
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
@ -540,9 +454,7 @@
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": false
},
"metadata": {},
"source": [
"----\n",
"我们可以看到,从 MemoryScope 检索记忆片段不会增加聊天的响应时间。"
@ -550,24 +462,13 @@
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": false
},
"metadata": {},
"source": [
"## 更多用法\n",
"我们建议读者参考[进阶自定义用法](./examples/api/advanced_customization_cn.ipynb)来对MemoryScope系统进行各种自定义设置。您还可以通过自定义**workflow**和对应的**worker**来创建或定制满足您特定需求的**operation**。\n",
"\n",
"此外,您还可以尝试使用[在命令行与MemoryScope聊天机器人交互](./examples/cli/dash_cli_cn1.sh)。我们在这里实现了始终在后台异步运行**记忆巩固**和**反思与再巩固**这两个操作,从而使得它们不会增加聊天的响应时间。"
"此外,您还可以尝试使用[在命令行与MemoryScope聊天机器人交互](../cli/README.md)。我们在这里实现了始终在后台异步运行**记忆巩固**和**反思与再巩固**这两个操作,从而使得它们不会增加聊天的响应时间。"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": []
}
],
"metadata": {
@ -585,8 +486,7 @@
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.6"
"pygments_lexer": "ipython2"
}
},
"nbformat": 4,

View file

@ -2,9 +2,7 @@
"cells": [
{
"cell_type": "markdown",
"metadata": {
"collapsed": false
},
"metadata": {},
"source": [
"# Example usages of **chat** and **service** interfaces\n",
"This notebook shows simple usages of MemoryScope's **chat** and **service** interfaces, along with its main features.\n",
@ -14,9 +12,7 @@
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": false
},
"metadata": {},
"source": [
"## Initiate a MemoryScope instance\n",
"First, we need to specify a configuration and initiate a MemoryScope instance.\n",
@ -25,14 +21,8 @@
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"ExecuteTime": {
"end_time": "2024-08-02T14:34:30.387354Z",
"start_time": "2024-08-02T14:34:28.512658Z"
},
"collapsed": false
},
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import sys\n",
@ -58,9 +48,7 @@
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": false
},
"metadata": {},
"source": [
"## Chat without memory\n",
"MemoryScope comes with a default **chat** interface, so it's very easy to start chatting, just as what you'll do with any LLM chatbot."
@ -68,14 +56,8 @@
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"ExecuteTime": {
"end_time": "2024-08-02T14:34:35.313590Z",
"start_time": "2024-08-02T14:34:30.388733Z"
},
"collapsed": false
},
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
@ -95,9 +77,7 @@
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": false
},
"metadata": {},
"source": [
"----\n",
"You can choose to chat with or without multi-round conversation contexts. However, since **Memory Consolidation** has not been called, there's no memory pieces in the system yet."
@ -105,14 +85,8 @@
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"ExecuteTime": {
"end_time": "2024-08-02T14:34:42.621918Z",
"start_time": "2024-08-02T14:34:35.315441Z"
},
"collapsed": false
},
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
@ -135,9 +109,7 @@
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": false
},
"metadata": {},
"source": [
"## Memory Consolidation\n",
"Now, we do a bit more chatting and then try out **Memory Consolidation**."
@ -145,14 +117,8 @@
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"ExecuteTime": {
"end_time": "2024-08-02T14:35:07.399702Z",
"start_time": "2024-08-02T14:34:42.622804Z"
},
"collapsed": false
},
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
@ -182,14 +148,8 @@
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"ExecuteTime": {
"end_time": "2024-08-02T14:35:42.560772Z",
"start_time": "2024-08-02T14:35:07.401224Z"
},
"collapsed": false
},
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
@ -211,9 +171,7 @@
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": false
},
"metadata": {},
"source": [
"----\n",
"**Memory Consolidation** extracted 3 *observations* out of the 7 chat messages from the user, with the uninformative ones being filtered out.\n",
@ -223,14 +181,8 @@
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"ExecuteTime": {
"end_time": "2024-08-02T14:36:30.548435Z",
"start_time": "2024-08-02T14:35:42.559854Z"
},
"collapsed": false
},
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
@ -294,14 +246,8 @@
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"ExecuteTime": {
"end_time": "2024-08-02T14:37:04.220392Z",
"start_time": "2024-08-02T14:36:30.549719Z"
},
"collapsed": false
},
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
@ -322,9 +268,7 @@
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": false
},
"metadata": {},
"source": [
"----\n",
"We can see **Memory Consolidation** successfully filtered out fictitious contents, and shows good time sensitivity.\n",
@ -334,14 +278,8 @@
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"ExecuteTime": {
"end_time": "2024-08-02T14:37:25.239829Z",
"start_time": "2024-08-02T14:37:04.221032Z"
},
"collapsed": false
},
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
@ -383,14 +321,8 @@
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {
"ExecuteTime": {
"end_time": "2024-08-02T14:38:05.369583Z",
"start_time": "2024-08-02T14:37:25.241674Z"
},
"collapsed": false
},
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
@ -413,9 +345,7 @@
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": false
},
"metadata": {},
"source": [
"## Reflection and Re-Consolidation\n",
"Now, we have accumulated enough new *observations* in the system, so we can call **Reflection and Re-Consolidation**, let's see what will it get."
@ -423,14 +353,8 @@
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {
"ExecuteTime": {
"end_time": "2024-08-02T14:38:27.126860Z",
"start_time": "2024-08-02T14:38:05.370326Z"
},
"collapsed": false
},
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
@ -463,9 +387,7 @@
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": false
},
"metadata": {},
"source": [
"## Low response-time (RT) for the user\n",
"Finally, we test the RT of MemoryScope system for the user. Specifically, we test the difference of RT when responding with and without retrieving memory pieces from the system."
@ -474,9 +396,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"import time\n",
@ -498,14 +418,8 @@
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {
"ExecuteTime": {
"end_time": "2024-08-02T14:38:46.158169Z",
"start_time": "2024-08-02T14:38:27.128634Z"
},
"collapsed": false
},
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
@ -557,9 +471,7 @@
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": false
},
"metadata": {},
"source": [
"----\n",
"We can see responding with retrieving memory pieces from MemoryScope does not increase RT."
@ -567,25 +479,14 @@
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": false
},
"metadata": {},
"source": [
"## More Examples\n",
"We direct the reader to [Advanced Customization](./examples/api/advanced_customization_en.ipynb) for guidance on customizing the various settings of the MemoryScope system. It is also possible to create or customize your own MemoryScope **operations** by specifying a **workflow** and the corresponding **workers** that best meet your specific needs.\n",
"\n",
"Additionally, you can also try out the [CLI with a MemoryScope Chatbot](./examples/cli/dash_cli_cn1.sh). We have implemented the chatbot so that the **Memory Consolidation** and **Reflection and Re-Consolidation** operations are always run asynchronously in the backend, ensuring that they do not incur any response time for the user.\n",
"Additionally, you can also try out the [CLI with a MemoryScope Chatbot](../cli/README.md). We have implemented the chatbot so that the **Memory Consolidation** and **Reflection and Re-Consolidation** operations are always run asynchronously in the backend, ensuring that they do not incur any response time for the user.\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": []
}
],
"metadata": {
@ -603,8 +504,7 @@
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.6"
"pygments_lexer": "ipython2"
}
},
"nbformat": 4,