Spaces:
Sleeping
Sleeping
Add AutoGen Playground
Browse files- .dockerignore +174 -0
- .gitattributes +0 -1
- Dockerfile +20 -11
- README.md +23 -1
- app.py +411 -119
- autogen-icons/agent_blue.png +0 -0
- autogen-icons/agent_dark.png +0 -0
- autogen-icons/agent_gray.png +0 -0
- autogen-icons/agent_green.png +0 -0
- autogen-icons/agent_orange.png +0 -0
- autogen-icons/agent_plum.png +0 -0
- autogen-icons/agent_turquoise.png +0 -0
- autogen-icons/user_blue.png +0 -0
- autogen-icons/user_green.png +0 -0
- autogen-icons/user_orange.png +0 -0
- autogen_playground.png +0 -0
- autogen_utils.py +107 -0
- custom_widgets.py +91 -0
- requirements.txt +5 -6
.dockerignore
ADDED
@@ -0,0 +1,174 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
.docusaurus/
|
2 |
+
node_modules/
|
3 |
+
# Project
|
4 |
+
/.vs
|
5 |
+
.vscode
|
6 |
+
|
7 |
+
# Log files
|
8 |
+
*.log
|
9 |
+
|
10 |
+
# Python virtualenv
|
11 |
+
.venv
|
12 |
+
|
13 |
+
# Byte-compiled / optimized / DLL files
|
14 |
+
__pycache__/
|
15 |
+
*.py[cod]
|
16 |
+
*$py.class
|
17 |
+
|
18 |
+
# C extensions
|
19 |
+
*.so
|
20 |
+
|
21 |
+
# Distribution / packaging
|
22 |
+
.Python
|
23 |
+
build/
|
24 |
+
develop-eggs/
|
25 |
+
dist/
|
26 |
+
downloads/
|
27 |
+
eggs/
|
28 |
+
.eggs/
|
29 |
+
lib/
|
30 |
+
lib64/
|
31 |
+
parts/
|
32 |
+
sdist/
|
33 |
+
var/
|
34 |
+
wheels/
|
35 |
+
share/python-wheels/
|
36 |
+
*.egg-info/
|
37 |
+
.installed.cfg
|
38 |
+
*.egg
|
39 |
+
MANIFEST
|
40 |
+
|
41 |
+
# PyInstaller
|
42 |
+
# Usually these files are written by a python script from a template
|
43 |
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
44 |
+
*.manifest
|
45 |
+
*.spec
|
46 |
+
|
47 |
+
# Installer logs
|
48 |
+
pip-log.txt
|
49 |
+
pip-delete-this-directory.txt
|
50 |
+
|
51 |
+
# Unit test / coverage reports
|
52 |
+
htmlcov/
|
53 |
+
.tox/
|
54 |
+
.nox/
|
55 |
+
.coverage
|
56 |
+
.coverage.*
|
57 |
+
.cache
|
58 |
+
nosetests.xml
|
59 |
+
coverage.xml
|
60 |
+
*.cover
|
61 |
+
*.py,cover
|
62 |
+
.hypothesis/
|
63 |
+
.pytest_cache/
|
64 |
+
cover/
|
65 |
+
|
66 |
+
# Translations
|
67 |
+
*.mo
|
68 |
+
*.pot
|
69 |
+
|
70 |
+
# Django stuff:
|
71 |
+
*.log
|
72 |
+
local_settings.py
|
73 |
+
db.sqlite3
|
74 |
+
db.sqlite3-journal
|
75 |
+
|
76 |
+
# Flask stuff:
|
77 |
+
instance/
|
78 |
+
.webassets-cache
|
79 |
+
|
80 |
+
# Scrapy stuff:
|
81 |
+
.scrapy
|
82 |
+
|
83 |
+
# Sphinx documentation
|
84 |
+
docs/_build/
|
85 |
+
|
86 |
+
# PyBuilder
|
87 |
+
.pybuilder/
|
88 |
+
target/
|
89 |
+
|
90 |
+
# Jupyter Notebook
|
91 |
+
.ipynb_checkpoints
|
92 |
+
|
93 |
+
# IPython
|
94 |
+
profile_default/
|
95 |
+
ipython_config.py
|
96 |
+
|
97 |
+
# pyenv
|
98 |
+
# For a library or package, you might want to ignore these files since the code is
|
99 |
+
# intended to run in multiple environments; otherwise, check them in:
|
100 |
+
# .python-version
|
101 |
+
|
102 |
+
# pipenv
|
103 |
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
104 |
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
105 |
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
106 |
+
# install all needed dependencies.
|
107 |
+
#Pipfile.lock
|
108 |
+
|
109 |
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
|
110 |
+
__pypackages__/
|
111 |
+
|
112 |
+
# Celery stuff
|
113 |
+
celerybeat-schedule
|
114 |
+
celerybeat.pid
|
115 |
+
|
116 |
+
# SageMath parsed files
|
117 |
+
*.sage.py
|
118 |
+
|
119 |
+
# Environments
|
120 |
+
.env
|
121 |
+
.venv
|
122 |
+
env/
|
123 |
+
venv/
|
124 |
+
ENV/
|
125 |
+
env.bak/
|
126 |
+
venv.bak/
|
127 |
+
|
128 |
+
# Spyder project settings
|
129 |
+
.spyderproject
|
130 |
+
.spyproject
|
131 |
+
|
132 |
+
# Rope project settings
|
133 |
+
.ropeproject
|
134 |
+
|
135 |
+
# mkdocs documentation
|
136 |
+
/site
|
137 |
+
|
138 |
+
# mypy
|
139 |
+
.mypy_cache/
|
140 |
+
.dmypy.json
|
141 |
+
dmypy.json
|
142 |
+
|
143 |
+
# Pyre type checker
|
144 |
+
.pyre/
|
145 |
+
|
146 |
+
# pytype static type analyzer
|
147 |
+
.pytype/
|
148 |
+
|
149 |
+
# Cython debug symbols
|
150 |
+
cython_debug/
|
151 |
+
|
152 |
+
logs
|
153 |
+
|
154 |
+
.idea/*
|
155 |
+
.DS_Store
|
156 |
+
|
157 |
+
output/
|
158 |
+
*.pkl
|
159 |
+
|
160 |
+
# local config files
|
161 |
+
*.config.local
|
162 |
+
# OAI_CONFIG_LIST
|
163 |
+
key_openai.txt
|
164 |
+
key_aoai.txt
|
165 |
+
base_aoai.txt
|
166 |
+
wolfram.txt
|
167 |
+
|
168 |
+
# DB on disk for TeachableAgent
|
169 |
+
tmp/
|
170 |
+
|
171 |
+
.cache
|
172 |
+
test*
|
173 |
+
coding
|
174 |
+
.chromadb
|
.gitattributes
CHANGED
@@ -32,4 +32,3 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
32 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
33 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
34 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
35 |
-
AutoGenPanel.gif filter=lfs diff=lfs merge=lfs -text
|
|
|
32 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
33 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
34 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
Dockerfile
CHANGED
@@ -1,16 +1,25 @@
|
|
1 |
-
FROM python:3.
|
2 |
|
3 |
-
|
|
|
|
|
4 |
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
|
9 |
-
|
|
|
|
|
10 |
|
11 |
-
|
|
|
|
|
12 |
|
13 |
-
|
14 |
-
RUN
|
15 |
-
RUN
|
16 |
-
|
|
|
|
|
|
|
|
1 |
+
FROM python:3.10.13-slim-bookworm
|
2 |
|
3 |
+
# Add user
|
4 |
+
RUN adduser --disabled-password --gecos '' autogen
|
5 |
+
RUN adduser autogen sudo
|
6 |
|
7 |
+
# Setup working directory
|
8 |
+
WORKDIR /home/autogen
|
9 |
+
COPY . /home/autogen/
|
10 |
|
11 |
+
# Setup permissions
|
12 |
+
RUN chown -R autogen:autogen /home/autogen
|
13 |
+
RUN chmod -R 755 /home/autogen
|
14 |
|
15 |
+
# Setup user to not run as root
|
16 |
+
RUN echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
|
17 |
+
USER autogen
|
18 |
|
19 |
+
# Install app requirements
|
20 |
+
RUN pip3 install --no-cache-dir torch --index-url https://download.pytorch.org/whl/cpu
|
21 |
+
RUN pip3 install -U pip && pip3 install --no-cache-dir -r requirements.txt
|
22 |
+
ENV PATH="${PATH}:/home/autogen/.local/bin"
|
23 |
+
|
24 |
+
EXPOSE 7860
|
25 |
+
ENTRYPOINT ["panel", "serve", "app.py", "--address", "0.0.0.0", "--port", "7860", "--allow-websocket-origin", "*"]
|
README.md
CHANGED
@@ -8,4 +8,26 @@ pinned: false
|
|
8 |
license: mit
|
9 |
---
|
10 |
|
11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
license: mit
|
9 |
---
|
10 |
|
11 |
+
# Microsoft AutoGen: Play Ground
|
12 |
+
|
13 |
+
This demo is an AutoGen playground implemented with [Panel](https://panel.holoviz.org/index.html).
|
14 |
+
|
15 |
+
## Run app
|
16 |
+
```
|
17 |
+
# Install dependencies
|
18 |
+
pip install -U -r requirements.txt
|
19 |
+
|
20 |
+
# Launch app
|
21 |
+
bash run.sh
|
22 |
+
```
|
23 |
+
|
24 |
+
## Run docker locally
|
25 |
+
```
|
26 |
+
docker build -t autogen/groupchat .
|
27 |
+
docker run -it autogen/groupchat -p 5006:5006
|
28 |
+
```
|
29 |
+
|
30 |
+
#### [AutoGen](https://github.com/microsoft/autogen) [SourceCode](https://github.com/thinkall/autogen-demos)
|
31 |
+
![](autogen_playground.png)
|
32 |
+
|
33 |
+
![](AutoGenPanel.gif)
|
app.py
CHANGED
@@ -1,147 +1,439 @@
|
|
1 |
-
import
|
2 |
import random
|
3 |
-
|
4 |
|
5 |
-
import
|
6 |
import panel as pn
|
7 |
-
from
|
8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
-
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
-
|
13 |
-
"brand-github": "https://github.com/holoviz/panel",
|
14 |
-
"brand-twitter": "https://twitter.com/Panel_Org",
|
15 |
-
"brand-linkedin": "https://www.linkedin.com/company/panel-org",
|
16 |
-
"message-circle": "https://discourse.holoviz.org/",
|
17 |
-
"brand-discord": "https://discord.gg/AXRHnJU6sP",
|
18 |
-
}
|
19 |
|
20 |
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
async with aiohttp.ClientSession() as session:
|
25 |
-
async with session.get(api_url) as resp:
|
26 |
-
return (await resp.json())[0]["url"]
|
27 |
|
|
|
28 |
|
29 |
-
|
30 |
-
|
31 |
-
processor_name: str, model_name: str
|
32 |
-
) -> Tuple[CLIPProcessor, CLIPModel]:
|
33 |
-
processor = CLIPProcessor.from_pretrained(processor_name)
|
34 |
-
model = CLIPModel.from_pretrained(model_name)
|
35 |
-
return processor, model
|
36 |
|
37 |
|
38 |
-
|
39 |
-
async with aiohttp.ClientSession() as session:
|
40 |
-
async with session.get(image_url) as resp:
|
41 |
-
return Image.open(io.BytesIO(await resp.read()))
|
42 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
|
|
|
|
|
|
|
|
|
|
52 |
)
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
|
|
57 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
main.disabled = True
|
66 |
-
if not image_url:
|
67 |
-
yield "##### β οΈ Provide an image URL"
|
68 |
-
return
|
69 |
-
|
70 |
-
yield "##### β Fetching image and running model..."
|
71 |
-
try:
|
72 |
-
pil_img = await open_image_url(image_url)
|
73 |
-
img = pn.pane.Image(pil_img, height=400, align="center")
|
74 |
-
except Exception as e:
|
75 |
-
yield f"##### π Something went wrong, please try a different URL!"
|
76 |
-
return
|
77 |
-
|
78 |
-
class_items = class_names.split(",")
|
79 |
-
class_likelihoods = get_similarity_scores(class_items, pil_img)
|
80 |
-
|
81 |
-
# build the results column
|
82 |
-
results = pn.Column("##### π Here are the results!", img)
|
83 |
-
|
84 |
-
for class_item, class_likelihood in zip(class_items, class_likelihoods):
|
85 |
-
row_label = pn.widgets.StaticText(
|
86 |
-
name=class_item.strip(), value=f"{class_likelihood:.2%}", align="center"
|
87 |
-
)
|
88 |
-
row_bar = pn.indicators.Progress(
|
89 |
-
value=int(class_likelihood * 100),
|
90 |
-
sizing_mode="stretch_width",
|
91 |
-
bar_color="secondary",
|
92 |
-
margin=(0, 10),
|
93 |
-
design=pn.theme.Material,
|
94 |
-
)
|
95 |
-
results.append(pn.Column(row_label, row_bar))
|
96 |
-
yield results
|
97 |
-
finally:
|
98 |
-
main.disabled = False
|
99 |
|
|
|
100 |
|
101 |
-
# create widgets
|
102 |
-
randomize_url = pn.widgets.Button(name="Randomize URL", align="end")
|
103 |
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
|
|
|
|
|
|
112 |
)
|
113 |
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
118 |
)
|
119 |
|
120 |
-
|
121 |
-
|
122 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
123 |
height=600,
|
124 |
)
|
125 |
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
139 |
)
|
140 |
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
import random
|
3 |
+
import time
|
4 |
|
5 |
+
import autogen
|
6 |
import panel as pn
|
7 |
+
from autogen_utils import (
|
8 |
+
MathUserProxyAgent,
|
9 |
+
RetrieveUserProxyAgent,
|
10 |
+
get_retrieve_config,
|
11 |
+
initialize_agents,
|
12 |
+
)
|
13 |
+
from custom_widgets import RowAgentWidget
|
14 |
+
from panel.chat import ChatInterface
|
15 |
+
from panel.widgets import Button, PasswordInput, Switch, TextInput
|
16 |
|
17 |
+
TIMEOUT = 60
|
18 |
+
TITLE = "Microsoft AutoGen Playground"
|
19 |
+
Q1 = "What's AutoGen?"
|
20 |
+
Q2 = "Write a python function to compute the sum of numbers."
|
21 |
+
Q3 = "find papers on LLM applications from arxiv in the last week, create a markdown table of different domains."
|
22 |
+
pn.extension(design="material")
|
23 |
|
24 |
+
template = pn.template.BootstrapTemplate(title=TITLE)
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
|
26 |
|
27 |
+
def get_description_text():
|
28 |
+
return f"""
|
29 |
+
# {TITLE}
|
|
|
|
|
|
|
30 |
|
31 |
+
This is an AutoGen playground built with [Panel](https://panel.holoviz.org/). You can use it to interact with the AutoGen agents.
|
32 |
|
33 |
+
#### [[AutoGen](https://github.com/microsoft/autogen)] [[Discord](https://discord.gg/pAbnFJrkgZ)] [[Paper](https://arxiv.org/abs/2308.08155)] [[SourceCode](https://github.com/thinkall/autogen-demos)]
|
34 |
+
"""
|
|
|
|
|
|
|
|
|
|
|
35 |
|
36 |
|
37 |
+
template.main.append(pn.pane.Markdown(get_description_text(), sizing_mode="stretch_width"))
|
|
|
|
|
|
|
38 |
|
39 |
+
txt_model = TextInput(
|
40 |
+
name="Model Name", placeholder="Enter your model name here...", value="gpt-35-turbo", sizing_mode="stretch_width"
|
41 |
+
)
|
42 |
+
pwd_openai_key = PasswordInput(
|
43 |
+
name="OpenAI API Key", placeholder="Enter your OpenAI API Key here...", sizing_mode="stretch_width"
|
44 |
+
)
|
45 |
+
pwd_aoai_key = PasswordInput(
|
46 |
+
name="Azure OpenAI API Key", placeholder="Enter your Azure OpenAI API Key here...", sizing_mode="stretch_width"
|
47 |
+
)
|
48 |
+
pwd_aoai_url = PasswordInput(
|
49 |
+
name="Azure OpenAI Base Url", placeholder="Enter your Azure OpenAI Base Url here...", sizing_mode="stretch_width"
|
50 |
+
)
|
51 |
+
file_cfg = pn.widgets.FileInput(filename="OAI_CONFIG_LIST", sizing_mode="stretch_width")
|
52 |
+
template.main.append(pn.Row(txt_model, pwd_openai_key, pwd_aoai_key, pwd_aoai_url, file_cfg))
|
53 |
|
54 |
+
|
55 |
+
def get_config(tmpfilename="OAI_CONFIG_LIST"):
|
56 |
+
os.makedirs(".chromadb", exist_ok=True)
|
57 |
+
if file_cfg.value:
|
58 |
+
if os.path.exists(f".chromadb/{tmpfilename}"):
|
59 |
+
os.remove(f".chromadb/{tmpfilename}")
|
60 |
+
file_cfg.save(f".chromadb/{tmpfilename}")
|
61 |
+
cfg_fpath = f".chromadb/{tmpfilename}"
|
62 |
+
else:
|
63 |
+
cfg_fpath = "OAI_CONFIG_LIST" # for local testing
|
64 |
+
config_list = autogen.config_list_from_json(
|
65 |
+
cfg_fpath,
|
66 |
+
file_location=".",
|
67 |
)
|
68 |
+
if not config_list:
|
69 |
+
os.environ["MODEL"] = txt_model.value
|
70 |
+
os.environ["OPENAI_API_KEY"] = pwd_openai_key.value
|
71 |
+
os.environ["AZURE_OPENAI_API_KEY"] = pwd_aoai_key.value
|
72 |
+
os.environ["AZURE_OPENAI_API_BASE"] = pwd_aoai_url.value
|
73 |
|
74 |
+
config_list = autogen.config_list_from_models(
|
75 |
+
model_list=[os.environ.get("MODEL", "gpt-35-turbo")],
|
76 |
+
)
|
77 |
+
if not config_list:
|
78 |
+
config_list = [
|
79 |
+
{
|
80 |
+
"api_key": "",
|
81 |
+
"base_url": "",
|
82 |
+
"api_type": "azure",
|
83 |
+
"api_version": "2023-07-01-preview",
|
84 |
+
"model": "gpt-35-turbo",
|
85 |
+
}
|
86 |
+
]
|
87 |
|
88 |
+
llm_config = {
|
89 |
+
"timeout": 60,
|
90 |
+
"cache_seed": 42,
|
91 |
+
"config_list": config_list,
|
92 |
+
"temperature": 0,
|
93 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
94 |
|
95 |
+
return llm_config
|
96 |
|
|
|
|
|
97 |
|
98 |
+
btn_add = Button(name="+", button_type="success")
|
99 |
+
btn_remove = Button(name="-", button_type="danger")
|
100 |
+
switch_code = Switch(name="Run Code", sizing_mode="fixed", width=50, height=30, align="end")
|
101 |
+
template.main.append(
|
102 |
+
pn.Row(
|
103 |
+
pn.pane.Markdown("## Add or Remove Agents: "),
|
104 |
+
btn_add,
|
105 |
+
btn_remove,
|
106 |
+
pn.pane.Markdown("### Run Code: "),
|
107 |
+
switch_code,
|
108 |
+
)
|
109 |
)
|
110 |
|
111 |
+
column_agents = pn.Column(
|
112 |
+
RowAgentWidget(
|
113 |
+
value=[
|
114 |
+
"User_Proxy",
|
115 |
+
"User Proxy Agent",
|
116 |
+
"UserProxyAgent",
|
117 |
+
"",
|
118 |
+
]
|
119 |
+
),
|
120 |
+
sizing_mode="stretch_width",
|
121 |
+
)
|
122 |
+
column_agents.append(
|
123 |
+
RowAgentWidget(
|
124 |
+
value=[
|
125 |
+
"Assistant_Agent",
|
126 |
+
"You are a helpful AI assistant. Reply `TERMINATE` if everything is done.",
|
127 |
+
"AssistantAgent",
|
128 |
+
"",
|
129 |
+
]
|
130 |
+
),
|
131 |
)
|
132 |
|
133 |
+
template.main.append(column_agents)
|
134 |
+
|
135 |
+
|
136 |
+
def add_agent(event):
|
137 |
+
column_agents.append(RowAgentWidget(value=["", "", "AssistantAgent", ""]))
|
138 |
+
|
139 |
+
|
140 |
+
def remove_agent(event):
|
141 |
+
column_agents.pop(-1)
|
142 |
+
|
143 |
+
|
144 |
+
btn_add.on_click(add_agent)
|
145 |
+
btn_remove.on_click(remove_agent)
|
146 |
+
|
147 |
+
|
148 |
+
def send_messages(recipient, messages, sender, config):
|
149 |
+
chatiface.send(messages[-1]["content"], user=sender.name, respond=False)
|
150 |
+
return False, None # required to ensure the agent communication flow continues
|
151 |
+
|
152 |
+
|
153 |
+
def init_groupchat(event, collection_name):
|
154 |
+
llm_config = get_config(collection_name)
|
155 |
+
agents = []
|
156 |
+
for row_agent in column_agents:
|
157 |
+
agent_name = row_agent[0][0].value
|
158 |
+
system_msg = row_agent[0][1].value
|
159 |
+
agent_type = row_agent[0][2].value
|
160 |
+
docs_path = row_agent[1].value
|
161 |
+
retrieve_config = (
|
162 |
+
get_retrieve_config(
|
163 |
+
docs_path,
|
164 |
+
txt_model.value,
|
165 |
+
collection_name=collection_name,
|
166 |
+
)
|
167 |
+
if agent_type == "RetrieveUserProxyAgent"
|
168 |
+
else None
|
169 |
+
)
|
170 |
+
code_execution_config = (
|
171 |
+
{
|
172 |
+
"work_dir": "coding",
|
173 |
+
"use_docker": False, # set to True or image name like "python:3" to use docker
|
174 |
+
}
|
175 |
+
if switch_code.value
|
176 |
+
else False
|
177 |
+
)
|
178 |
+
agent = initialize_agents(
|
179 |
+
llm_config, agent_name, system_msg, agent_type, retrieve_config, code_execution_config
|
180 |
+
)
|
181 |
+
agent.register_reply([autogen.Agent, None], reply_func=send_messages, config={"callback": None})
|
182 |
+
agents.append(agent)
|
183 |
+
if len(agents) >= 3:
|
184 |
+
groupchat = autogen.GroupChat(
|
185 |
+
agents=agents, messages=[], max_round=12, speaker_selection_method="round_robin", allow_repeat_speaker=False
|
186 |
+
) # todo: auto, sometimes message has no name
|
187 |
+
manager = autogen.GroupChatManager(groupchat=groupchat, llm_config=llm_config)
|
188 |
+
else:
|
189 |
+
manager = None
|
190 |
+
return agents, manager
|
191 |
+
|
192 |
+
|
193 |
+
async def agents_chat(init_sender, manager, contents, agents):
|
194 |
+
recipient = manager if len(agents) > 2 else agents[1] if agents[1] != init_sender else agents[0]
|
195 |
+
if isinstance(init_sender, (RetrieveUserProxyAgent, MathUserProxyAgent)):
|
196 |
+
await init_sender.a_initiate_chat(recipient, problem=contents)
|
197 |
+
else:
|
198 |
+
await init_sender.a_initiate_chat(recipient, message=contents)
|
199 |
+
|
200 |
+
|
201 |
+
async def reply_chat(contents, user, instance):
|
202 |
+
# print([message for message in instance.objects])
|
203 |
+
if hasattr(instance, "collection_name"):
|
204 |
+
collection_name = instance.collection_name
|
205 |
+
else:
|
206 |
+
collection_name = f"{int(time.time())}_{random.randint(0, 100000)}"
|
207 |
+
instance.collection_name = collection_name
|
208 |
+
|
209 |
+
column_agents_list = [agent[0][0].value for agent in column_agents]
|
210 |
+
if not hasattr(instance, "agent_list") or instance.agents_list != column_agents_list:
|
211 |
+
agents, manager = init_groupchat(None, collection_name)
|
212 |
+
instance.manager = manager
|
213 |
+
instance.agents = agents
|
214 |
+
instance.agents_list = column_agents_list
|
215 |
+
else:
|
216 |
+
agents = instance.agents
|
217 |
+
manager = instance.manager
|
218 |
+
|
219 |
+
if len(agents) <= 1:
|
220 |
+
return "Please add more agents."
|
221 |
+
|
222 |
+
init_sender = None
|
223 |
+
for agent in agents:
|
224 |
+
if "UserProxy" in str(type(agent)):
|
225 |
+
init_sender = agent
|
226 |
+
break
|
227 |
+
if not init_sender:
|
228 |
+
init_sender = agents[0]
|
229 |
+
await agents_chat(init_sender, manager, contents, agents)
|
230 |
+
return "The task is done. Please start a new task."
|
231 |
+
|
232 |
+
|
233 |
+
chatiface = ChatInterface(
|
234 |
+
callback=reply_chat,
|
235 |
height=600,
|
236 |
)
|
237 |
|
238 |
+
template.main.append(chatiface)
|
239 |
+
|
240 |
+
btn_msg1 = Button(name=Q1, sizing_mode="stretch_width")
|
241 |
+
btn_msg2 = Button(name=Q2, sizing_mode="stretch_width")
|
242 |
+
btn_msg3 = Button(name=Q3, sizing_mode="stretch_width")
|
243 |
+
template.main.append(
|
244 |
+
pn.Column(
|
245 |
+
pn.pane.Markdown("## Message Examples: ", sizing_mode="stretch_width"),
|
246 |
+
btn_msg1,
|
247 |
+
btn_msg2,
|
248 |
+
btn_msg3,
|
249 |
+
sizing_mode="stretch_width",
|
250 |
+
)
|
251 |
+
)
|
252 |
+
|
253 |
+
|
254 |
+
def load_message(event):
|
255 |
+
if event.obj.name == Q1:
|
256 |
+
chatiface.send(Q1)
|
257 |
+
elif event.obj.name == Q2:
|
258 |
+
chatiface.send(Q2)
|
259 |
+
elif event.obj.name == Q3:
|
260 |
+
chatiface.send(Q3)
|
261 |
+
|
262 |
+
|
263 |
+
btn_msg1.on_click(load_message)
|
264 |
+
btn_msg2.on_click(load_message)
|
265 |
+
btn_msg3.on_click(load_message)
|
266 |
+
|
267 |
+
|
268 |
+
btn_example1 = Button(name="General 2 agents", button_type="primary", sizing_mode="stretch_width")
|
269 |
+
btn_example2 = Button(name="RAG 2 agents", button_type="primary", sizing_mode="stretch_width")
|
270 |
+
btn_example3 = Button(name="Software Dev 3 agents", button_type="primary", sizing_mode="stretch_width")
|
271 |
+
btn_example4 = Button(name="Research 6 agents", button_type="primary", sizing_mode="stretch_width")
|
272 |
+
template.main.append(
|
273 |
+
pn.Row(
|
274 |
+
pn.pane.Markdown("## Agent Examples: ", sizing_mode="stretch_width"),
|
275 |
+
btn_example1,
|
276 |
+
btn_example2,
|
277 |
+
btn_example3,
|
278 |
+
btn_example4,
|
279 |
+
sizing_mode="stretch_width",
|
280 |
+
)
|
281 |
)
|
282 |
|
283 |
+
|
284 |
+
def clear_agents():
|
285 |
+
while len(column_agents) > 0:
|
286 |
+
column_agents.pop(-1)
|
287 |
+
|
288 |
+
|
289 |
+
def load_example(event):
|
290 |
+
clear_agents()
|
291 |
+
if event.obj.name == "RAG 2 agents":
|
292 |
+
column_agents.append(
|
293 |
+
RowAgentWidget(
|
294 |
+
value=[
|
295 |
+
"Boss_Assistant",
|
296 |
+
"Assistant who has extra content retrieval power for solving difficult problems.",
|
297 |
+
"RetrieveUserProxyAgent",
|
298 |
+
"",
|
299 |
+
]
|
300 |
+
),
|
301 |
+
)
|
302 |
+
column_agents.append(
|
303 |
+
RowAgentWidget(
|
304 |
+
value=[
|
305 |
+
"Senior_Python_Engineer",
|
306 |
+
"You are a senior python engineer. Reply `TERMINATE` if everything is done.",
|
307 |
+
"RetrieveAssistantAgent",
|
308 |
+
"",
|
309 |
+
]
|
310 |
+
),
|
311 |
+
)
|
312 |
+
elif event.obj.name == "General 2 agents":
|
313 |
+
column_agents.append(
|
314 |
+
RowAgentWidget(
|
315 |
+
value=[
|
316 |
+
"User_Proxy",
|
317 |
+
"User Proxy Agent",
|
318 |
+
"UserProxyAgent",
|
319 |
+
"",
|
320 |
+
]
|
321 |
+
),
|
322 |
+
)
|
323 |
+
column_agents.append(
|
324 |
+
RowAgentWidget(
|
325 |
+
value=[
|
326 |
+
"Assistant_Agent",
|
327 |
+
"You are a helpful AI assistant. Reply `TERMINATE` if everything is done.",
|
328 |
+
"AssistantAgent",
|
329 |
+
"",
|
330 |
+
]
|
331 |
+
),
|
332 |
+
)
|
333 |
+
elif event.obj.name == "Software Dev 3 agents":
|
334 |
+
column_agents.append(
|
335 |
+
RowAgentWidget(
|
336 |
+
value=[
|
337 |
+
"Boss",
|
338 |
+
"The boss who ask questions and give tasks. Reply `TERMINATE` if everything is done.",
|
339 |
+
"UserProxyAgent",
|
340 |
+
"",
|
341 |
+
]
|
342 |
+
),
|
343 |
+
)
|
344 |
+
column_agents.append(
|
345 |
+
RowAgentWidget(
|
346 |
+
value=[
|
347 |
+
"Senior_Python_Engineer",
|
348 |
+
"You are a senior python engineer. Reply `TERMINATE` if everything is done.",
|
349 |
+
"AssistantAgent",
|
350 |
+
"",
|
351 |
+
]
|
352 |
+
),
|
353 |
+
)
|
354 |
+
column_agents.append(
|
355 |
+
RowAgentWidget(
|
356 |
+
value=[
|
357 |
+
"Product_Manager",
|
358 |
+
"You are a product manager. Reply `TERMINATE` if everything is done.",
|
359 |
+
"AssistantAgent",
|
360 |
+
"",
|
361 |
+
]
|
362 |
+
),
|
363 |
+
)
|
364 |
+
elif event.obj.name == "Research 6 agents":
|
365 |
+
column_agents.append(
|
366 |
+
RowAgentWidget(
|
367 |
+
value=[
|
368 |
+
"Admin",
|
369 |
+
"A human admin. Interact with the planner to discuss the plan. Plan execution needs to be approved by this admin.",
|
370 |
+
"UserProxyAgent",
|
371 |
+
"",
|
372 |
+
]
|
373 |
+
),
|
374 |
+
)
|
375 |
+
column_agents.append(
|
376 |
+
RowAgentWidget(
|
377 |
+
value=[
|
378 |
+
"Engineer",
|
379 |
+
"""Engineer. You follow an approved plan. You write python/shell code to solve tasks. Wrap the code in a code block that specifies the script type. The user can't modify your code. So do not suggest incomplete code which requires others to modify. Don't use a code block if it's not intended to be executed by the executor.
|
380 |
+
Don't include multiple code blocks in one response. Do not ask others to copy and paste the result. Check the execution result returned by the executor.
|
381 |
+
If the result indicates there is an error, fix the error and output the code again. Suggest the full code instead of partial code or code changes. If the error can't be fixed or if the task is not solved even after the code is executed successfully, analyze the problem, revisit your assumption, collect additional info you need, and think of a different approach to try.
|
382 |
+
""",
|
383 |
+
"AssistantAgent",
|
384 |
+
"",
|
385 |
+
]
|
386 |
+
),
|
387 |
+
)
|
388 |
+
column_agents.append(
|
389 |
+
RowAgentWidget(
|
390 |
+
value=[
|
391 |
+
"Scientist",
|
392 |
+
"""Scientist. You follow an approved plan. You are able to categorize papers after seeing their abstracts printed. You don't write code.""",
|
393 |
+
"AssistantAgent",
|
394 |
+
"",
|
395 |
+
]
|
396 |
+
),
|
397 |
+
)
|
398 |
+
column_agents.append(
|
399 |
+
RowAgentWidget(
|
400 |
+
value=[
|
401 |
+
"Planner",
|
402 |
+
"""Planner. Suggest a plan. Revise the plan based on feedback from admin and critic, until admin approval.
|
403 |
+
The plan may involve an engineer who can write code and a scientist who doesn't write code.
|
404 |
+
Explain the plan first. Be clear which step is performed by an engineer, and which step is performed by a scientist.
|
405 |
+
""",
|
406 |
+
"AssistantAgent",
|
407 |
+
"",
|
408 |
+
]
|
409 |
+
),
|
410 |
+
)
|
411 |
+
column_agents.append(
|
412 |
+
RowAgentWidget(
|
413 |
+
value=[
|
414 |
+
"Critic",
|
415 |
+
"Critic. Double check plan, claims, code from other agents and provide feedback. Check whether the plan includes adding verifiable info such as source URL.",
|
416 |
+
"AssistantAgent",
|
417 |
+
"",
|
418 |
+
]
|
419 |
+
),
|
420 |
+
)
|
421 |
+
|
422 |
+
column_agents.append(
|
423 |
+
RowAgentWidget(
|
424 |
+
value=[
|
425 |
+
"Executor",
|
426 |
+
"Executor. Execute the code written by the engineer and report the result.",
|
427 |
+
"UserProxyAgent",
|
428 |
+
"",
|
429 |
+
]
|
430 |
+
),
|
431 |
+
)
|
432 |
+
|
433 |
+
|
434 |
+
btn_example1.on_click(load_example)
|
435 |
+
btn_example2.on_click(load_example)
|
436 |
+
btn_example3.on_click(load_example)
|
437 |
+
btn_example4.on_click(load_example)
|
438 |
+
|
439 |
+
template.servable(title=TITLE)
|
autogen-icons/agent_blue.png
ADDED
autogen-icons/agent_dark.png
ADDED
autogen-icons/agent_gray.png
ADDED
autogen-icons/agent_green.png
ADDED
autogen-icons/agent_orange.png
ADDED
autogen-icons/agent_plum.png
ADDED
autogen-icons/agent_turquoise.png
ADDED
autogen-icons/user_blue.png
ADDED
autogen-icons/user_green.png
ADDED
autogen-icons/user_orange.png
ADDED
autogen_playground.png
ADDED
autogen_utils.py
ADDED
@@ -0,0 +1,107 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import sys
|
2 |
+
import threading
|
3 |
+
from ast import literal_eval
|
4 |
+
|
5 |
+
import autogen
|
6 |
+
import chromadb
|
7 |
+
from autogen import AssistantAgent, UserProxyAgent
|
8 |
+
from autogen.agentchat.contrib.compressible_agent import CompressibleAgent
|
9 |
+
from autogen.agentchat.contrib.gpt_assistant_agent import GPTAssistantAgent
|
10 |
+
from autogen.agentchat.contrib.llava_agent import LLaVAAgent
|
11 |
+
from autogen.agentchat.contrib.math_user_proxy_agent import MathUserProxyAgent
|
12 |
+
from autogen.agentchat.contrib.retrieve_assistant_agent import RetrieveAssistantAgent
|
13 |
+
from autogen.agentchat.contrib.retrieve_user_proxy_agent import RetrieveUserProxyAgent
|
14 |
+
from autogen.agentchat.contrib.teachable_agent import TeachableAgent
|
15 |
+
from autogen.code_utils import extract_code
|
16 |
+
|
17 |
+
|
18 |
+
def get_retrieve_config(docs_path, model_name, collection_name):
|
19 |
+
return {
|
20 |
+
"docs_path": literal_eval(docs_path),
|
21 |
+
"chunk_token_size": 1000,
|
22 |
+
"model": model_name,
|
23 |
+
"embedding_model": "all-mpnet-base-v2",
|
24 |
+
"get_or_create": True,
|
25 |
+
"client": chromadb.PersistentClient(path=".chromadb"),
|
26 |
+
"collection_name": collection_name,
|
27 |
+
}
|
28 |
+
|
29 |
+
|
30 |
+
# autogen.ChatCompletion.start_logging()
|
31 |
+
def termination_msg(x):
|
32 |
+
return isinstance(x, dict) and "TERMINATE" == str(x.get("content", ""))[-9:].upper()
|
33 |
+
|
34 |
+
|
35 |
+
def _is_termination_msg(message):
|
36 |
+
"""Check if a message is a termination message.
|
37 |
+
Terminate when no code block is detected. Currently only detect python code blocks.
|
38 |
+
"""
|
39 |
+
if isinstance(message, dict):
|
40 |
+
message = message.get("content")
|
41 |
+
if message is None:
|
42 |
+
return False
|
43 |
+
cb = extract_code(message)
|
44 |
+
contain_code = False
|
45 |
+
for c in cb:
|
46 |
+
# todo: support more languages
|
47 |
+
if c[0] == "python":
|
48 |
+
contain_code = True
|
49 |
+
break
|
50 |
+
return not contain_code
|
51 |
+
|
52 |
+
|
53 |
+
def initialize_agents(
|
54 |
+
llm_config, agent_name, system_msg, agent_type, retrieve_config=None, code_execution_config=False
|
55 |
+
):
|
56 |
+
if "RetrieveUserProxyAgent" == agent_type:
|
57 |
+
agent = RetrieveUserProxyAgent(
|
58 |
+
name=agent_name,
|
59 |
+
is_termination_msg=termination_msg,
|
60 |
+
human_input_mode="NEVER",
|
61 |
+
max_consecutive_auto_reply=5,
|
62 |
+
retrieve_config=retrieve_config,
|
63 |
+
code_execution_config=code_execution_config, # set to False if you don't want to execute the code
|
64 |
+
default_auto_reply="Reply `TERMINATE` if the task is done.",
|
65 |
+
)
|
66 |
+
elif "GPTAssistantAgent" == agent_type:
|
67 |
+
agent = GPTAssistantAgent(
|
68 |
+
name=agent_name,
|
69 |
+
instructions=system_msg,
|
70 |
+
llm_config=llm_config,
|
71 |
+
is_termination_msg=termination_msg,
|
72 |
+
)
|
73 |
+
elif "CompressibleAgent" == agent_type:
|
74 |
+
compress_config = {
|
75 |
+
"mode": "COMPRESS",
|
76 |
+
"trigger_count": 600, # set this to a large number for less frequent compression
|
77 |
+
"verbose": True, # to allow printing of compression information: contex before and after compression
|
78 |
+
"leave_last_n": 2,
|
79 |
+
}
|
80 |
+
agent = CompressibleAgent(
|
81 |
+
name=agent_name,
|
82 |
+
system_message=system_msg,
|
83 |
+
llm_config=llm_config,
|
84 |
+
compress_config=compress_config,
|
85 |
+
is_termination_msg=termination_msg,
|
86 |
+
)
|
87 |
+
elif "UserProxy" in agent_type:
|
88 |
+
agent = globals()[agent_type](
|
89 |
+
name=agent_name,
|
90 |
+
is_termination_msg=termination_msg,
|
91 |
+
human_input_mode="NEVER",
|
92 |
+
system_message=system_msg,
|
93 |
+
default_auto_reply="Reply `TERMINATE` if the task is done.",
|
94 |
+
max_consecutive_auto_reply=5,
|
95 |
+
code_execution_config=code_execution_config,
|
96 |
+
)
|
97 |
+
else:
|
98 |
+
agent = globals()[agent_type](
|
99 |
+
name=agent_name,
|
100 |
+
is_termination_msg=termination_msg,
|
101 |
+
human_input_mode="NEVER",
|
102 |
+
system_message=system_msg,
|
103 |
+
llm_config=llm_config,
|
104 |
+
)
|
105 |
+
|
106 |
+
return agent
|
107 |
+
|
custom_widgets.py
ADDED
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import panel as pn
|
2 |
+
import param
|
3 |
+
from panel.viewable import Viewer
|
4 |
+
from panel.widgets import Button, PasswordInput, Select, TextAreaInput, TextInput
|
5 |
+
|
6 |
+
DEFAULT_LIST = [
|
7 |
+
"https://raw.githubusercontent.com/microsoft/autogen/main/README.md",
|
8 |
+
"https://raw.githubusercontent.com/microsoft/FLAML/main/website/docs/Examples/Integrate%20-%20Spark.md",
|
9 |
+
]
|
10 |
+
|
11 |
+
|
12 |
+
class RowAgentWidget(Viewer):
|
13 |
+
"""A widget for creating a row of agent widgets. Including agent name, system message, and agent type."""
|
14 |
+
|
15 |
+
value = param.List(
|
16 |
+
default=[
|
17 |
+
"",
|
18 |
+
"",
|
19 |
+
"AssistantAgent",
|
20 |
+
DEFAULT_LIST,
|
21 |
+
],
|
22 |
+
doc="Agent name, system message, and agent type",
|
23 |
+
)
|
24 |
+
|
25 |
+
def __init__(self, **params):
|
26 |
+
layout_params = {key: value for key, value in params.items() if key not in ["value"]}
|
27 |
+
params = {key: value for key, value in params.items() if key not in layout_params}
|
28 |
+
self._agent_name = TextInput(
|
29 |
+
name="",
|
30 |
+
value=params.get("value")[0],
|
31 |
+
placeholder="Agent Name",
|
32 |
+
min_width=100,
|
33 |
+
sizing_mode="scale_width",
|
34 |
+
)
|
35 |
+
self._system_msg = TextInput(
|
36 |
+
name="",
|
37 |
+
value=params.get("value")[1],
|
38 |
+
placeholder="System Message",
|
39 |
+
min_width=400,
|
40 |
+
sizing_mode="scale_width",
|
41 |
+
)
|
42 |
+
self._agent_type = Select(
|
43 |
+
name="",
|
44 |
+
value=params.get("value")[2],
|
45 |
+
min_width=100,
|
46 |
+
options=[
|
47 |
+
"AssistantAgent",
|
48 |
+
"UserProxyAgent",
|
49 |
+
"RetrieveUserProxyAgent",
|
50 |
+
"RetrieveAssistantAgent",
|
51 |
+
"CompressibleAgent",
|
52 |
+
"GPTAssistantAgent",
|
53 |
+
"LLaVAAgent",
|
54 |
+
"MathUserProxyAgent",
|
55 |
+
# "TeachableAgent",
|
56 |
+
],
|
57 |
+
sizing_mode="scale_width",
|
58 |
+
)
|
59 |
+
self._rag_docs = TextAreaInput(
|
60 |
+
name="",
|
61 |
+
value=f"{DEFAULT_LIST}",
|
62 |
+
placeholder="List of links to docs",
|
63 |
+
sizing_mode="scale_width",
|
64 |
+
auto_grow=True,
|
65 |
+
visible=False,
|
66 |
+
)
|
67 |
+
|
68 |
+
super().__init__(**params)
|
69 |
+
self._layout = pn.Column(
|
70 |
+
pn.Row(self._agent_name, self._system_msg, self._agent_type, sizing_mode="scale_width"),
|
71 |
+
self._rag_docs,
|
72 |
+
sizing_mode="scale_width",
|
73 |
+
)
|
74 |
+
self._sync_widgets()
|
75 |
+
|
76 |
+
def __panel__(self):
|
77 |
+
return self._layout
|
78 |
+
|
79 |
+
@param.depends("value", watch=True)
|
80 |
+
def _sync_widgets(self):
|
81 |
+
self._agent_name.value = self.value[0]
|
82 |
+
self._system_msg.value = self.value[1]
|
83 |
+
self._agent_type.value = self.value[2]
|
84 |
+
if self.value[2] == "RetrieveUserProxyAgent":
|
85 |
+
self._rag_docs.visible = True
|
86 |
+
else:
|
87 |
+
self._rag_docs.visible = False
|
88 |
+
|
89 |
+
@param.depends("_agent_name.value", "_system_msg.value", "_agent_type.value", "_rag_docs.value", watch=True)
|
90 |
+
def _sync_params(self):
|
91 |
+
self.value = [self._agent_name.value, self._system_msg.value, self._agent_type.value, self._rag_docs.value]
|
requirements.txt
CHANGED
@@ -1,6 +1,5 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
aiohttp
|
|
|
1 |
+
pyautogen[retrievechat,mathchat,lmm]~=0.2.0b6
|
2 |
+
panel>=1.3.1
|
3 |
+
cloudpickle
|
4 |
+
diskcache
|
5 |
+
yfinance
|
|