mirror of
https://github.com/OpenHands/OpenHands.git
synced 2025-12-26 05:48:36 +08:00
Fix/mypy routes (#6900)
Co-authored-by: openhands <openhands@all-hands.dev>
This commit is contained in:
parent
5ffb1ef704
commit
7a235ce6ff
@ -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.
|
||||
|
||||
@ -15,7 +15,7 @@ from openhands.server.auth import get_github_token, get_idp_token, get_user_id
|
||||
app = APIRouter(prefix='/api/github')
|
||||
|
||||
|
||||
@app.get('/repositories')
|
||||
@app.get('/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(
|
||||
)
|
||||
|
||||
|
||||
@app.get('/user')
|
||||
@app.get('/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(
|
||||
)
|
||||
|
||||
|
||||
@app.get('/installations')
|
||||
@app.get('/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(
|
||||
)
|
||||
|
||||
|
||||
@app.get('/search/repositories')
|
||||
@app.get('/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(
|
||||
)
|
||||
|
||||
|
||||
@app.get('/suggested-tasks')
|
||||
@app.get('/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),
|
||||
|
||||
@ -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')
|
||||
|
||||
|
||||
@app.get('/models')
|
||||
@app.get('/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)))
|
||||
|
||||
|
||||
@app.get('/agents')
|
||||
async def get_agents():
|
||||
@app.get('/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())
|
||||
|
||||
|
||||
@app.get('/security-analyzers')
|
||||
async def get_security_analyzers():
|
||||
@app.get('/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())
|
||||
|
||||
|
||||
@app.get('/config')
|
||||
async def get_config():
|
||||
"""
|
||||
Get current config
|
||||
"""
|
||||
@app.get('/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()
|
||||
|
||||
@ -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.
|
||||
|
||||
@ -11,8 +11,8 @@ from openhands.server.shared import SettingsStoreImpl, config
|
||||
app = APIRouter(prefix='/api')
|
||||
|
||||
|
||||
@app.get('/settings')
|
||||
async def load_settings(request: Request) -> GETSettingsModel | None:
|
||||
@app.get('/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:
|
||||
)
|
||||
|
||||
|
||||
@app.post('/settings')
|
||||
@app.post('/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
|
||||
|
||||
@ -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.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user