This commit is contained in:
CakeCN
2024-12-03 16:21:19 +08:00
commit 4198ca63b1
975 changed files with 333413 additions and 0 deletions

View File

@@ -0,0 +1,21 @@
# Multi-Agent Conversation in AgentScope
This example will show how to program a multi-agent conversation in AgentScope.
Complete code is in `conversation.py`, which set up a user agent and an
assistant agent to have a conversation. When user input "exit", the
conversation ends.
You can modify the `sys_prompt` to change the role of assistant agent.
```bash
# Note: Set your api_key in conversation.py first
python conversation.py
```
## Tested Models
These models are tested in this example. For other models, some modifications may be needed.
- dashscope_chat (qwen-max)
- ollama_chat (ollama_llama3_8b)
- gemini_chat (models/gemini-pro)
## Prerequisites
To set up model serving with open-source LLMs, follow the guidance in
[scripts/REAMDE.md](../../scripts/README.md).

View File

@@ -0,0 +1,49 @@
# -*- coding: utf-8 -*-
"""A simple example for conversation between user and assistant agent."""
import agentscope
from agentscope.agents import DialogAgent
from agentscope.agents.user_agent import UserAgent
from agentscope.pipelines.functional import sequentialpipeline
def main() -> None:
"""A basic conversation demo"""
agentscope.init(
model_configs=[
{
"model_type": "openai_chat",
"config_name": "gpt-3.5-turbo",
"model_name": "gpt-3.5-turbo",
"api_key": "xxx", # Load from env if not provided
"organization": "xxx", # Load from env if not provided
"generate_args": {
"temperature": 0.5,
},
},
{
"model_type": "post_api_chat",
"config_name": "my_post_api",
"api_url": "https://xxx",
"headers": {},
},
],
project="Multi-Agent Conversation",
)
# Init two agents
dialog_agent = DialogAgent(
name="Assistant",
sys_prompt="You're a helpful assistant.",
model_config_name="gpt-3.5-turbo", # replace by your model config name
)
user_agent = UserAgent()
# start the conversation between user and assistant
x = None
while x is None or x.content != "exit":
x = sequentialpipeline([dialog_agent, user_agent], x)
if __name__ == "__main__":
main()