add api cards
Release / release (push) Canceled after 0s
Create and publish Docker images with specific build args / build-main-image (linux/amd64, ubuntu-latest) (push) Canceled after 0s
Create and publish Docker images with specific build args / build-main-image (linux/arm64, ubuntu-24.04-arm) (push) Canceled after 0s
Create and publish Docker images with specific build args / build-cuda-image (linux/amd64, ubuntu-latest) (push) Canceled after 0s
Create and publish Docker images with specific build args / build-cuda-image (linux/arm64, ubuntu-24.04-arm) (push) Canceled after 0s
Create and publish Docker images with specific build args / build-cuda126-image (linux/amd64, ubuntu-latest) (push) Canceled after 0s
Create and publish Docker images with specific build args / build-cuda126-image (linux/arm64, ubuntu-24.04-arm) (push) Canceled after 0s
Create and publish Docker images with specific build args / build-ollama-image (linux/amd64, ubuntu-latest) (push) Canceled after 0s
Create and publish Docker images with specific build args / build-ollama-image (linux/arm64, ubuntu-24.04-arm) (push) Canceled after 0s
Create and publish Docker images with specific build args / build-slim-image (linux/amd64, ubuntu-latest) (push) Canceled after 0s
Create and publish Docker images with specific build args / build-slim-image (linux/arm64, ubuntu-24.04-arm) (push) Canceled after 0s
Python CI / Format Backend (3.11.x) (push) Canceled after 0s
Python CI / Format Backend (3.12.x) (push) Canceled after 0s
Frontend Build / Format & Build Frontend (push) Canceled after 0s
Frontend Build / Frontend Unit Tests (push) Canceled after 0s
Release to PyPI / release (push) Canceled after 0s
Create and publish Docker images with specific build args / merge-main-images (push) Canceled after 0s
Create and publish Docker images with specific build args / merge-cuda-images (push) Canceled after 0s
Create and publish Docker images with specific build args / merge-cuda126-images (push) Canceled after 0s
Create and publish Docker images with specific build args / merge-ollama-images (push) Canceled after 0s
Create and publish Docker images with specific build args / merge-slim-images (push) Canceled after 0s
Create and publish Docker images with specific build args / copy-to-dockerhub (, main) (push) Canceled after 0s
Create and publish Docker images with specific build args / copy-to-dockerhub (-cuda, cuda) (push) Canceled after 0s
Create and publish Docker images with specific build args / copy-to-dockerhub (-cuda126, cuda126) (push) Canceled after 0s
Create and publish Docker images with specific build args / copy-to-dockerhub (-ollama, ollama) (push) Canceled after 0s
Create and publish Docker images with specific build args / copy-to-dockerhub (-slim, slim) (push) Canceled after 0s
Release / release (push) Canceled after 0s
Create and publish Docker images with specific build args / build-main-image (linux/amd64, ubuntu-latest) (push) Canceled after 0s
Create and publish Docker images with specific build args / build-main-image (linux/arm64, ubuntu-24.04-arm) (push) Canceled after 0s
Create and publish Docker images with specific build args / build-cuda-image (linux/amd64, ubuntu-latest) (push) Canceled after 0s
Create and publish Docker images with specific build args / build-cuda-image (linux/arm64, ubuntu-24.04-arm) (push) Canceled after 0s
Create and publish Docker images with specific build args / build-cuda126-image (linux/amd64, ubuntu-latest) (push) Canceled after 0s
Create and publish Docker images with specific build args / build-cuda126-image (linux/arm64, ubuntu-24.04-arm) (push) Canceled after 0s
Create and publish Docker images with specific build args / build-ollama-image (linux/amd64, ubuntu-latest) (push) Canceled after 0s
Create and publish Docker images with specific build args / build-ollama-image (linux/arm64, ubuntu-24.04-arm) (push) Canceled after 0s
Create and publish Docker images with specific build args / build-slim-image (linux/amd64, ubuntu-latest) (push) Canceled after 0s
Create and publish Docker images with specific build args / build-slim-image (linux/arm64, ubuntu-24.04-arm) (push) Canceled after 0s
Python CI / Format Backend (3.11.x) (push) Canceled after 0s
Python CI / Format Backend (3.12.x) (push) Canceled after 0s
Frontend Build / Format & Build Frontend (push) Canceled after 0s
Frontend Build / Frontend Unit Tests (push) Canceled after 0s
Release to PyPI / release (push) Canceled after 0s
Create and publish Docker images with specific build args / merge-main-images (push) Canceled after 0s
Create and publish Docker images with specific build args / merge-cuda-images (push) Canceled after 0s
Create and publish Docker images with specific build args / merge-cuda126-images (push) Canceled after 0s
Create and publish Docker images with specific build args / merge-ollama-images (push) Canceled after 0s
Create and publish Docker images with specific build args / merge-slim-images (push) Canceled after 0s
Create and publish Docker images with specific build args / copy-to-dockerhub (, main) (push) Canceled after 0s
Create and publish Docker images with specific build args / copy-to-dockerhub (-cuda, cuda) (push) Canceled after 0s
Create and publish Docker images with specific build args / copy-to-dockerhub (-cuda126, cuda126) (push) Canceled after 0s
Create and publish Docker images with specific build args / copy-to-dockerhub (-ollama, ollama) (push) Canceled after 0s
Create and publish Docker images with specific build args / copy-to-dockerhub (-slim, slim) (push) Canceled after 0s
This commit is contained in:
@@ -1209,6 +1209,16 @@ TERMINAL_SERVER_CONNECTIONS = PersistentConfig(
|
||||
terminal_server_connections,
|
||||
)
|
||||
|
||||
####################################
|
||||
# CUSTOM API ENDPOINTS
|
||||
####################################
|
||||
|
||||
CUSTOM_API_ENDPOINTS = PersistentConfig(
|
||||
'CUSTOM_API_ENDPOINTS',
|
||||
'custom_api.endpoints',
|
||||
[],
|
||||
)
|
||||
|
||||
####################################
|
||||
# WEBUI
|
||||
####################################
|
||||
|
||||
@@ -662,3 +662,102 @@ async def get_banners(
|
||||
user=Depends(get_verified_user),
|
||||
):
|
||||
return request.app.state.config.BANNERS
|
||||
|
||||
|
||||
############################
|
||||
# Custom API Endpoints Config
|
||||
############################
|
||||
|
||||
|
||||
class CustomApiEndpoint(BaseModel):
|
||||
id: str
|
||||
name: str
|
||||
connection_idx: int
|
||||
path: str
|
||||
method: Optional[str] = 'GET'
|
||||
refresh_interval: Optional[int] = 60
|
||||
enabled: Optional[bool] = True
|
||||
|
||||
model_config = ConfigDict(extra='allow')
|
||||
|
||||
|
||||
class CustomApiEndpointsConfigForm(BaseModel):
|
||||
CUSTOM_API_ENDPOINTS: list[CustomApiEndpoint]
|
||||
|
||||
|
||||
@router.get('/custom_api_endpoints', response_model=CustomApiEndpointsConfigForm)
|
||||
async def get_custom_api_endpoints_config(request: Request, user=Depends(get_verified_user)):
|
||||
return {
|
||||
'CUSTOM_API_ENDPOINTS': request.app.state.config.CUSTOM_API_ENDPOINTS,
|
||||
}
|
||||
|
||||
|
||||
@router.post('/custom_api_endpoints', response_model=CustomApiEndpointsConfigForm)
|
||||
async def set_custom_api_endpoints_config(
|
||||
request: Request,
|
||||
form_data: CustomApiEndpointsConfigForm,
|
||||
user=Depends(get_admin_user),
|
||||
):
|
||||
request.app.state.config.CUSTOM_API_ENDPOINTS = [
|
||||
endpoint.model_dump() for endpoint in form_data.CUSTOM_API_ENDPOINTS
|
||||
]
|
||||
return {
|
||||
'CUSTOM_API_ENDPOINTS': request.app.state.config.CUSTOM_API_ENDPOINTS,
|
||||
}
|
||||
|
||||
|
||||
@router.post('/custom_api_endpoints/execute')
|
||||
async def execute_custom_api_endpoint(
|
||||
request: Request,
|
||||
endpoint_id: str,
|
||||
user=Depends(get_verified_user),
|
||||
):
|
||||
endpoints = request.app.state.config.CUSTOM_API_ENDPOINTS
|
||||
endpoint = next((e for e in endpoints if e.get('id') == endpoint_id), None)
|
||||
if not endpoint:
|
||||
raise HTTPException(status_code=404, detail='Custom API endpoint not found')
|
||||
|
||||
if not endpoint.get('enabled', True):
|
||||
raise HTTPException(status_code=403, detail='Custom API endpoint is disabled')
|
||||
|
||||
connection_idx = endpoint.get('connection_idx', 0)
|
||||
openai_base_urls = request.app.state.config.OPENAI_API_BASE_URLS
|
||||
openai_keys = request.app.state.config.OPENAI_API_KEYS
|
||||
openai_configs = request.app.state.config.OPENAI_API_CONFIGS
|
||||
|
||||
if connection_idx >= len(openai_base_urls):
|
||||
raise HTTPException(status_code=400, detail='Connection index out of range')
|
||||
|
||||
base_url = openai_base_urls[connection_idx].rstrip('/')
|
||||
key = openai_keys[connection_idx] if connection_idx < len(openai_keys) else ''
|
||||
config = openai_configs.get(str(connection_idx), {})
|
||||
|
||||
url = f"{base_url}{endpoint['path']}"
|
||||
method = endpoint.get('method', 'GET').upper()
|
||||
|
||||
headers = {
|
||||
'Content-Type': 'application/json',
|
||||
**({'Authorization': f'Bearer {key}'} if key else {}),
|
||||
}
|
||||
if config.get('headers') and isinstance(config.get('headers'), dict):
|
||||
headers = {**headers, **config.get('headers')}
|
||||
|
||||
try:
|
||||
async with aiohttp.ClientSession(
|
||||
trust_env=True,
|
||||
timeout=aiohttp.ClientTimeout(total=AIOHTTP_CLIENT_TIMEOUT),
|
||||
) as session:
|
||||
async with session.request(
|
||||
method, url, headers=headers, ssl=AIOHTTP_CLIENT_SESSION_SSL
|
||||
) as resp:
|
||||
try:
|
||||
data = await resp.json()
|
||||
except Exception:
|
||||
data = {'text': await resp.text()}
|
||||
return {
|
||||
'status': resp.status,
|
||||
'data': data,
|
||||
}
|
||||
except Exception as e:
|
||||
log.debug(f'Failed to execute custom API endpoint: {e}')
|
||||
raise HTTPException(status_code=400, detail='Failed to execute custom API endpoint')
|
||||
|
||||
Reference in New Issue
Block a user