Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickbdevaney committed Dec 11, 2024
2 parents c313eeb + 7192dc0 commit efa4f5c
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 19 deletions.
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ AZURE_OPENAI_DEPLOYMENT=your_azure_openai_deployment
OPENAI_API_VERSION=your_openai_api_version
AZURE_OPENAI_API_KEY=your_azure_openai_api_key
AZURE_OPENAI_AD_TOKEN=your_azure_openai_ad_token
#AWS_LAMBDA_FUNCTION_NAME=your_aws_lambda_function_name

49 changes: 49 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -224,3 +224,52 @@ cython_debug/
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
.vscode/settings.json
# -*- mode: gitignore; -*-
*~
\#*\#
/.emacs.desktop
/.emacs.desktop.lock
*.elc
auto-save-list
tramp
.\#*

# Org-mode
.org-id-locations
*_archive

# flymake-mode
*_flymake.*

# eshell files
/eshell/history
/eshell/lastdir

# elpa packages
/elpa/

# reftex files
*.rel

# AUCTeX auto folder
/auto/

# cask packages
.cask/
dist/

# Flycheck
flycheck_*.el

# server auth directory
/server/

# projectiles files
.projectile

# directory configuration
.dir-locals.el

# network security
/network-security.data

15 changes: 12 additions & 3 deletions api/agent_api.py → api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from swarms import Agent
from dotenv import load_dotenv

print ("starting")
# Load environment variables
load_dotenv()

Expand Down Expand Up @@ -613,17 +614,25 @@ async def _cleanup_old_metrics(self, agent_id: UUID):

def create_app() -> FastAPI:
"""Create and configure the FastAPI application."""
print("create app")
api = SwarmsAPI()
return api.app


if __name__ == "__main__":
#if __name__ == "__main__":
if __name__ == '__main__':
#freeze_support()
print("yes in main")
# Configure uvicorn logging
logger.info("API Starting")

uvicorn.run(
"main:create_app",
host="0.0.0.0",
port=8000,
reload=True,
workers=4,
# reload=True,
# workers=4,
)
else:
print("not in main")

38 changes: 22 additions & 16 deletions swarms/structs/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -2388,36 +2388,42 @@ def handle_artifacts(
) -> None:
"""Handle creating and saving artifacts with error handling."""
try:
logger.info(
f"Creating artifact for file: {file_output_path}"
)
# Ensure file_extension starts with a dot
if not file_extension.startswith('.'):
file_extension = '.' + file_extension

# If file_output_path doesn't have an extension, treat it as a directory
# and create a default filename based on timestamp
if not os.path.splitext(file_output_path)[1]:
timestamp = time.strftime("%Y%m%d_%H%M%S")
filename = f"artifact_{timestamp}{file_extension}"
full_path = os.path.join(file_output_path, filename)
else:
full_path = file_output_path

# Create the directory if it doesn't exist
os.makedirs(os.path.dirname(full_path), exist_ok=True)

logger.info(f"Creating artifact for file: {full_path}")
artifact = Artifact(
file_path=file_output_path,
file_path=full_path,
file_type=file_extension,
contents=text,
edit_count=0,
)

logger.info(
f"Saving artifact with extension: {file_extension}"
)
logger.info(f"Saving artifact with extension: {file_extension}")
artifact.save_as(file_extension)
logger.success(
f"Successfully saved artifact to {file_output_path}"
)
logger.success(f"Successfully saved artifact to {full_path}")

except ValueError as e:
logger.error(
f"Invalid input values for artifact: {str(e)}"
)
logger.error(f"Invalid input values for artifact: {str(e)}")
raise
except IOError as e:
logger.error(f"Error saving artifact to file: {str(e)}")
raise
except Exception as e:
logger.error(
f"Unexpected error handling artifact: {str(e)}"
)
logger.error(f"Unexpected error handling artifact: {str(e)}")
raise

def showcase_config(self):
Expand Down

0 comments on commit efa4f5c

Please sign in to comment.