Skip to content

Commit

Permalink
Don't start conversation runtime without valid API key (#6181)
Browse files Browse the repository at this point in the history
  • Loading branch information
raymyers authored Jan 13, 2025
1 parent 2755123 commit 6d015a5
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion openhands/server/routes/manage_conversations.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,26 @@ async def new_conversation(request: Request, data: InitSessionRequest):
session_init_args: dict = {}
if settings:
session_init_args = {**settings.__dict__, **session_init_args}

# We could use litellm.check_valid_key for a more accurate check,
# but that would run a tiny inference.
if not settings.llm_api_key or settings.llm_api_key.isspace():
logger.warn(f'Missing api key for model {settings.llm_model}')
return JSONResponse(
content={
'status': 'error',
'message': 'Error authenticating with the LLM provider. Please check your API key',
'msg_id': 'STATUS$ERROR_LLM_AUTHENTICATION',
}
)
else:
logger.warn('Settings not present, not starting conversation')
return JSONResponse(
content={
'status': 'error',
'message': 'Settings not found',
'msg_id': 'CONFIGURATION$SETTINGS_NOT_FOUND',
}
)
github_token = getattr(request.state, 'github_token', '')
session_init_args['github_token'] = github_token or data.github_token or ''
session_init_args['selected_repository'] = data.selected_repository
Expand Down

0 comments on commit 6d015a5

Please sign in to comment.