pull/709/head
harshalmore31 4 months ago
parent 452be52013
commit fdcf91e83a

@ -84,8 +84,7 @@ def load_prompts_from_json() -> Dict[str, str]:
AGENT_PROMPTS = load_prompts_from_json() AGENT_PROMPTS = load_prompts_from_json()
def initialize_agents(dynamic_temp: float, agent_keys: List[str], model_name: str, def initialize_agents(dynamic_temp: float, agent_keys: List[str]) -> List[Agent]:
provider: str, api_key: str, temperature:float, max_tokens:int) -> List[Agent]:
agents = [] agents = []
seen_names = set() seen_names = set()
for agent_key in agent_keys: for agent_key in agent_keys:
@ -103,18 +102,10 @@ def initialize_agents(dynamic_temp: float, agent_keys: List[str], model_name: st
counter += 1 counter += 1
seen_names.add(agent_name) seen_names.add(agent_name)
llm = LiteLLM(
model_name=model_name,
system_prompt=agent_prompt,
temperature=temperature,
max_tokens = max_tokens,
)
agent = Agent( agent = Agent(
agent_name=f"Agent-{agent_name}", agent_name=f"Agent-{agent_name}",
system_prompt=agent_prompt, system_prompt=agent_prompt,
llm=llm, llm=model,
max_loops=1, max_loops=1,
autosave=True, autosave=True,
verbose=True, verbose=True,
@ -124,7 +115,7 @@ def initialize_agents(dynamic_temp: float, agent_keys: List[str], model_name: st
retry_attempts=1, retry_attempts=1,
context_length=200000, context_length=200000,
output_type="string", # here is the output type which is string output_type="string", # here is the output type which is string
temperature=dynamic_temp, temperature=dynamic_temp, # THIS LINE IS CHANGED
) )
agents.append(agent) agents.append(agent)
@ -736,47 +727,8 @@ def create_app():
lines=3 lines=3
) )
with gr.Row(): with gr.Row():
with gr.Column(scale=1):
# Get available agent prompts
available_prompts = list(AGENT_PROMPTS.keys()) if AGENT_PROMPTS else ["No agents available"]
agent_prompt_selector = gr.Dropdown(
label="Select Agent Prompts",
choices=available_prompts,
value=[available_prompts[0]] if available_prompts else None,
multiselect=True,
interactive=True
)
with gr.Column(scale=1):
# Get available swarm types
swarm_types = [
"SequentialWorkflow", "ConcurrentWorkflow","AgentRearrange",
"MixtureOfAgents", "SpreadSheetSwarm", "auto"
]
agent_selector = gr.Dropdown(
label="Select Swarm",
choices=swarm_types,
value=swarm_types[0],
multiselect=False,
interactive=True
)
# Flow configuration components for AgentRearrange with gr.Column(scale=1):
with gr.Column(visible=False) as flow_config:
flow_text = gr.Textbox(
label="Agent Flow Configuration",
placeholder="Enter agent flow !",
lines=2
)
gr.Markdown(
"""
**Flow Configuration Help:**
- Enter agent names separated by ' -> '
- Example: Agent1 -> Agent2 -> Agent3
- Use exact agent names from the prompts above
"""
)
with gr.Column(scale=2, min_width=200):
with gr.Row(): with gr.Row():
# Provider selection dropdown # Provider selection dropdown
provider_dropdown = gr.Dropdown( provider_dropdown = gr.Dropdown(
@ -799,17 +751,28 @@ def create_app():
placeholder="Enter your API key", placeholder="Enter your API key",
type="password", type="password",
) )
with gr.Column(scale=1):
with gr.Row(): with gr.Row():
# temp slider dynamic_slider = gr.Slider(
temperature_slider = gr.Slider( label="Dyn. Temp",
label="Temperature",
minimum=0, minimum=0,
maximum=1, maximum=1,
value=0.1, value=0.1,
step=0.01 step=0.01
) )
# with gr.Row(): # with gr.Row():
# max tokens slider # max tokens slider
max_loops_slider = gr.Slider(
label="Max Loops",
minimum=1,
maximum=10,
value=1,
step=1
)
with gr.Row():
max_tokens_slider = gr.Slider( max_tokens_slider = gr.Slider(
label="Max Tokens", label="Max Tokens",
minimum=100, minimum=100,
@ -818,28 +781,58 @@ def create_app():
step=100, step=100,
) )
with gr.Row(): with gr.Column(scale=2, min_width=200):
max_loops_slider = gr.Slider( with gr.Column(scale=1):
label="Max Loops", # Get available agent prompts
minimum=1, available_prompts = list(AGENT_PROMPTS.keys()) if AGENT_PROMPTS else ["No agents available"]
maximum=10, agent_prompt_selector = gr.Dropdown(
value=1, label="Select Agent Prompts",
step=1 choices=available_prompts,
value=[available_prompts[0]] if available_prompts else None,
multiselect=True,
interactive=True
) )
with gr.Row(): # with gr.Column(scale=1):
dynamic_slider = gr.Slider( # Get available swarm types
label="Dyn. Temp", swarm_types = [
minimum=0, "SequentialWorkflow", "ConcurrentWorkflow","AgentRearrange",
maximum=1, "MixtureOfAgents", "SpreadSheetSwarm", "auto"
value=0.1, ]
step=0.01 agent_selector = gr.Dropdown(
label="Select Swarm",
choices=swarm_types,
value=swarm_types[0],
multiselect=False,
interactive=True
) )
with gr.Row():
loading_status = gr.Textbox( # Flow configuration components for AgentRearrange
label="Status", with gr.Column(visible=False) as flow_config:
value="Ready", flow_text = gr.Textbox(
interactive=False label="Agent Flow Configuration",
placeholder="Enter agent flow !",
lines=2
) )
gr.Markdown(
"""
**Flow Configuration Help:**
- Enter agent names separated by ' -> '
- Example: Agent1 -> Agent2 -> Agent3
- Use exact agent names from the prompts above
"""
)
# with gr.Row():
# temperature_slider = gr.Slider(
# label="Temperature",
# minimum=0,
# maximum=1,
# value=0.1,
# step=0.01
# )
#Hidden textbox to store API Key #Hidden textbox to store API Key
env_api_key_textbox = gr.Textbox( env_api_key_textbox = gr.Textbox(
value="", value="",
@ -847,8 +840,17 @@ def create_app():
) )
with gr.Row(): with gr.Row():
with gr.Column(scale=1):
run_button = gr.Button("Run Task", variant="primary") run_button = gr.Button("Run Task", variant="primary")
cancel_button = gr.Button("Cancel", variant="secondary") cancel_button = gr.Button("Cancel", variant="secondary")
with gr.Column(scale=1):
with gr.Row():
loading_status = gr.Textbox(
label="Status",
value="Ready",
interactive=False
)
# Add loading indicator and status # Add loading indicator and status
with gr.Row(): with gr.Row():
@ -892,79 +894,36 @@ def create_app():
models = filtered_models.get(provider, []) models = filtered_models.get(provider, [])
return gr.update(choices=models, value=models[0] if models else None) return gr.update(choices=models, value=models[0] if models else None)
async def run_task_wrapper(task, max_loops, dynamic_temp, swarm_type, agent_prompt_selector, flow_text, async def run_task_wrapper(task, max_loops, dynamic_temp, swarm_type, agent_prompt_selector, flow_text):
provider, model_name, api_key, temperature, max_tokens):
"""Execute the task and update the UI with progress.""" """Execute the task and update the UI with progress."""
try: try:
if not task: if not task:
yield "Please provide a task description.", "Error: Missing task", "" yield "Please provide a task description.", "Error: Missing task"
return return
if not agent_prompt_selector or len(agent_prompt_selector) == 0: if not agent_prompt_selector or len(agent_prompt_selector) == 0:
yield "Please select at least one agent.", "Error: No agents selected", "" yield "Please select at least one agent.", "Error: No agents selected"
return
if not provider:
yield "Please select a provider.", "Error: No provider selected", ""
return return
if not model_name:
yield "Please select a model.", "Error: No model selected", ""
return
if not api_key:
yield "Please enter an API Key", "Error: API Key is required", ""
return
# Update status # Update status
yield "Processing...", "Running task...", "" yield "Processing...", "Running task..."
# Prepare flow for AgentRearrange # Prepare flow for AgentRearrange
flow = None flow = None
if swarm_type == "AgentRearrange": if swarm_type == "AgentRearrange":
if not flow_text: if not flow_text:
yield "Please provide the agent flow configuration.", "Error: Flow not configured", "" yield "Please provide the agent flow configuration.", "Error: Flow not configured"
return return
flow = flow_text flow = flow_text
# Save API key to .env
env_path = find_dotenv()
if provider == "openai":
set_key(env_path, "OPENAI_API_KEY", api_key)
elif provider == "anthropic":
set_key(env_path, "ANTHROPIC_API_KEY", api_key)
elif provider == "cohere":
set_key(env_path, "COHERE_API_KEY", api_key)
elif provider == "gemini":
set_key(env_path, "GEMINI_API_KEY", api_key)
elif provider == "mistral":
set_key(env_path, "MISTRAL_API_KEY", api_key)
elif provider == "groq":
set_key(env_path, "GROQ_API_KEY", api_key)
elif provider == "nvidia_nim":
set_key(env_path, "NVIDIA_NIM_API_KEY", api_key)
elif provider == "huggingface":
set_key(env_path, "HUGGINGFACE_API_KEY", api_key)
elif provider == "perplexity":
set_key(env_path, "PERPLEXITY_API_KEY", api_key)
else:
yield f"Error: {provider} this provider is not present", f"Error: {provider} not supported", ""
return
# Execute task # Execute task
result, router, error = await execute_task( result, router, error = await execute_task(
task=task, task=task,
max_loops=max_loops, max_loops=max_loops,
dynamic_temp=dynamic_temp, dynamic_temp=dynamic_temp, # THIS LINE IS CHANGED
swarm_type=swarm_type, swarm_type=swarm_type,
agent_keys=agent_prompt_selector, agent_keys=agent_prompt_selector,
flow=flow, flow=flow
model_name=model_name,
provider=provider,
api_key=api_key,
temperature=temperature,
max_tokens = max_tokens,
) )
if error: if error:
@ -1038,7 +997,6 @@ def create_app():
provider_dropdown, provider_dropdown,
model_dropdown, model_dropdown,
api_key_input, api_key_input,
temperature_slider,
max_tokens_slider max_tokens_slider
], ],
outputs=[agent_output_display, loading_status, env_api_key_textbox] outputs=[agent_output_display, loading_status, env_api_key_textbox]

Loading…
Cancel
Save