Skip to content

Commit

Permalink
[PROGRESS UPDATE]
Browse files Browse the repository at this point in the history
  • Loading branch information
Kye committed Dec 8, 2023
1 parent b1d1ba5 commit f21d473
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 18 deletions.
5 changes: 0 additions & 5 deletions .vscode/settings.json

This file was deleted.

8 changes: 2 additions & 6 deletions errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@ DEBUG:jaxlib.mlir._mlir_libs:Registering dialects from initializer <module 'jaxl
Registering dialects from initializer <module 'jaxlib.mlir._mlir_libs._site_initialize_0' from '/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/jaxlib/mlir/_mlir_libs/_site_initialize_0.so'>
DEBUG:jax._src.path:etils.epath was not found. Using pathlib for file I/O.
etils.epath was not found. Using pathlib for file I/O.
INFO: Started server process [46156]
INFO: Started server process [47939]
INFO: Waiting for application startup.
INFO: Application startup complete.
INFO: Uvicorn running on http://0.0.0.0:8000 (Press CTRL+C to quit)
INFO: Shutting down
INFO: Waiting for application shutdown.
INFO: Application shutdown complete.
INFO: Finished server process [46156]
INFO: Uvicorn running on http://0.0.0.0:8001 (Press CTRL+C to quit)
4 changes: 2 additions & 2 deletions example_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@


# Define the API endpoint
url = "http://localhost:8000/agent"
url = "http://localhost:8001/agent"

# Define the task for the agent
task = "Generate a 10,000 word blog on health and wellness."

# Define the payload for the POST request
payload = {
"msg": task,
"task": task,
}

# Send the POST request to the API
Expand Down
5 changes: 2 additions & 3 deletions func_api_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@

# Initialize the API wrapper
api = FuncAPIWrapper(
host = "0.0.0.0",
port = 8000,
port=8001,
)


Expand All @@ -39,7 +38,7 @@
)


@api.add("/agent")
@api.add("/agent", method="post")
def agent_method(task: str):
"""Agent method
Expand Down
13 changes: 13 additions & 0 deletions func_api_example2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from swarms_cloud.func_api_wrapper import FuncAPIWrapper

api = FuncAPIWrapper(
port=8001,
)


@api.add("/agent", method="post")
def check():
return "Hello World"


api.run()
12 changes: 10 additions & 2 deletions swarms_cloud/func_api_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import uvicorn
from fastapi import FastAPI, HTTPException

# Logger initialization
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)

Expand Down Expand Up @@ -90,7 +91,14 @@ def add(self, path: str, method: str = "post", *args, **kwargs):

def decorator(func: Callable):
try:

if method.lower() == "get":
endpoint_func = self.app.get(path)
elif method.lower() == "post":
endpoint_func = self.app.post(path)
else:
raise ValueError(f"Invalid method: {method}")

@endpoint_func
async def endpoint_wrapper(*args, **kwargs):
try:
logger.info(f"Calling method {func.__name__}")
Expand All @@ -100,7 +108,7 @@ async def endpoint_wrapper(*args, **kwargs):
logger.error(f"Error in {func.__name__}: {error}")
raise HTTPException(status_code=500, detail=str(error))

# Register the endpoint with the hhttp methopd
# Register the endpoint with the http method
endpoint_func = getattr(self.app, method.lower())
endpoint_func(path)(endpoint_wrapper)
return func
Expand Down

0 comments on commit f21d473

Please sign in to comment.