Spaces:
Sleeping
Sleeping
Commit
·
79877e0
1
Parent(s):
1e7f871
Upload 2 files
Browse files- app.py +69 -0
- requirements.txt +59 -0
app.py
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import asyncio
|
| 3 |
+
from autogen import AssistantAgent, UserProxyAgent
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
st.write("""# AutoGen Chat Agents""")
|
| 7 |
+
|
| 8 |
+
class TrackableAssistantAgent(AssistantAgent):
|
| 9 |
+
def _process_received_message(self, message, sender, silent):
|
| 10 |
+
with st.chat_message(sender.name):
|
| 11 |
+
st.markdown(message)
|
| 12 |
+
return super()._process_received_message(message, sender, silent)
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
class TrackableUserProxyAgent(UserProxyAgent):
|
| 16 |
+
def _process_received_message(self, message, sender, silent):
|
| 17 |
+
with st.chat_message(sender.name):
|
| 18 |
+
st.markdown(message)
|
| 19 |
+
return super()._process_received_message(message, sender, silent)
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
selected_model = None
|
| 23 |
+
selected_key = None
|
| 24 |
+
with st.sidebar:
|
| 25 |
+
st.header("OpenAI Configuration")
|
| 26 |
+
selected_model = st.selectbox("Model", ['gpt-3.5-turbo', 'gpt-4'], index=1)
|
| 27 |
+
selected_key = st.text_input("API Key", type="password")
|
| 28 |
+
|
| 29 |
+
with st.container():
|
| 30 |
+
# for message in st.session_state["messages"]:
|
| 31 |
+
# st.markdown(message)
|
| 32 |
+
|
| 33 |
+
user_input = st.chat_input("Type something...")
|
| 34 |
+
if user_input:
|
| 35 |
+
if not selected_key or not selected_model:
|
| 36 |
+
st.warning(
|
| 37 |
+
'You must provide valid OpenAI API key and choose preferred model', icon="⚠️")
|
| 38 |
+
st.stop()
|
| 39 |
+
|
| 40 |
+
llm_config = {
|
| 41 |
+
"request_timeout": 600,
|
| 42 |
+
"config_list": [
|
| 43 |
+
{
|
| 44 |
+
"model": selected_model,
|
| 45 |
+
"api_key": selected_key
|
| 46 |
+
}
|
| 47 |
+
]
|
| 48 |
+
}
|
| 49 |
+
# create an AssistantAgent instance named "assistant"
|
| 50 |
+
assistant = TrackableAssistantAgent(
|
| 51 |
+
name="assistant", llm_config=llm_config)
|
| 52 |
+
|
| 53 |
+
# create a UserProxyAgent instance named "user"
|
| 54 |
+
user_proxy = TrackableUserProxyAgent(
|
| 55 |
+
name="user", human_input_mode="NEVER", llm_config=llm_config)
|
| 56 |
+
|
| 57 |
+
# Create an event loop
|
| 58 |
+
loop = asyncio.new_event_loop()
|
| 59 |
+
asyncio.set_event_loop(loop)
|
| 60 |
+
|
| 61 |
+
# Define an asynchronous function
|
| 62 |
+
async def initiate_chat():
|
| 63 |
+
await user_proxy.a_initiate_chat(
|
| 64 |
+
assistant,
|
| 65 |
+
message=user_input,
|
| 66 |
+
)
|
| 67 |
+
|
| 68 |
+
# Run the asynchronous function within the event loop
|
| 69 |
+
loop.run_until_complete(initiate_chat())
|
requirements.txt
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
aiohttp==3.8.6
|
| 2 |
+
aiosignal==1.3.1
|
| 3 |
+
altair==5.1.2
|
| 4 |
+
async-timeout==4.0.3
|
| 5 |
+
attrs==23.1.0
|
| 6 |
+
blinker==1.6.3
|
| 7 |
+
cachetools==5.3.2
|
| 8 |
+
certifi==2023.7.22
|
| 9 |
+
charset-normalizer==3.3.1
|
| 10 |
+
click==8.1.7
|
| 11 |
+
diskcache==5.6.3
|
| 12 |
+
docker==6.1.3
|
| 13 |
+
FLAML==2.1.1
|
| 14 |
+
frozenlist==1.4.0
|
| 15 |
+
gitdb==4.0.11
|
| 16 |
+
GitPython==3.1.40
|
| 17 |
+
idna==3.4
|
| 18 |
+
importlib-metadata==6.8.0
|
| 19 |
+
Jinja2==3.1.2
|
| 20 |
+
jsonschema==4.19.1
|
| 21 |
+
jsonschema-specifications==2023.7.1
|
| 22 |
+
markdown-it-py==3.0.0
|
| 23 |
+
MarkupSafe==2.1.3
|
| 24 |
+
mdurl==0.1.2
|
| 25 |
+
multidict==6.0.4
|
| 26 |
+
numpy==1.26.1
|
| 27 |
+
openai==0.28.1
|
| 28 |
+
packaging==23.2
|
| 29 |
+
pandas==2.1.2
|
| 30 |
+
Pillow==10.1.0
|
| 31 |
+
protobuf==4.24.4
|
| 32 |
+
pyarrow==13.0.0
|
| 33 |
+
pyautogen==0.1.13
|
| 34 |
+
pydeck==0.8.1b0
|
| 35 |
+
Pygments==2.16.1
|
| 36 |
+
python-dateutil==2.8.2
|
| 37 |
+
python-dotenv==1.0.0
|
| 38 |
+
pytz==2023.3.post1
|
| 39 |
+
referencing==0.30.2
|
| 40 |
+
requests==2.31.0
|
| 41 |
+
rich==13.6.0
|
| 42 |
+
rpds-py==0.10.6
|
| 43 |
+
six==1.16.0
|
| 44 |
+
smmap==5.0.1
|
| 45 |
+
streamlit==1.28.0
|
| 46 |
+
tenacity==8.2.3
|
| 47 |
+
termcolor==2.3.0
|
| 48 |
+
toml==0.10.2
|
| 49 |
+
toolz==0.12.0
|
| 50 |
+
tornado==6.3.3
|
| 51 |
+
tqdm==4.66.1
|
| 52 |
+
typing_extensions==4.8.0
|
| 53 |
+
tzdata==2023.3
|
| 54 |
+
tzlocal==5.2
|
| 55 |
+
urllib3==2.0.7
|
| 56 |
+
validators==0.22.0
|
| 57 |
+
websocket-client==1.6.4
|
| 58 |
+
yarl==1.9.2
|
| 59 |
+
zipp==3.17.0
|