Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interactive UI for Swarms Framework #733

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

harshalmore31
Copy link
Collaborator

@harshalmore31 harshalmore31 commented Jan 9, 2025

Interactive UI for Swarms Framework: Swarm-Specific Parsing, Agent Management, and LLM Integration with Hugging Face Deployment & Local Deployment

Description:

  • Developed a robust and feature-rich UI for the Swarms framework using Gradio, focused on enhancing usability, modularity, and interactive capabilities. Key additions include:
    • Swarm-Specific Parsing:
      • Implemented parsers for all swarm types, including SequentialWorkflow, ConcurrentWorkflow, AgentRearrange, MixtureOfAgents, SpreadSheetSwarm, and auto.
      • Ensures consistent formatting of output data and detailed feedback for each workflow type.
    • Dynamic Prompt Loading:
      • Integrated functionality to load agent prompts dynamically from a JSON file.
      • Default prompts are used if the file is absent or improperly formatted.
    • Agent Management in UI:
      • Enabled creation of new agent prompts directly via the UI.
      • Supports editing and validation of custom prompts with seamless integration into the workflow configuration.
    • UI Framework Enhancements:
      • Introduced a dedicated UI class for streamlined Gradio component management, improving scalability and readability of the codebase.
      • Added modular components like dropdowns, sliders, and conditional inputs for an intuitive user experience.
    • LLM Integration:
      • Using LiteLLM, integrated the following models and providers:
        • OpenAI
        • Anthropic
        • Cohere
        • Gemini
        • Mistral
        • Groq
        • Perplexity

Key Features:

  • Interactive Swarm Configuration: Supports flexible configuration for workflows, including custom execution flows for AgentRearrange and advanced features like agent flow validation.
  • Agent-Centric Design: Facilitates agent selection, prompt management, and dynamic updates for added flexibility.
  • User Feedback and Debugging: Incorporates detailed logging, error handling, and status displays for enhanced user experience.

Issue:

  • Not linked to any specific issue. This PR focuses on establishing a functional and scalable UI layer for the Swarms framework.

Dependencies:

  • Gradio: Core framework for building the modular UI.
  • dotenv: Securely manages API keys and configurations.
  • litellm: Enables seamless integration with multiple language model providers and their respective models.

Deployment:

Tag Maintainer:

@kyegomez

Twitter Handle:

@harshalmore31


Additional Changes:

  • spreadsheet_swarm.py is modified accordingly for the working of UI


📚 Documentation preview 📚: https://swarms--733.org.readthedocs.build/en/733/

return f"Error: 'steps' data is None at index {i}"

if not isinstance(agent_output["steps"], list):
logger.error(f"Error: 'steps' data is not a list at index {i}")

Check failure

Code scanning / Bearer

Unsanitized dynamic input in file path Error

Unsanitized dynamic input in file path
elif swarm_type in ["SequentialWorkflow", "ConcurrentWorkflow"]:
return parse_sequential_workflow_output(data, error_display)
elif swarm_type == "SpreadSheetSwarm":
if os.path.exists(data):

Check failure

Code scanning / CodeQL

Uncontrolled data used in path expression High

This path depends on a
user-provided value
.
return f"Error: 'steps' data is None at index {i}"

if not isinstance(agent_output["steps"], list):
logger.error(f"Error: 'steps' data is not a list at index {i}")

Check failure

Code scanning / CodeQL

Uncontrolled data used in path expression High

This path depends on a
user-provided value
.
@@ -0,0 +1,1889 @@
import subprocess
import sys

Check failure

Code scanning / Pyre

Undefined import Error

Undefined import [21]: Could not find a module corresponding to import dotenv.

# Package installation function
def install_and_import_packages():
"""Auto-install and import required packages."""

Check failure

Code scanning / Pyre

Undefined import Error

Undefined import [21]: Could not find a module corresponding to import gradio.
'python-dotenv': 'dotenv',
'swarms': 'swarms',
'cryptography': 'cryptography',
'darkdetect': 'darkdetect'

Check failure

Code scanning / Pyre

Undefined import Error

Undefined import [21]: Could not find a module corresponding to import litellm.

agent = Agent(
agent_name=agent_name,
system_prompt=agent_prompt,

Check failure

Code scanning / Pyre

Incompatible variable type Error

Incompatible variable type [9]: flow is declared to have type str but is used as type None.
system_prompt=agent_prompt,
llm=llm,
max_loops=1,
autosave=True,

Check failure

Code scanning / Pyre

Incompatible variable type Error

Incompatible variable type [9]: api_key is declared to have type str but is used as type None.
if isinstance(result,dict):
result = json.dumps(
{
"input" : {

Check failure

Code scanning / Pyre

Uninitialized local Error

Uninitialized local [61]: Local variable timeout is undefined, or not always defined.
return
except asyncio.TimeoutError as e:
logger.error(f"Task execution timed out after {timeout} seconds", exc_info=True)
yield f"Task execution timed out after {timeout} seconds", gr.update(visible=True), ""

Check failure

Code scanning / Pyre

Uninitialized local Error

Uninitialized local [61]: Local variable timeout is undefined, or not always defined.
logger.error(f"Task execution timed out after {timeout} seconds", exc_info=True)
yield f"Task execution timed out after {timeout} seconds", gr.update(visible=True), ""
return
except litellm.exceptions.APIError as e: # Catch litellm APIError

Check failure

Code scanning / Pyre

Invalid except clause Error

Invalid except clause [66]: Exception handler type annotation unknown must extend BaseException.
logger.error(f"LiteLLM API Error: {e}", exc_info=True)
yield f"LiteLLM API Error: {e}", gr.update(visible=True), ""
return
except litellm.exceptions.AuthenticationError as e: # Catch litellm AuthenticationError

Check failure

Code scanning / Pyre

Invalid except clause Error

Invalid except clause [66]: Exception handler type annotation unknown must extend BaseException.

@staticmethod
def create_ui_theme(primary_color="red"):
import darkdetect # First install: pip install darkdetect

Check failure

Code scanning / Pyre

Undefined import Error

Undefined import [21]: Could not find a module corresponding to import darkdetect.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant