feat: Add discord bot

Former-commit-id: 9f47cc2bff
discord-bot
Zack 2 years ago
parent d47e8d1efe
commit 213053cc1e

@ -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

@ -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)
<div align="center">

@ -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

@ -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(

@ -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 = "<div style='max-height:400px;overflow-y:scroll;'>"
chat_str="<div style='max-height:400px;overflow-y:scroll;'>"
for message in chat_history:
if message['type'] == 'user':
chat_str += f"<p><strong>User:</strong> {message['content']}</p>"
elif message['type'] == 'text':
chat_str += f"<p><strong>Agent:</strong> {message['content']}</p>"
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"<p><strong>Agent:</strong> <img src='data:image/png;base64,{base64_img}' alt='image' width='200'/></p>"
chat_str += "</div>"
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:

@ -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,

Loading…
Cancel
Save