Skip to content

Commit

Permalink
fixing the api endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
mike dupont committed Jul 26, 2024
1 parent 38b9d54 commit 742847f
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 6 deletions.
2 changes: 1 addition & 1 deletion servers/agent/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ COPY . .
EXPOSE 8000

# Command to run the application
CMD ["uvicorn", "api:app", "--host", "0.0.0.0", "--port", "8000"]
CMD ["uvicorn", "api:app", "--host", "0.0.0.0", "--port", "8000", "--access-log", "--no-use-colors", "--log-level", "trace"]

# Additional optimizations:
# 1. Use multi-stage builds to separate the build environment from the runtime environment if necessary.
Expand Down
41 changes: 41 additions & 0 deletions servers/agent/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,44 @@ kubectl apply -f deployment.yaml
Look in eks and see that the resource has been deployed.
https://us-east-1.console.aws.amazon.com/eks/home?region=us-east-1#/clusters/cluster?selectedTab=cluster-resources-tab&selectedResourceId=pods

* describe
`kubectl describe service swarms-world`
gives
```
Name: swarms-world
Namespace: default
Labels: app=swarms-cloud-server-agent
Annotations: <none>
Selector: app=swarms-cloud-server-agent
Type: LoadBalancer
IP Family Policy: SingleStack
IP Families: IPv4
IP: 10.100.123.185
IPs: 10.100.123.185
LoadBalancer Ingress: a34f2f308013145858827f49a34f3bef-1801899861.us-east-1.elb.amazonaws.com
Port: <unset> 80/TCP
TargetPort: 8000/TCP
NodePort: <unset> 31384/TCP
Endpoints: 172.16.22.218:8000,172.16.27.42:8000,172.16.8.120:8000
Session Affinity: None
External Traffic Policy: Cluster
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal EnsuringLoadBalancer 8m53s (x3 over 12h) service-controller Ensuring load balancer
Normal EnsuredLoadBalancer 8m52s (x3 over 12h) service-controller Ensured load balancer
```

get the logs
`kubectl logs --all-containers=true -l app=swarms-cloud-server-agent`


Test locally
`docker compose build`
`docker compose up`

Roll out new version
`kubectl rollout restart deployment -l app=swarms-cloud-server-agent`
13 changes: 8 additions & 5 deletions servers/agent/api.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import asyncio
import os
from typing import List

import uvicorn
import tiktoken
from fastapi import FastAPI, HTTPException
from fastapi.middleware.cors import CORSMiddleware
Expand Down Expand Up @@ -95,7 +95,8 @@ async def model_router(model_name: str):


# Create a FastAPI app
app = FastAPI(debug=True)
app = FastAPI(debug=True,
)

# Load the middleware to handle CORS
app.add_middleware(
Expand All @@ -119,7 +120,7 @@ async def model_router(model_name: str):
# return ModelList(data=[model_card])


@app.post("v1/agent/completions", response_model=AgentOutput)
@app.post("/v1/agent/completions", response_model=AgentOutput)
async def agent_completions(agent_input: AgentInput):
try:
logger.info(f"Received request: {agent_input}")
Expand Down Expand Up @@ -185,6 +186,8 @@ async def agent_completions(agent_input: AgentInput):


if __name__ == "__main__":
import uvicorn


uvicorn.run(app, host="0.0.0.0", port=8080, use_colors=True, log_level="info")
uvicorn.run(app, host="0.0.0.0", port=8080, #use_colors=True,

log_level="debug")
2 changes: 2 additions & 0 deletions servers/agent/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
docker build . -t h4ckermike/swarms.world:first
docker push h4ckermike/swarms.world:first
9 changes: 9 additions & 0 deletions servers/agent/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# docker-compose.yaml
version: "3"

services:
api:
image: h4ckermike/swarms.world:first
build: .
ports:
- "8000:8000"
25 changes: 25 additions & 0 deletions servers/agent/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
curl -X 'POST' \
'http://a34f2f308013145858827f49a34f3bef-1801899861.us-east-1.elb.amazonaws.com/v1/agent/completions' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"agent_name": "Swarm Agent",
"system_prompt": "string",
"agent_description": "string",
"model_name": "OpenAIChat",
"max_loops": 1,
"autosave": false,
"dynamic_temperature_enabled": false,
"dashboard": false,
"verbose": false,
"streaming_on": true,
"saved_state_path": "string",
"sop": "string",
"sop_list": [
"string"
],
"user_name": "User",
"retry_attempts": 3,
"context_length": 8192,
"task": "string"
}'

0 comments on commit 742847f

Please sign in to comment.