mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-07 21:29:13 +00:00
Move API endpoints under /configure/<type>/model to /api/model/<type>
Now the API to configure all the AI models is under /api/models. This provides better organization and API hierarchy. The /configure url segment was redundant. - Rename POST /api/phone to PATCH /api/phone - Rename GET /api/configure to GET /api/settings Refactor Flow 1. Move out POST /user/name to main api.py 2. Rename /api/configure/<type>/model -> /api/model/<type> 3. Rename @api_configure to @api_mode 4. Rename file api_config.py to api_model.py
This commit is contained in:
@@ -308,15 +308,15 @@ def configure_routes(app):
|
||||
from khoj.routers.api import api
|
||||
from khoj.routers.api_agents import api_agents
|
||||
from khoj.routers.api_chat import api_chat
|
||||
from khoj.routers.api_config import api_config
|
||||
from khoj.routers.api_content import api_content
|
||||
from khoj.routers.api_model import api_model
|
||||
from khoj.routers.notion import notion_router
|
||||
from khoj.routers.web_client import web_client
|
||||
|
||||
app.include_router(api, prefix="/api")
|
||||
app.include_router(api_chat, prefix="/api/chat")
|
||||
app.include_router(api_agents, prefix="/api/agents")
|
||||
app.include_router(api_config, prefix="/api/configure")
|
||||
app.include_router(api_model, prefix="/api/model")
|
||||
app.include_router(api_content, prefix="/api/content")
|
||||
app.include_router(notion_router, prefix="/api/notion")
|
||||
app.include_router(web_client)
|
||||
|
||||
@@ -394,8 +394,8 @@
|
||||
|
||||
function saveProfileGivenName() {
|
||||
const givenName = document.getElementById("profile_given_name").value;
|
||||
fetch('/api/configure/user/name?name=' + givenName, {
|
||||
method: 'POST',
|
||||
fetch('/api/user/name?name=' + givenName, {
|
||||
method: 'PATCH',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
}
|
||||
@@ -421,7 +421,7 @@
|
||||
saveVoiceModelButton.disabled = true;
|
||||
saveVoiceModelButton.textContent = "Saving...";
|
||||
|
||||
fetch('/api/configure/voice/model?id=' + voiceModel, {
|
||||
fetch('/api/model/voice?id=' + voiceModel, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
@@ -455,7 +455,7 @@
|
||||
saveModelButton.innerHTML = "";
|
||||
saveModelButton.textContent = "Saving...";
|
||||
|
||||
fetch('/api/configure/chat/model?id=' + chatModel, {
|
||||
fetch('/api/model/chat?id=' + chatModel, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
@@ -494,7 +494,7 @@
|
||||
saveSearchModelButton.disabled = true;
|
||||
saveSearchModelButton.textContent = "Saving...";
|
||||
|
||||
fetch('/api/configure/search/model?id=' + searchModel, {
|
||||
fetch('/api/model/search?id=' + searchModel, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
@@ -526,7 +526,7 @@
|
||||
saveModelButton.disabled = true;
|
||||
saveModelButton.innerHTML = "Saving...";
|
||||
|
||||
fetch('/api/configure/paint/model?id=' + paintModel, {
|
||||
fetch('/api/model/paint?id=' + paintModel, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
|
||||
@@ -19,6 +19,7 @@ from fastapi.responses import Response
|
||||
from starlette.authentication import has_required_scope, requires
|
||||
|
||||
from khoj.configure import initialize_content
|
||||
from khoj.database import adapters
|
||||
from khoj.database.adapters import (
|
||||
AutomationAdapters,
|
||||
ConversationAdapters,
|
||||
@@ -276,6 +277,38 @@ async def transcribe(
|
||||
return Response(content=content, media_type="application/json", status_code=200)
|
||||
|
||||
|
||||
@api.patch("/user/name", status_code=200)
|
||||
@requires(["authenticated"])
|
||||
def set_user_name(
|
||||
request: Request,
|
||||
name: str,
|
||||
client: Optional[str] = None,
|
||||
):
|
||||
user = request.user.object
|
||||
|
||||
split_name = name.split(" ")
|
||||
|
||||
if len(split_name) > 2:
|
||||
raise HTTPException(status_code=400, detail="Name must be in the format: Firstname Lastname")
|
||||
|
||||
if len(split_name) == 1:
|
||||
first_name = split_name[0]
|
||||
last_name = ""
|
||||
else:
|
||||
first_name, last_name = split_name[0], split_name[-1]
|
||||
|
||||
adapters.set_user_name(user, first_name, last_name)
|
||||
|
||||
update_telemetry_state(
|
||||
request=request,
|
||||
telemetry_type="api",
|
||||
api="set_user_name",
|
||||
client=client,
|
||||
)
|
||||
|
||||
return {"status": "ok"}
|
||||
|
||||
|
||||
async def extract_references_and_questions(
|
||||
request: Request,
|
||||
meta_log: dict,
|
||||
|
||||
@@ -11,11 +11,11 @@ from khoj.database import adapters
|
||||
from khoj.database.adapters import ConversationAdapters, EntryAdapters
|
||||
from khoj.routers.helpers import update_telemetry_state
|
||||
|
||||
api_config = APIRouter()
|
||||
api_model = APIRouter()
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@api_config.get("/chat/model/options", response_model=Dict[str, Union[str, int]])
|
||||
@api_model.get("/chat/options", response_model=Dict[str, Union[str, int]])
|
||||
def get_chat_model_options(
|
||||
request: Request,
|
||||
client: Optional[str] = None,
|
||||
@@ -29,7 +29,7 @@ def get_chat_model_options(
|
||||
return Response(content=json.dumps(all_conversation_options), media_type="application/json", status_code=200)
|
||||
|
||||
|
||||
@api_config.get("/chat/model")
|
||||
@api_model.get("/chat")
|
||||
@requires(["authenticated"])
|
||||
def get_user_chat_model(
|
||||
request: Request,
|
||||
@@ -45,7 +45,7 @@ def get_user_chat_model(
|
||||
return Response(status_code=200, content=json.dumps({"id": chat_model.id, "chat_model": chat_model.chat_model}))
|
||||
|
||||
|
||||
@api_config.post("/chat/model", status_code=200)
|
||||
@api_model.post("/chat", status_code=200)
|
||||
@requires(["authenticated", "premium"])
|
||||
async def update_chat_model(
|
||||
request: Request,
|
||||
@@ -70,7 +70,7 @@ async def update_chat_model(
|
||||
return {"status": "ok"}
|
||||
|
||||
|
||||
@api_config.post("/voice/model", status_code=200)
|
||||
@api_model.post("/voice", status_code=200)
|
||||
@requires(["authenticated", "premium"])
|
||||
async def update_voice_model(
|
||||
request: Request,
|
||||
@@ -94,7 +94,7 @@ async def update_voice_model(
|
||||
return Response(status_code=202, content=json.dumps({"status": "ok"}))
|
||||
|
||||
|
||||
@api_config.post("/search/model", status_code=200)
|
||||
@api_model.post("/search", status_code=200)
|
||||
@requires(["authenticated"])
|
||||
async def update_search_model(
|
||||
request: Request,
|
||||
@@ -127,7 +127,7 @@ async def update_search_model(
|
||||
return {"status": "ok"}
|
||||
|
||||
|
||||
@api_config.post("/paint/model", status_code=200)
|
||||
@api_model.post("/paint", status_code=200)
|
||||
@requires(["authenticated"])
|
||||
async def update_paint_model(
|
||||
request: Request,
|
||||
@@ -154,35 +154,3 @@ async def update_paint_model(
|
||||
return {"status": "error", "message": "Model not found"}
|
||||
|
||||
return {"status": "ok"}
|
||||
|
||||
|
||||
@api_config.post("/user/name", status_code=200)
|
||||
@requires(["authenticated"])
|
||||
def set_user_name(
|
||||
request: Request,
|
||||
name: str,
|
||||
client: Optional[str] = None,
|
||||
):
|
||||
user = request.user.object
|
||||
|
||||
split_name = name.split(" ")
|
||||
|
||||
if len(split_name) > 2:
|
||||
raise HTTPException(status_code=400, detail="Name must be in the format: Firstname Lastname")
|
||||
|
||||
if len(split_name) == 1:
|
||||
first_name = split_name[0]
|
||||
last_name = ""
|
||||
else:
|
||||
first_name, last_name = split_name[0], split_name[-1]
|
||||
|
||||
adapters.set_user_name(user, first_name, last_name)
|
||||
|
||||
update_telemetry_state(
|
||||
request=request,
|
||||
telemetry_type="api",
|
||||
api="set_user_name",
|
||||
client=client,
|
||||
)
|
||||
|
||||
return {"status": "ok"}
|
||||
Reference in New Issue
Block a user