mirror of
https://github.com/agentscope-ai/ReMe.git
synced 2026-10-06 02:48:22 +00:00
modify en zh docs
This commit is contained in:
parent
8b4ccb6f3f
commit
e780670381
12 changed files with 103 additions and 64 deletions
|
|
@ -1,13 +1,14 @@
|
|||
# Installing MemoryScope
|
||||
|
||||
## I. Install with docker [Recommended]
|
||||
|
||||
1. Clone the repository and edit settings
|
||||
```bash
|
||||
# clone project
|
||||
git clone https://github.com/modelscope/memoryscope
|
||||
cd memoryscope
|
||||
# edit configuration, e.g. add api keys
|
||||
vim memoryscope/core/config/demo_config_zh.yaml
|
||||
vim memoryscope/core/config/demo_config.yaml
|
||||
```
|
||||
|
||||
2. Build Docker image
|
||||
|
|
@ -15,7 +16,6 @@
|
|||
sudo docker build --network=host -t memoryscope .
|
||||
```
|
||||
|
||||
|
||||
3. Launch Docker container
|
||||
```bash
|
||||
sudo docker run -it --rm --net=host memoryscope
|
||||
|
|
@ -24,31 +24,29 @@
|
|||
|
||||
## II. Install with docker compose [Recommended]
|
||||
|
||||
|
||||
1. Clone the repository and edit settings
|
||||
```bash
|
||||
# clone project
|
||||
git clone https://github.com/modelscope/memoryscope
|
||||
cd memoryscope
|
||||
# edit configuration, e.g. add api keys
|
||||
vim memoryscope/core/config/demo_config_zh.yaml
|
||||
vim memoryscope/core/config/demo_config.yaml
|
||||
```
|
||||
|
||||
|
||||
2. Edit `docker-compose.yml` to change environment variable.
|
||||
```
|
||||
DASHSCOPE_API_KEY: "sk-0000000000"
|
||||
OPENAI_API_KEY: "sk-0000000000"
|
||||
```
|
||||
|
||||
3. Run `docker-compose up` to build and launch the memory-scope cli interface.
|
||||
|
||||
|
||||
## III. Install from PyPI
|
||||
1. Install from PyPI
|
||||
|
||||
```bash
|
||||
pip install memoryscope
|
||||
```
|
||||
1. Install from PyPI
|
||||
```bash
|
||||
pip install memoryscope
|
||||
```
|
||||
|
||||
2. Run Elasticsearch service, refer to [elasticsearch documents](https://www.elastic.co/guide/en/elasticsearch/reference/current/getting-started.html).
|
||||
The docker method is recommended:
|
||||
|
|
@ -98,7 +96,7 @@ The docker method is recommended:
|
|||
git clone https://github.com/modelscope/memoryscope
|
||||
cd memoryscope
|
||||
# edit configuration, e.g. add api keys
|
||||
vim memoryscope/core/config/demo_config_zh.yaml
|
||||
vim memoryscope/core/config/demo_config.yaml
|
||||
```
|
||||
|
||||
2. Install
|
||||
|
|
@ -118,6 +116,6 @@ The docker method is recommended:
|
|||
|
||||
4. Launch memoryscope, also refer to [cli documents](../examples/cli/README.md)
|
||||
```bash
|
||||
export DASHSCOPE_API_KEY="sk-0000000000"
|
||||
export OPENAI_API_KEY="sk-0000000000"
|
||||
python quick-start-demo.py --config_path=memoryscope/core/config/demo_config_zh.yaml
|
||||
```
|
||||
|
|
@ -11,7 +11,7 @@ MemoryScope Documentation
|
|||
Welcome to MemoryScope Tutorial
|
||||
-------------------------------
|
||||
|
||||
.. image:: docs/images/logo_1.png
|
||||
.. image:: docs/images/logo.png
|
||||
:align: center
|
||||
|
||||
MemoryScope is a powerful and flexible long term memory system for LLM chatbots. It consists
|
||||
|
|
|
|||
|
|
@ -1,49 +1,49 @@
|
|||
# Custom Operator and Worker
|
||||
|
||||
# 自定义 Operator 和 Worker
|
||||
|
||||
1. 在 `contrib` 路径下创建新worker,命名为 `example_query_worker.py`:
|
||||
1. Create a new worker named `example_query_worker.py` in the `contrib` directory:
|
||||
```bash
|
||||
vim memoryscope/contrib/example_query_worker.py
|
||||
```
|
||||
|
||||
2. 写入新的自定义worker的程序,注意`class`的命名需要与文件名保持一致,为`ExampleQueryWorker`:
|
||||
2. Write the program for the new custom worker. Note that the class name must match the filename, which is `ExampleQueryWorker`:
|
||||
```python
|
||||
import datetime
|
||||
|
||||
from memoryscope.constants.common_constants import QUERY_WITH_TS
|
||||
from memoryscope.core.worker.memory_base_worker import MemoryBaseWorker
|
||||
|
||||
|
||||
class ExampleQueryWorker(MemoryBaseWorker):
|
||||
|
||||
def _run(self):
|
||||
|
||||
timestamp = int(datetime.datetime.now().timestamp()) # Current timestamp as default
|
||||
|
||||
assert "query" in self.chat_kwargs
|
||||
query = self.chat_kwargs["query"]
|
||||
if not query:
|
||||
query = ""
|
||||
else:
|
||||
query = query.strip() + "\n You must add a `meow~` at the end of each of your answer."
|
||||
|
||||
query = query.strip() + "\n You must add a `meow~` at the end of each of your answers."
|
||||
# Store the determined query and its timestamp in the context
|
||||
self.set_workflow_context(QUERY_WITH_TS, (query, timestamp))
|
||||
```
|
||||
|
||||
3. 创建yaml启动文件(复制demo_config.yaml)
|
||||
3. Create a YAML startup file (copying `demo_config.yaml`):
|
||||
```
|
||||
cp memoryscope/core/config/demo_config.yaml examples/advance/replacement.yaml
|
||||
vim examples/advance/replacement.yaml
|
||||
```
|
||||
|
||||
4. 在最下面插入新worker的定义,并且取代之前的默认`set_query`worker
|
||||
4. At the bottom, insert the definition for the new worker and replace the previous default `set_query` worker, and update the operation's workflow:
|
||||
```
|
||||
set_query_meow:
|
||||
rewrite_query:
|
||||
class: contrib.example_query_worker
|
||||
generation_model: generation_model
|
||||
```
|
||||
```
|
||||
retrieve_memory:
|
||||
class: core.operation.frontend_operation
|
||||
workflow: rewrite_query,[extract_time|retrieve_obs_ins,semantic_rank],fuse_rerank
|
||||
description: "retrieve long-term memory"
|
||||
```
|
||||
|
||||
5. 验证:
|
||||
5. Verify:
|
||||
```
|
||||
python quick-start-demo.py --config examples/advance/replacement.yaml
|
||||
```
|
||||
```
|
||||
53
examples/advance/custom_operator_zh.md
Normal file
53
examples/advance/custom_operator_zh.md
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
# 自定义 Operator 和 Worker
|
||||
|
||||
1. 在 `contrib` 路径下创建新worker,命名为 `example_query_worker.py`:
|
||||
```bash
|
||||
vim memoryscope/contrib/example_query_worker.py
|
||||
```
|
||||
|
||||
2. 写入新的自定义worker的程序,注意`class`的命名需要与文件名保持一致,为`ExampleQueryWorker`:
|
||||
```python
|
||||
import datetime
|
||||
from memoryscope.constants.common_constants import QUERY_WITH_TS
|
||||
from memoryscope.core.worker.memory_base_worker import MemoryBaseWorker
|
||||
|
||||
class ExampleQueryWorker(MemoryBaseWorker):
|
||||
|
||||
def _run(self):
|
||||
|
||||
timestamp = int(datetime.datetime.now().timestamp()) # Current timestamp as default
|
||||
|
||||
assert "query" in self.chat_kwargs
|
||||
query = self.chat_kwargs["query"]
|
||||
if not query:
|
||||
query = ""
|
||||
else:
|
||||
query = query.strip() + "\n You must add a `meow~` at the end of each of your answer."
|
||||
|
||||
# Store the determined query and its timestamp in the context
|
||||
self.set_workflow_context(QUERY_WITH_TS, (query, timestamp))
|
||||
```
|
||||
|
||||
3. 创建yaml启动文件(复制demo_config_zh.yaml)
|
||||
```
|
||||
cp memoryscope/core/config/demo_config_zh.yaml examples/advance/replacement.yaml
|
||||
vim examples/advance/replacement.yaml
|
||||
```
|
||||
|
||||
4. 在最下面插入新worker的定义,并且取代之前的默认`set_query`worker,并替换operation的workflow
|
||||
```
|
||||
rewrite_query:
|
||||
class: contrib.example_query_worker
|
||||
generation_model: generation_model
|
||||
```
|
||||
```
|
||||
retrieve_memory:
|
||||
class: core.operation.frontend_operation
|
||||
workflow: rewrite_query,[extract_time|retrieve_obs_ins,semantic_rank],fuse_rerank
|
||||
description: "retrieve long-term memory"
|
||||
```
|
||||
|
||||
5. 验证:
|
||||
```
|
||||
python quick-start-demo.py --config examples/advance/replacement.yaml
|
||||
```
|
||||
|
|
@ -34,11 +34,10 @@ class MemoryScopeAgent(AgentBase):
|
|||
|
||||
|
||||
def main():
|
||||
|
||||
# Setting of MemoryScope
|
||||
arguments = Arguments(
|
||||
language="cn",
|
||||
human_name="User",
|
||||
human_name="用户",
|
||||
assistant_name="AI",
|
||||
memory_chat_class="api_memory_chat",
|
||||
generation_backend="dashscope_generation",
|
||||
|
|
@ -46,19 +45,12 @@ def main():
|
|||
embedding_backend="dashscope_embedding",
|
||||
embedding_model="text-embedding-v2",
|
||||
rank_backend="dashscope_rank",
|
||||
rank_model="gte-rerank"
|
||||
)
|
||||
rank_model="gte-rerank")
|
||||
|
||||
# Initialize AgentScope
|
||||
agentscope.init(
|
||||
project="MemoryScope",
|
||||
agentscope.init(project="MemoryScope")
|
||||
|
||||
)
|
||||
|
||||
memoryscope_agent = MemoryScopeAgent(
|
||||
name="Assistant",
|
||||
arguments=arguments
|
||||
)
|
||||
memoryscope_agent = MemoryScopeAgent(name="Assistant", arguments=arguments)
|
||||
|
||||
user_agent = UserAgent()
|
||||
|
||||
|
|
|
|||
|
|
@ -7,13 +7,13 @@ from memoryscope import MemoryScope, Arguments
|
|||
|
||||
class MemoryScopeAgent(ConversableAgent):
|
||||
def __init__(
|
||||
self,
|
||||
name: str = "assistant",
|
||||
system_message: Optional[str] = "",
|
||||
human_input_mode: Literal["ALWAYS", "NEVER", "TERMINATE"] = "NEVER",
|
||||
llm_config: Optional[Union[Dict, bool]] = None,
|
||||
arguments: Arguments = None,
|
||||
**kwargs,
|
||||
self,
|
||||
name: str = "assistant",
|
||||
system_message: Optional[str] = "",
|
||||
human_input_mode: Literal["ALWAYS", "NEVER", "TERMINATE"] = "NEVER",
|
||||
llm_config: Optional[Union[Dict, bool]] = None,
|
||||
arguments: Arguments = None,
|
||||
**kwargs,
|
||||
):
|
||||
super().__init__(
|
||||
name=name,
|
||||
|
|
@ -29,12 +29,11 @@ class MemoryScopeAgent(ConversableAgent):
|
|||
|
||||
self.register_reply([Agent, None], MemoryScopeAgent.generate_reply_with_memory, remove_other_reply_funcs=True)
|
||||
|
||||
|
||||
def generate_reply_with_memory(
|
||||
self,
|
||||
messages: Optional[List[Dict]] = None,
|
||||
sender: Optional[Agent] = None,
|
||||
config: Optional[Any] = None,
|
||||
self,
|
||||
messages: Optional[List[Dict]] = None,
|
||||
sender: Optional[Agent] = None,
|
||||
config: Optional[Any] = None,
|
||||
) -> Tuple[bool, Union[str, Dict, None]]:
|
||||
# Generate response
|
||||
|
||||
|
|
@ -50,11 +49,12 @@ class MemoryScopeAgent(ConversableAgent):
|
|||
def close(self):
|
||||
self.memory_scope.close()
|
||||
|
||||
|
||||
def main():
|
||||
# Create the agent of MemoryScope
|
||||
arguments = Arguments(
|
||||
language="cn",
|
||||
human_name="User",
|
||||
human_name="用户",
|
||||
assistant_name="AI",
|
||||
memory_chat_class="api_memory_chat",
|
||||
generation_backend="dashscope_generation",
|
||||
|
|
@ -71,7 +71,7 @@ def main():
|
|||
user_proxy = UserProxyAgent("user", code_execution_config=False)
|
||||
|
||||
# Let the assistant start the conversation. It will end when the user types exit.
|
||||
assistant.initiate_chat(user_proxy, message="How can I help you today?")
|
||||
assistant.initiate_chat(user_proxy, message="有什么需要帮忙的吗?")
|
||||
assistant.close()
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,19 +1,17 @@
|
|||
import sys
|
||||
sys.path.append(".")
|
||||
from memoryscope import MemoryScope, Arguments
|
||||
|
||||
arguments = Arguments(
|
||||
language="cn",
|
||||
human_name="User",
|
||||
human_name="用户",
|
||||
assistant_name="AI",
|
||||
memory_chat_class="api_memory_chat",
|
||||
generation_backend="dashscope_generation",
|
||||
generation_model="qwen2-72b-instruct",
|
||||
generation_model="qwen-max",
|
||||
embedding_backend="dashscope_embedding",
|
||||
embedding_model="text-embedding-v2",
|
||||
rank_backend="dashscope_rank",
|
||||
rank_model="gte-rerank",
|
||||
enable_ranker=False)
|
||||
enable_ranker=True)
|
||||
|
||||
|
||||
def chat_example1():
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ MemoryScope 可以通过两种不同的方式启动:
|
|||
|
||||
如果您更喜欢通过 YAML 文件配置设置,可以通过提供配置文件的路径来实现:
|
||||
```bash
|
||||
memoryscope --config_path=memoryscope/core/config/demo_config.yaml
|
||||
memoryscope --config_path=memoryscope/core/config/demo_config_zh.yaml
|
||||
```
|
||||
|
||||
### 2. 使用命令行参数
|
||||
|
|
@ -28,7 +28,6 @@ memoryscope --language="cn" \
|
|||
--enable_ranker=True \
|
||||
--rank_backend="dashscope_rank" \
|
||||
--rank_model="gte-rerank"
|
||||
|
||||
# 英文
|
||||
memoryscope --language="en" \
|
||||
--memory_chat_class="cli_memory_chat" \
|
||||
|
|
@ -40,7 +39,6 @@ memoryscope --language="en" \
|
|||
--embedding_model="text-embedding-3-small" \
|
||||
--enable_ranker=False
|
||||
```
|
||||
|
||||
|
||||
以下是可以通过任一方法设置的可用选项:
|
||||
|
||||
|
|
@ -54,4 +52,4 @@ memoryscope --language="en" \
|
|||
- `--embedding_model`: 用于创建文本嵌入的模型。
|
||||
- `--enable_ranker`: 一个布尔值,指示是否使用排名器(默认为 False)。
|
||||
- `--rank_backend`: 用于排名回复的后端。
|
||||
- `--rank_model`: 用于排名回复的模型。
|
||||
- `--rank_model`: 用于排名回复的模型。
|
||||
Loading…
Add table
Reference in a new issue