diff --git a/swarms_cloud/__init__.py b/swarms_cloud/__init__.py index 7609639..015d053 100644 --- a/swarms_cloud/__init__.py +++ b/swarms_cloud/__init__.py @@ -1,10 +1,14 @@ from swarms_cloud.main import agent_api_wrapper from swarms_cloud.rate_limiter import rate_limiter from swarms_cloud.func_api_wrapper import api_wrapper, FuncAPIWrapper +from swarms_cloud.api_key_generator import generate_api_key +from swarms_cloud.sky_api import SkyInterface __all__ = [ "agent_api_wrapper", "rate_limiter", "api_wrapper", "FuncAPIWrapper", + "generate_api_key", + "SkyInterface", ] diff --git a/swarms_cloud/agent_types.py b/swarms_cloud/agent_types.py index 0690541..55db9d6 100644 --- a/swarms_cloud/agent_types.py +++ b/swarms_cloud/agent_types.py @@ -6,7 +6,39 @@ class AgentParameters(BaseModel): """Agent Parameters Args: - BaseModel (_type_): _description_ + temperature (float, optional): _description_. Defaults to None. + model_name (str, optional): _description_. Defaults to None. + openai_api_key (str, optional): _description_. Defaults to None. + id (str, optional): _description_. Defaults to None. + llm (Any, optional): _description_. Defaults to None. + template (Optional[str], optional): _description_. Defaults to None. + max_loops (int, optional): _description_. Defaults to 5. + stopping_condition (Optional[Callable], optional): _description_. Defaults to None. + loop_interval (int, optional): _description_. Defaults to 1. + retry_attempts (int, optional): _description_. Defaults to 3. + retry_interval (int, optional): _description_. Defaults to 1. + return_history (bool, optional): _description_. Defaults to False. + stopping_token (str, optional): _description_. Defaults to None. + dynamic_loops (Optional[bool], optional): _description_. Defaults to False. + interactive (bool, optional): _description_. Defaults to False. + dashboard (bool, optional): _description_. Defaults to False. + agent_name (str, optional): _description_. Defaults to "Autonomous-Agent-XYZ1B". + agent_description (str, optional): _description_. Defaults to None. + system_prompt (str, optional): _description_. Defaults to None. + tools (List[Any], optional): _description_. Defaults to None. + dynamic_temperature_enabled (Optional[bool], optional): _description_. Defaults to False. + sop (Optional[str], optional): _description_. Defaults to None. + sop_list (Optional[List[str]], optional): _description_. Defaults to None. + saved_state_path (Optional[str], optional): _description_. Defaults to None. + autosave (Optional[bool], optional): _description_. Defaults to False. + context_length (Optional[int], optional): _description_. Defaults to 8192. + user_name (str, optional): _description_. Defaults to "Human:". + self_healing_enabled (Optional[bool], optional): _description_. Defaults to False. + code_interpreter (Optional[bool], optional): _description_. Defaults to False. + multi_modal (Optional[bool], optional): _description_. Defaults to None. + pdf_path (Optional[str], optional): _description_. Defaults to None. + + """ temperature: float = None diff --git a/swarms_cloud/parse_file.py b/swarms_cloud/parse_file.py deleted file mode 100644 index a5406cc..0000000 --- a/swarms_cloud/parse_file.py +++ /dev/null @@ -1,147 +0,0 @@ -import ast -import astor - - -class CodeTransformer(ast.NodeTransformer): - def __init__(self): - self.agent_logic = [] - - def visit_Assign(self, node): - if ( - isinstance(node.value, ast.Call) - and getattr(node.value.func, "id", "") == "Agent" - ): - self.agent_logic.append(node) - return None - return node - - def visit_Expr(self, node): - if ( - isinstance(node.value, ast.Call) - and getattr(node.value.func, "id", "") == "Agent" - ): - self.agent_logic.append(node) - return None - return node - - -def wrap_with_fastapi(input_code): - tree = ast.parse(input_code) - transformer = CodeTransformer() - transformer.visit(tree) - - # Define the agent_method function - agent_function = ast.FunctionDef( - name="agent_method", - args=ast.arguments( - args=[], - vararg=None, - kwarg=None, - posonlyargs=[], - kwonlyargs=[], - kw_defaults=[], - defaults=[], - ), - body=transformer.agent_logic, - decorator_list=[ - ast.Call( - func=ast.Attribute( - value=ast.Name(id="app", ctx=ast.Load()), - attr="post", - ctx=ast.Load(), - ), - args=[], - keywords=[ast.keyword(arg="path", value=ast.Str(s="/agent"))], - ) - ], - ) - - # Add necessary imports - imports = [ - ast.Import(names=[ast.alias(name="FastAPI", asname=None)]), - ast.ImportFrom( - module="swarms.structs.agent", - names=[ast.alias(name="Agent", asname=None)], - level=0, - ), - ast.ImportFrom( - module="swarms_cloud", - names=[ast.alias(name="agent_api_wrapper", asname=None)], - level=0, - ), - ast.ImportFrom( - module="uvicorn", names=[ast.alias(name="uvicorn", asname=None)], level=0 - ), - ] - - # Insert imports at the beginning - for imp in reversed(imports): - tree.body.insert(0, imp) - - # Insert FastAPI app initialization - tree.body.insert( - len(imports), - ast.Assign( - targets=[ast.Name(id="app", ctx=ast.Store())], - value=ast.Call( - func=ast.Name(id="FastAPI", ctx=ast.Load()), args=[], keywords=[] - ), - ), - ) - - # Add the agent_method function - tree.body.append(agent_function) - - # Code to run the app with uvicorn - run_app_code = ast.parse( - "if __name__ == '__main__':\n uvicorn.run(app, host='0.0.0.0', port=8000)" - ).body - tree.body.extend(run_app_code) - - return astor.to_source(tree) - - -# Example Usage -input_code = """ - - - -import os - -from dotenv import load_dotenv - -# Import the OpenAIChat model and the Agent struct -from swarms.models import OpenAIChat -from swarms.structs import Agent - -# Load the environment variables -load_dotenv() - -# Get the API key from the environment -api_key = os.environ.get("OPENAI_API_KEY") - -# Initialize the language model -llm = OpenAIChat( - temperature=0.5, - model_name="gpt-4", - openai_api_key=api_key, -) - - -## Initialize the workflow -agent = Agent( - llm=llm, - max_loops=1, - autosave=True, - dashboard=True, -) - -# Run the workflow on a task -out = agent.run("Generate a 10,000 word blog on health and wellness.") -print(out) - - - -""" -output_code = wrap_with_fastapi(input_code) -print(output_code) diff --git a/swarms_cloud/prep_file.py b/swarms_cloud/prep_file.py deleted file mode 100644 index d70d54b..0000000 --- a/swarms_cloud/prep_file.py +++ /dev/null @@ -1,68 +0,0 @@ -def wrap_file_with_fastapi( - input_file_path, output_file_path, endpoint_path, http_method="post" -): - # Read the input file - with open(input_file_path, "r") as file: - original_code = file.read() - - # Extract the main logic into a new function - agent_function_logic = """ - def run_agent_task(): - # Original agent logic - agent = Agent( - llm=llm, - max_loops=1, - autosave=True, - dashboard=True, - ) - return agent.run("Generate a 10,000 word blog on health and wellness.") - """ - - # Full template with FastAPI and agent_api_wrapper - fastapi_template = f"""import os - from dotenv import load_dotenv - from fastapi import FastAPI - from swarms.models import OpenAIChat - from swarms.structs import Agent - from your_module_where_decorator_is import agent_api_wrapper - - # Load the environment variables - load_dotenv() - - # Get the API key from the environment - api_key = os.environ.get("OPENAI_API_KEY") - - # Initialize the language model - llm = OpenAIChat( - temperature=0.5, - model_name="gpt-4", - openai_api_key=api_key, - ) - - app = FastAPI() - - @agent_api_wrapper(Agent, app, path="{endpoint_path}", http_method="{http_method}") - {agent_function_logic} - - # Original code without the agent initialization and run logic - {original_code} - """ - - # Remove the original Agent initialization and run logic from the original code - fastapi_template = fastapi_template.replace("## Initialize the workflow\n", "") - fastapi_template = fastapi_template.replace( - "agent = Agent(\n llm=llm,\n max_loops=1,\n autosave=True,\n dashboard=True,\n)\n\n", - "", - ) - fastapi_template = fastapi_template.replace( - '# Run the workflow on a task\nout = agent.run("Generate a 10,000 word blog on health and wellness.")\nprint(out)', - "", - ) - - # Write the modified code to a new output file - with open(output_file_path, "w") as file: - file.write(fastapi_template) - - -# Example usage -wrap_file_with_fastapi("input_file.py", "output_file.py", "/run-agent")