Skip to content

πŸ™Œ OpenHands: AI-Driven Development

Fix/mypy routes (#6900)

Graham Neubig7a235ce6ff44
diff --git a/openhands/server/routes/feedback.py b/openhands/server/routes/feedback.py
index a181315815..4974ea992d 100644
--- a/openhands/server/routes/feedback.py
+++ b/openhands/server/routes/feedback.py
@@ -11,7 +11,7 @@ app = APIRouter(prefix='/api/conversations/{conversation_id}')
@app.post('/submit-feedback')
-async def submit_feedback(request: Request, conversation_id: str):
+async def submit_feedback(request: Request, conversation_id: str) -> JSONResponse:
"""Submit user feedback.
This function stores the provided feedback data.
diff --git a/openhands/server/routes/github.py b/openhands/server/routes/github.py
index 0255f6327b..71f10d3749 100644
--- a/openhands/server/routes/github.py
+++ b/openhands/server/routes/github.py
@@ -15,7 +15,7 @@ from openhands.server.auth import get_github_token, get_idp_token, get_user_id
app = APIRouter(prefix='/api/github')
[email protected]('/repositories')
[email protected]('/repositories', response_model=list[GitHubRepository])
async def get_github_repositories(
page: int = 1,
per_page: int = 10,
@@ -47,7 +47,7 @@ async def get_github_repositories(
)
[email protected]('/user', response_model=GitHubUser)
async def get_github_user(
github_user_id: str | None = Depends(get_user_id),
github_user_token: SecretStr | None = Depends(get_github_token),
@@ -73,7 +73,7 @@ async def get_github_user(
)
[email protected]('/installations')
[email protected]('/installations', response_model=list[int])
async def get_github_installation_ids(
github_user_id: str | None = Depends(get_user_id),
github_user_token: SecretStr | None = Depends(get_github_token),
@@ -99,7 +99,7 @@ async def get_github_installation_ids(
)
[email protected]('/search/repositories')
[email protected]('/search/repositories', response_model=list[GitHubRepository])
async def search_github_repositories(
query: str,
per_page: int = 5,
@@ -131,7 +131,7 @@ async def search_github_repositories(
)
[email protected]('/suggested-tasks')
[email protected]('/suggested-tasks', response_model=list[SuggestedTask])
async def get_suggested_tasks(
github_user_id: str | None = Depends(get_user_id),
github_user_token: SecretStr | None = Depends(get_github_token),
diff --git a/openhands/server/routes/public.py b/openhands/server/routes/public.py
index 59e5c4e4ef..a9dcd6d977 100644
--- a/openhands/server/routes/public.py
+++ b/openhands/server/routes/public.py
@@ -1,6 +1,8 @@
import warnings
+from typing import Any
import requests
+from fastapi import APIRouter
from openhands.security.options import SecurityAnalyzers
@@ -8,10 +10,6 @@ with warnings.catch_warnings():
warnings.simplefilter('ignore')
import litellm
-from fastapi import (
- APIRouter,
-)
-
from openhands.controller.agent import Agent
from openhands.core.config import LLMConfig
from openhands.core.logger import openhands_logger as logger
@@ -21,7 +19,7 @@ from openhands.server.shared import config, server_config
app = APIRouter(prefix='/api/options')
[email protected]('/models', response_model=list[str])
async def get_litellm_models() -> list[str]:
"""Get all models supported by LiteLLM.
@@ -34,7 +32,7 @@ async def get_litellm_models() -> list[str]:
```
Returns:
- list: A sorted list of unique model names.
+ list[str]: A sorted list of unique model names.
"""
litellm_model_list = litellm.model_list + list(litellm.model_cost.keys())
litellm_model_list_without_bedrock = bedrock.remove_error_modelId(
@@ -74,8 +72,8 @@ async def get_litellm_models() -> list[str]:
return list(sorted(set(model_list)))
-async def get_agents():
[email protected]('/agents', response_model=list[str])
+async def get_agents() -> list[str]:
"""Get all agents supported by LiteLLM.
To get the agents:
@@ -84,14 +82,13 @@ async def get_agents():
```
Returns:
- list: A sorted list of agent names.
+ list[str]: A sorted list of agent names.
"""
- agents = sorted(Agent.list_agents())
- return agents
+ return sorted(Agent.list_agents())
[email protected]('/security-analyzers')
-async def get_security_analyzers():
[email protected]('/security-analyzers', response_model=list[str])
+async def get_security_analyzers() -> list[str]:
"""Get all supported security analyzers.
To get the security analyzers:
@@ -100,15 +97,16 @@ async def get_security_analyzers():
```
Returns:
- list: A sorted list of security analyzer names.
+ list[str]: A sorted list of security analyzer names.
"""
return sorted(SecurityAnalyzers.keys())
-async def get_config():
- """
- Get current config
- """
[email protected]('/config', response_model=dict[str, Any])
+async def get_config() -> dict[str, Any]:
+ """Get current config.
+ Returns:
+ dict[str, Any]: The current server configuration.
+ """
return server_config.get_config()
diff --git a/openhands/server/routes/security.py b/openhands/server/routes/security.py
index 719cfa4728..e59f19631e 100644
--- a/openhands/server/routes/security.py
+++ b/openhands/server/routes/security.py
@@ -2,6 +2,7 @@ from fastapi import (
APIRouter,
HTTPException,
Request,
+ Response,
status,
)
@@ -9,7 +10,7 @@ app = APIRouter(prefix='/api/conversations/{conversation_id}')
@app.route('/security/{path:path}', methods=['GET', 'POST', 'PUT', 'DELETE'])
-async def security_api(request: Request):
+async def security_api(request: Request) -> Response:
"""Catch-all route for security analyzer API requests.
Each request is handled directly to the security analyzer.
@@ -18,7 +19,7 @@ async def security_api(request: Request):
request (Request): The incoming FastAPI request object.
Returns:
- Any: The response from the security analyzer.
+ Response: The response from the security analyzer.
Raises:
HTTPException: If the security analyzer is not initialized.
diff --git a/openhands/server/routes/settings.py b/openhands/server/routes/settings.py
index a63c84fa7f..410cd343c8 100644
--- a/openhands/server/routes/settings.py
+++ b/openhands/server/routes/settings.py
@@ -11,8 +11,8 @@ from openhands.server.shared import SettingsStoreImpl, config
app = APIRouter(prefix='/api')
[email protected]('/settings')
-async def load_settings(request: Request) -> GETSettingsModel | None:
[email protected]('/settings', response_model=GETSettingsModel)
+async def load_settings(request: Request) -> GETSettingsModel | JSONResponse:
try:
user_id = get_user_id(request)
settings_store = await SettingsStoreImpl.get_instance(config, user_id)
@@ -40,13 +40,12 @@ async def load_settings(request: Request) -> GETSettingsModel | None:
)
[email protected]('/settings')
[email protected]('/settings', response_model=dict[str, str])
async def store_settings(
request: Request,
settings: POSTSettingsModel,
) -> JSONResponse:
# Check if token is valid
-
if settings.github_token:
try:
# We check if the token is valid by getting the user
diff --git a/openhands/server/routes/trajectory.py b/openhands/server/routes/trajectory.py
index b9732ede0c..3fbea8eb73 100644
--- a/openhands/server/routes/trajectory.py
+++ b/openhands/server/routes/trajectory.py
@@ -9,7 +9,7 @@ app = APIRouter(prefix='/api/conversations/{conversation_id}')
@app.get('/trajectory')
-async def get_trajectory(request: Request):
+async def get_trajectory(request: Request) -> JSONResponse:
"""Get trajectory.
This function retrieves the current trajectory and returns it.