forked from All-Hands-AI/OpenHands
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# OpenDevin mock server | ||
This is a simple mock server to facilitate development in the frontend. | ||
|
||
## Start the Server | ||
``` | ||
python -m pip install -r requirements.txt | ||
python listen.py | ||
``` | ||
|
||
Then open the frontend to connect to the mock server. It will simply reply to every received message. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import uvicorn | ||
from fastapi import FastAPI, WebSocket | ||
|
||
app = FastAPI() | ||
@app.websocket("/ws") | ||
async def websocket_endpoint(websocket: WebSocket): | ||
await websocket.accept() | ||
# send message to mock connection | ||
await websocket.send_json({"action": "initialize", "message": "Control loop started."}) | ||
|
||
try: | ||
while True: | ||
# receive message | ||
data = await websocket.receive_json() | ||
print(f"Received message: {data}") | ||
|
||
# send mock response to client | ||
response = {"message": f"receive {data}"} | ||
await websocket.send_json(response) | ||
print(f"Sent message: {response}") | ||
except Exception as e: | ||
print(f"WebSocket Error: {e}") | ||
|
||
@app.get("/") | ||
def read_root(): | ||
return {"message": "This is a mock server"} | ||
|
||
if __name__ == "__main__": | ||
uvicorn.run(app, host="127.0.0.1", port=3000) |