Commit ·
5de7a1a
1
Parent(s): 8429bcb
refactor(api): simplify root endpoint and remove markdown rendering
Browse filesThe root endpoint has been simplified to serve as a basic API health check, removing the markdown rendering logic and associated dependencies. This change reduces complexity and improves performance by eliminating unnecessary file I/O and markdown processing. Additionally, the `template.html` file and `markdown` package have been removed from the project as they are no longer required.
ref #123: simplify root endpoint and clean up dependencies
- main.py +2 -30
- requirements.txt +1 -3
- template.html +0 -51
main.py
CHANGED
|
@@ -6,7 +6,6 @@ from concurrent.futures import ThreadPoolExecutor
|
|
| 6 |
from contextvars import ContextVar
|
| 7 |
from typing import Any, Dict, Generator, List
|
| 8 |
|
| 9 |
-
import markdown
|
| 10 |
from anthropic import Anthropic
|
| 11 |
from fastapi import FastAPI, HTTPException, Request, Response
|
| 12 |
from fastapi.responses import JSONResponse, StreamingResponse, HTMLResponse
|
|
@@ -121,35 +120,8 @@ def get_anthropic_client():
|
|
| 121 |
@app.get("/v1")
|
| 122 |
@app.get("/")
|
| 123 |
async def read_root():
|
| 124 |
-
"""Root endpoint
|
| 125 |
-
|
| 126 |
-
# Load HTML template
|
| 127 |
-
with open('template.html', 'r', encoding='utf-8') as f:
|
| 128 |
-
template = f.read()
|
| 129 |
-
|
| 130 |
-
# Load and convert README
|
| 131 |
-
with open('README.md', 'r', encoding='utf-8') as f:
|
| 132 |
-
content = f.read()
|
| 133 |
-
html_content = markdown.markdown(
|
| 134 |
-
content,
|
| 135 |
-
extensions=[
|
| 136 |
-
'fenced_code',
|
| 137 |
-
'tables',
|
| 138 |
-
'markdown.extensions.codehilite',
|
| 139 |
-
'markdown.extensions.toc'
|
| 140 |
-
]
|
| 141 |
-
)
|
| 142 |
-
|
| 143 |
-
# Return HTML response with the rendered template
|
| 144 |
-
return HTMLResponse(content=template.format(content=html_content))
|
| 145 |
-
except Exception as e:
|
| 146 |
-
logger.error(f"Error loading documentation: {str(e)}")
|
| 147 |
-
return HTMLResponse(
|
| 148 |
-
content="""
|
| 149 |
-
<h1>OpenWebUI Anthropic Integration</h1>
|
| 150 |
-
<p>Error loading documentation.</p>
|
| 151 |
-
"""
|
| 152 |
-
)
|
| 153 |
|
| 154 |
|
| 155 |
@app.get("/v1/models")
|
|
|
|
| 6 |
from contextvars import ContextVar
|
| 7 |
from typing import Any, Dict, Generator, List
|
| 8 |
|
|
|
|
| 9 |
from anthropic import Anthropic
|
| 10 |
from fastapi import FastAPI, HTTPException, Request, Response
|
| 11 |
from fastapi.responses import JSONResponse, StreamingResponse, HTMLResponse
|
|
|
|
| 120 |
@app.get("/v1")
|
| 121 |
@app.get("/")
|
| 122 |
async def read_root():
|
| 123 |
+
"""Root endpoint for API health check."""
|
| 124 |
+
return {"Hello": "World!"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 125 |
|
| 126 |
|
| 127 |
@app.get("/v1/models")
|
requirements.txt
CHANGED
|
@@ -1,6 +1,4 @@
|
|
| 1 |
fastapi
|
| 2 |
uvicorn
|
| 3 |
pydantic
|
| 4 |
-
anthropic
|
| 5 |
-
markdown
|
| 6 |
-
pygments
|
|
|
|
| 1 |
fastapi
|
| 2 |
uvicorn
|
| 3 |
pydantic
|
| 4 |
+
anthropic
|
|
|
|
|
|
template.html
DELETED
|
@@ -1,51 +0,0 @@
|
|
| 1 |
-
<!DOCTYPE html>
|
| 2 |
-
<html>
|
| 3 |
-
<head>
|
| 4 |
-
<title>OpenWebUI Anthropic Integration</title>
|
| 5 |
-
<meta charset="utf-8">
|
| 6 |
-
<meta name="viewport" content="width=device-width, initial-scale=1">
|
| 7 |
-
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
|
| 8 |
-
<style>
|
| 9 |
-
body {
|
| 10 |
-
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
|
| 11 |
-
line-height: 1.6;
|
| 12 |
-
padding: 20px;
|
| 13 |
-
max-width: 1000px;
|
| 14 |
-
margin: 0 auto;
|
| 15 |
-
background-color: #f8f9fa;
|
| 16 |
-
}
|
| 17 |
-
.container {
|
| 18 |
-
background-color: white;
|
| 19 |
-
padding: 30px;
|
| 20 |
-
border-radius: 8px;
|
| 21 |
-
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
| 22 |
-
margin-top: 20px;
|
| 23 |
-
}
|
| 24 |
-
h1, h2 {
|
| 25 |
-
color: #333;
|
| 26 |
-
margin-top: 1.5em;
|
| 27 |
-
}
|
| 28 |
-
code {
|
| 29 |
-
background-color: #f8f9fa;
|
| 30 |
-
padding: 2px 4px;
|
| 31 |
-
border-radius: 4px;
|
| 32 |
-
font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, Courier, monospace;
|
| 33 |
-
}
|
| 34 |
-
pre {
|
| 35 |
-
background-color: #f8f9fa;
|
| 36 |
-
padding: 15px;
|
| 37 |
-
border-radius: 4px;
|
| 38 |
-
overflow-x: auto;
|
| 39 |
-
}
|
| 40 |
-
.alert {
|
| 41 |
-
margin-top: 20px;
|
| 42 |
-
}
|
| 43 |
-
</style>
|
| 44 |
-
</head>
|
| 45 |
-
<body>
|
| 46 |
-
<div class="container">
|
| 47 |
-
{content}
|
| 48 |
-
</div>
|
| 49 |
-
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
|
| 50 |
-
</body>
|
| 51 |
-
</html>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|