init
This commit is contained in:
41
AlgoriAgent/examples/distributed_conversation/README.md
Normal file
41
AlgoriAgent/examples/distributed_conversation/README.md
Normal file
@@ -0,0 +1,41 @@
|
||||
# Distributed Conversation
|
||||
|
||||
This example will show
|
||||
- How to set up and run a distributed conversation.
|
||||
- How to configure and use different language models in the system.
|
||||
|
||||
## Background
|
||||
|
||||
This example demonstrates a distributed dialog system leveraging various language models. The system is designed to handle conversational AI tasks in a distributed manner, allowing for scalable and efficient dialog management.
|
||||
|
||||
## Tested Models
|
||||
|
||||
These models are tested in this example. For other models, some modifications may be needed.
|
||||
- Ollama Chat (llama3_8b)
|
||||
- Dashscope Chat (qwen-Max)
|
||||
- Gemini Chat (gemini-pro)
|
||||
|
||||
## Prerequisites
|
||||
|
||||
Before running the example, please install the distributed version of Agentscope, fill in your model configuration correctly in `configs/model_configs.json`, and modify the `model_config_name` field in `distributed_dialog.py` accordingly.
|
||||
|
||||
## Running the Example
|
||||
Use the following command to start the assistant agent:
|
||||
|
||||
```
|
||||
cd examples/distributed_basic
|
||||
python distributed_dialog.py --role assistant --assistant-host localhost --assistant-port 12010
|
||||
# Please make sure the port is available.
|
||||
# If the assistant agent and the user agent are started on different machines,
|
||||
# please fill in the ip address of the assistant agent in the host field
|
||||
```
|
||||
|
||||
Then, run the user agent:
|
||||
|
||||
```
|
||||
python distributed_dialog.py --role user --assistant-host localhost --assistant-port 12010
|
||||
# If the assistant agent is started on another machine,
|
||||
# please fill in the ip address of the assistant agent in the host field
|
||||
```
|
||||
|
||||
Now, you can chat with the assistant agent using the command line.
|
||||
@@ -0,0 +1,21 @@
|
||||
[
|
||||
{
|
||||
"config_name": "gpt-4",
|
||||
"model_type": "openai_chat",
|
||||
"model_name": "gpt-4",
|
||||
"api_key": "xxx",
|
||||
"organization": "xxx",
|
||||
"generate_args": {
|
||||
"temperature": 0.5
|
||||
}
|
||||
},
|
||||
{
|
||||
"config_name": "qwen",
|
||||
"model_type": "dashscope_chat",
|
||||
"model_name": "qwen-max",
|
||||
"api_key": "xxx",
|
||||
"generate_args": {
|
||||
"temperature": 0.5
|
||||
}
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1,83 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
""" An example of distributed dialog """
|
||||
|
||||
import argparse
|
||||
from loguru import logger
|
||||
|
||||
import agentscope
|
||||
from agentscope.agents.user_agent import UserAgent
|
||||
from agentscope.agents.dialog_agent import DialogAgent
|
||||
from agentscope.server import RpcAgentServerLauncher
|
||||
|
||||
|
||||
def parse_args() -> argparse.Namespace:
|
||||
"""Parse arguments"""
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument(
|
||||
"--role",
|
||||
choices=["assistant", "user"],
|
||||
default="user",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--assistant-port",
|
||||
type=int,
|
||||
default=12010,
|
||||
)
|
||||
parser.add_argument(
|
||||
"--assistant-host",
|
||||
type=str,
|
||||
default="localhost",
|
||||
)
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
def setup_assistant_server(assistant_host: str, assistant_port: int) -> None:
|
||||
"""Set up assistant rpc server"""
|
||||
agentscope.init(
|
||||
model_configs="configs/model_configs.json",
|
||||
project="Distributed Conversation",
|
||||
)
|
||||
assistant_server_launcher = RpcAgentServerLauncher(
|
||||
host=assistant_host,
|
||||
port=assistant_port,
|
||||
)
|
||||
assistant_server_launcher.launch()
|
||||
assistant_server_launcher.wait_until_terminate()
|
||||
|
||||
|
||||
def run_main_process(assistant_host: str, assistant_port: int) -> None:
|
||||
"""Run dialog main process"""
|
||||
agentscope.init(
|
||||
model_configs="configs/model_configs.json",
|
||||
project="Distributed Conversation",
|
||||
)
|
||||
assistant_agent = DialogAgent(
|
||||
name="Assistant",
|
||||
sys_prompt="You are a helpful assistant.",
|
||||
model_config_name="qwen",
|
||||
use_memory=True,
|
||||
).to_dist(
|
||||
host=assistant_host,
|
||||
port=assistant_port,
|
||||
)
|
||||
user_agent = UserAgent(
|
||||
name="User",
|
||||
require_url=False,
|
||||
)
|
||||
logger.info(
|
||||
"Setup successfully, have fun chatting! (enter 'exit' to close the "
|
||||
"agent)",
|
||||
)
|
||||
msg = user_agent()
|
||||
while not msg.content.endswith("exit"):
|
||||
msg = assistant_agent(msg)
|
||||
logger.chat(msg)
|
||||
msg = user_agent(msg)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
args = parse_args()
|
||||
if args.role == "assistant":
|
||||
setup_assistant_server(args.assistant_host, args.assistant_port)
|
||||
elif args.role == "user":
|
||||
run_main_process(args.assistant_host, args.assistant_port)
|
||||
Reference in New Issue
Block a user