From 213053cc1e2703455e8405a8f07a079f6bf2b497 Mon Sep 17 00:00:00 2001 From: Zack Date: Fri, 6 Oct 2023 13:47:39 -0500 Subject: [PATCH] feat: Add discord bot Former-commit-id: 9f47cc2bff9e0f02a9bab441b3ceddca0965a6dd --- .github/workflows/update_space.yml | 28 +++++++++++++++++++ README.md | 6 ++++ docs/marketing.md | 12 ++++++++ groupchat.py | 26 ++++++++++-------- omni_ui.py | 44 ++++++++++++++---------------- swarms/swarms/groupchat.py | 4 +-- 6 files changed, 83 insertions(+), 37 deletions(-) create mode 100644 .github/workflows/update_space.yml create mode 100644 docs/marketing.md diff --git a/.github/workflows/update_space.yml b/.github/workflows/update_space.yml new file mode 100644 index 00000000..27449783 --- /dev/null +++ b/.github/workflows/update_space.yml @@ -0,0 +1,28 @@ +name: Run Python script + +on: + push: + branches: + - discord-bot + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: '3.9' + + - name: Install Gradio + run: python -m pip install gradio + + - name: Log in to Hugging Face + run: python -c 'import huggingface_hub; huggingface_hub.login(token="${{ secrets.hf_token }}")' + + - name: Deploy to Spaces + run: gradio deploy diff --git a/README.md b/README.md index 5f0a833b..ea65b026 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,9 @@ +--- +title: omni_bot +app_file: omni_ui.py +sdk: gradio +sdk_version: 3.33.1 +--- ![Swarming banner icon](images/swarmsbanner.png)
diff --git a/docs/marketing.md b/docs/marketing.md new file mode 100644 index 00000000..24dabafb --- /dev/null +++ b/docs/marketing.md @@ -0,0 +1,12 @@ +Monitezation of the Swarm +========================= +The swarm is a free and open source frame work for building autonous agents in the form of swarms + +some possible ways to monitize the swarm are: + + - selling the swarm as a service + -through eg the domain where users can pay a fee to have their swarm hosted on the swarm server + -Consumer interface for them to interact with their swarm subscription 99 per month interact + -swarm as a service + + diff --git a/groupchat.py b/groupchat.py index 76e5aba9..4cc74fbf 100644 --- a/groupchat.py +++ b/groupchat.py @@ -3,8 +3,8 @@ from swarms.swarms import GroupChat, GroupChatManager from swarms.workers import Worker llm = OpenAIChat( - model_name='gpt-4', - openai_api_key="api-key", + model_name='gpt-4', + openai_api_key="api-key", temperature=0.5 ) @@ -12,27 +12,27 @@ node = Worker( llm=llm, ai_name="Optimus Prime", ai_role="Worker in a swarm", - external_tools = None, - human_in_the_loop = False, - temperature = 0.5, + external_tools=None, + human_in_the_loop=False, + temperature=0.5, ) node2 = Worker( llm=llm, ai_name="Optimus Prime", ai_role="Worker in a swarm", - external_tools = None, - human_in_the_loop = False, - temperature = 0.5, + external_tools=None, + human_in_the_loop=False, + temperature=0.5, ) node3 = Worker( llm=llm, ai_name="Optimus Prime", ai_role="Worker in a swarm", - external_tools = None, - human_in_the_loop = False, - temperature = 0.5, + external_tools=None, + human_in_the_loop=False, + temperature=0.5, ) nodes = [ @@ -57,7 +57,9 @@ group = GroupChat( manager = GroupChatManager( groupchat=group, - max_consecutive_auto_reply=3, + # max_consecutive_auto_reply=3, + # human_input_mode="NEVER", + # system_message="Group chat manager" ) output = group.run( diff --git a/omni_ui.py b/omni_ui.py index f3e0c4f6..d8119516 100644 --- a/omni_ui.py +++ b/omni_ui.py @@ -7,77 +7,77 @@ import base64 from langchain.llms import OpenAIChat from swarms.agents import OmniModalAgent import gradio_client as grc +from dspy import Program, Prompt, Finetune, Decompose +from dspy import Program, Prompt, Finetune, Decompose +from dspy.retrieval import retrieve -grc.Client("Wawaa/omniagent").deploy_discord() - -# Function to convert image to base64 +program = Program( + Decompose( + Prompt("I have 4 shirts that take 5hrs to dry long shoul") + ) +grc.Client("Wawaa/omni_bot").deploy_discord() +# Function to convert image to base64 def image_to_base64(image_path): with open(image_path, "rb") as image_file: return base64.b64encode(image_file.read()).decode() # Function to get the most recently created image in the directory - - def get_latest_image(): - list_of_files = glob.glob('./*.png') # Replace with your image file type + list_of_files=glob.glob('./*.png') # Replace with your image file type if not list_of_files: return None - latest_file = max(list_of_files, key=os.path.getctime) + latest_file=max(list_of_files, key=os.path.getctime) return latest_file # Initialize your OmniModalAgent -llm = OpenAIChat(model_name="gpt-4") # Replace with your actual initialization -agent = OmniModalAgent(llm) # Replace with your actual initialization +llm=OpenAIChat(model_name="gpt-4") # Replace with your actual initialization +agent=OmniModalAgent(llm) # Replace with your actual initialization # Global variable to store chat history -chat_history = [] +chat_history=[] # Function to update chat - - def update_chat(user_input): global chat_history chat_history.append({"type": "user", "content": user_input}) # Get agent response - agent_response = agent.run(user_input) + agent_response=agent.run(user_input) # Handle the case where agent_response is not in the expected dictionary format if not isinstance(agent_response, dict): - agent_response = {"type": "text", "content": str(agent_response)} + agent_response={"type": "text", "content": str(agent_response)} chat_history.append(agent_response) # Check for the most recently created image and add it to the chat history - latest_image = get_latest_image() + latest_image=get_latest_image() if latest_image: chat_history.append({"type": "image", "content": latest_image}) return render_chat(chat_history) # Function to render chat as HTML - - def render_chat(chat_history): - chat_str = "
" + chat_str="
" for message in chat_history: if message['type'] == 'user': chat_str += f"

User: {message['content']}

" elif message['type'] == 'text': chat_str += f"

Agent: {message['content']}

" elif message['type'] == 'image': - img_path = os.path.join(".", message['content']) - base64_img = image_to_base64(img_path) + img_path=os.path.join(".", message['content']) + base64_img=image_to_base64(img_path) chat_str += f"

Agent: image

" chat_str += "
" return chat_str # Define Gradio interface -iface = Interface( +iface=Interface( fn=update_chat, inputs=Textbox(label="Your Message", type="text"), outputs=HTML(label="Chat History"), @@ -85,8 +85,6 @@ iface = Interface( ) # Function to update the chat display - - def update_display(): global chat_history while True: diff --git a/swarms/swarms/groupchat.py b/swarms/swarms/groupchat.py index d5d8ddc4..1efcbc58 100644 --- a/swarms/swarms/groupchat.py +++ b/swarms/swarms/groupchat.py @@ -77,14 +77,14 @@ class GroupChatManager(Worker): def __init__( self, groupchat: GroupChat, - ai_name: Optional[str] = "chat_manager", + name: Optional[str] = "chat_manager", max_consecutive_auto_reply: Optional[int] = sys.maxsize, human_input_mode: Optional[str] = "NEVER", system_message: Optional[str] = "Group chat manager", **kwargs ): super().__init__( - ai_name=ai_name, + name=name, max_consecutive_auto_reply=max_consecutive_auto_reply, human_input_mode=human_input_mode, system_message=system_message,