Spaces:
Configuration error
Configuration error
Download openhands/server/routes/conversation.py from flyingdarkdev/README: direct link, hf CLI and curl.
- Browser
- Download file 3.05 kB
-
https://huggingface.co/spaces/flyingdarkdev/README/resolve/main/openhands/server/routes/conversation.py
- Command line
-
hf download hf://spaces/flyingdarkdev/README/openhands/server/routes/conversation.py
-
curl -L -o conversation.py https://huggingface.co/spaces/flyingdarkdev/README/resolve/main/openhands/server/routes/conversation.py
3.05 kB
| from fastapi import APIRouter, Request, status | |
| from fastapi.responses import JSONResponse | |
| from openhands.core.logger import openhands_logger as logger | |
| from openhands.runtime.base import Runtime | |
| app = APIRouter(prefix='/api/conversations/{conversation_id}') | |
| async def get_remote_runtime_config(request: Request): | |
| """Retrieve the runtime configuration. | |
| Currently, this is the session ID and runtime ID (if available). | |
| """ | |
| runtime = request.state.conversation.runtime | |
| runtime_id = runtime.runtime_id if hasattr(runtime, 'runtime_id') else None | |
| session_id = runtime.sid if hasattr(runtime, 'sid') else None | |
| return JSONResponse( | |
| content={ | |
| 'runtime_id': runtime_id, | |
| 'session_id': session_id, | |
| } | |
| ) | |
| async def get_vscode_url(request: Request): | |
| """Get the VSCode URL. | |
| This endpoint allows getting the VSCode URL. | |
| Args: | |
| request (Request): The incoming FastAPI request object. | |
| Returns: | |
| JSONResponse: A JSON response indicating the success of the operation. | |
| """ | |
| try: | |
| runtime: Runtime = request.state.conversation.runtime | |
| logger.debug(f'Runtime type: {type(runtime)}') | |
| logger.debug(f'Runtime VSCode URL: {runtime.vscode_url}') | |
| return JSONResponse( | |
| status_code=status.HTTP_200_OK, content={'vscode_url': runtime.vscode_url} | |
| ) | |
| except Exception as e: | |
| logger.error(f'Error getting VSCode URL: {e}') | |
| return JSONResponse( | |
| status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, | |
| content={ | |
| 'vscode_url': None, | |
| 'error': f'Error getting VSCode URL: {e}', | |
| }, | |
| ) | |
| async def get_hosts(request: Request): | |
| """Get the hosts used by the runtime. | |
| This endpoint allows getting the hosts used by the runtime. | |
| Args: | |
| request (Request): The incoming FastAPI request object. | |
| Returns: | |
| JSONResponse: A JSON response indicating the success of the operation. | |
| """ | |
| try: | |
| if not hasattr(request.state, 'conversation'): | |
| return JSONResponse( | |
| status_code=500, | |
| content={'error': 'No conversation found in request state'}, | |
| ) | |
| if not hasattr(request.state.conversation, 'runtime'): | |
| return JSONResponse( | |
| status_code=500, content={'error': 'No runtime found in conversation'} | |
| ) | |
| runtime: Runtime = request.state.conversation.runtime | |
| logger.debug(f'Runtime type: {type(runtime)}') | |
| logger.debug(f'Runtime hosts: {runtime.web_hosts}') | |
| return JSONResponse(status_code=200, content={'hosts': runtime.web_hosts}) | |
| except Exception as e: | |
| logger.error(f'Error getting runtime hosts: {e}') | |
| return JSONResponse( | |
| status_code=500, | |
| content={ | |
| 'hosts': None, | |
| 'error': f'Error getting runtime hosts: {e}', | |
| }, | |
| ) | |