mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-02 21:19:12 +00:00
Make config api endpoint urls consistent
- Consistently use /content/ for data. Remove content-source from path - Remove unnecessary /data/ prefix for API endpoints under /config
This commit is contained in:
@@ -68,8 +68,8 @@ interface ModelPickerProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const ModelPicker: React.FC<any> = (props: ModelPickerProps) => {
|
export const ModelPicker: React.FC<any> = (props: ModelPickerProps) => {
|
||||||
const { data: models } = useOptionsRequest('/api/config/data/conversation/model/options');
|
const { data: models } = useOptionsRequest('/api/config/chat/model/options');
|
||||||
const { data: selectedModel } = useSelectedModel('/api/config/data/conversation/model');
|
const { data: selectedModel } = useSelectedModel('/api/config/chat/model');
|
||||||
const [openLoginDialog, setOpenLoginDialog] = React.useState(false);
|
const [openLoginDialog, setOpenLoginDialog] = React.useState(false);
|
||||||
|
|
||||||
let userData = useAuthenticatedData();
|
let userData = useAuthenticatedData();
|
||||||
@@ -94,7 +94,7 @@ export const ModelPicker: React.FC<any> = (props: ModelPickerProps) => {
|
|||||||
props.setModelUsed(model);
|
props.setModelUsed(model);
|
||||||
}
|
}
|
||||||
|
|
||||||
fetch('/api/config/data/conversation/model' + '?id=' + String(model.id), { method: 'POST', body: JSON.stringify(model) })
|
fetch('/api/config/chat/model' + '?id=' + String(model.id), { method: 'POST', body: JSON.stringify(model) })
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error('Failed to select model');
|
throw new Error('Failed to select model');
|
||||||
|
|||||||
@@ -148,7 +148,7 @@ interface FilesMenuProps {
|
|||||||
|
|
||||||
function FilesMenu(props: FilesMenuProps) {
|
function FilesMenu(props: FilesMenuProps) {
|
||||||
// Use SWR to fetch files
|
// Use SWR to fetch files
|
||||||
const { data: files, error } = useSWR<string[]>(props.conversationId ? '/api/config/data/computer' : null, fetcher);
|
const { data: files, error } = useSWR<string[]>(props.conversationId ? '/api/config/content/computer' : null, fetcher);
|
||||||
const { data: selectedFiles, error: selectedFilesError } = useSWR(props.conversationId ? `/api/chat/conversation/file-filters/${props.conversationId}` : null, fetcher);
|
const { data: selectedFiles, error: selectedFilesError } = useSWR(props.conversationId ? `/api/chat/conversation/file-filters/${props.conversationId}` : null, fetcher);
|
||||||
const [isOpen, setIsOpen] = useState(false);
|
const [isOpen, setIsOpen] = useState(false);
|
||||||
const [unfilteredFiles, setUnfilteredFiles] = useState<string[]>([]);
|
const [unfilteredFiles, setUnfilteredFiles] = useState<string[]>([]);
|
||||||
|
|||||||
@@ -1954,7 +1954,7 @@ To get started, just start typing below. You can also type / to see a list of co
|
|||||||
}
|
}
|
||||||
var allFiles;
|
var allFiles;
|
||||||
function renderAllFiles() {
|
function renderAllFiles() {
|
||||||
fetch('/api/config/data/computer')
|
fetch('/api/config/content/computer')
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(data => {
|
.then(data => {
|
||||||
var indexedFiles = document.getElementsByClassName("indexed-files")[0];
|
var indexedFiles = document.getElementsByClassName("indexed-files")[0];
|
||||||
|
|||||||
@@ -421,7 +421,7 @@
|
|||||||
saveVoiceModelButton.disabled = true;
|
saveVoiceModelButton.disabled = true;
|
||||||
saveVoiceModelButton.textContent = "Saving...";
|
saveVoiceModelButton.textContent = "Saving...";
|
||||||
|
|
||||||
fetch('/api/config/data/voice/model?id=' + voiceModel, {
|
fetch('/api/config/voice/model?id=' + voiceModel, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
@@ -455,7 +455,7 @@
|
|||||||
saveModelButton.innerHTML = "";
|
saveModelButton.innerHTML = "";
|
||||||
saveModelButton.textContent = "Saving...";
|
saveModelButton.textContent = "Saving...";
|
||||||
|
|
||||||
fetch('/api/config/data/conversation/model?id=' + chatModel, {
|
fetch('/api/config/chat/model?id=' + chatModel, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
@@ -494,7 +494,7 @@
|
|||||||
saveSearchModelButton.disabled = true;
|
saveSearchModelButton.disabled = true;
|
||||||
saveSearchModelButton.textContent = "Saving...";
|
saveSearchModelButton.textContent = "Saving...";
|
||||||
|
|
||||||
fetch('/api/config/data/search/model?id=' + searchModel, {
|
fetch('/api/config/search/model?id=' + searchModel, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
@@ -526,7 +526,7 @@
|
|||||||
saveModelButton.disabled = true;
|
saveModelButton.disabled = true;
|
||||||
saveModelButton.innerHTML = "Saving...";
|
saveModelButton.innerHTML = "Saving...";
|
||||||
|
|
||||||
fetch('/api/config/data/paint/model?id=' + paintModel, {
|
fetch('/api/config/paint/model?id=' + paintModel, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
@@ -553,7 +553,7 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
function clearContentType(content_source) {
|
function clearContentType(content_source) {
|
||||||
fetch('/api/config/data/content-source/' + content_source, {
|
fetch('/api/config/content/' + content_source, {
|
||||||
method: 'DELETE',
|
method: 'DELETE',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
@@ -676,7 +676,7 @@
|
|||||||
|
|
||||||
content_sources = ["computer", "github", "notion"];
|
content_sources = ["computer", "github", "notion"];
|
||||||
content_sources.forEach(content_source => {
|
content_sources.forEach(content_source => {
|
||||||
fetch(`/api/config/data/${content_source}`, {
|
fetch(`/api/config/content/${content_source}`, {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
@@ -807,7 +807,7 @@
|
|||||||
|
|
||||||
function getIndexedDataSize() {
|
function getIndexedDataSize() {
|
||||||
document.getElementById("indexed-data-size").textContent = "Calculating...";
|
document.getElementById("indexed-data-size").textContent = "Calculating...";
|
||||||
fetch('/api/config/index/size')
|
fetch('/api/config/content/size')
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(data => {
|
.then(data => {
|
||||||
document.getElementById("indexed-data-size").textContent = data.indexed_data_size_in_mb + " MB used";
|
document.getElementById("indexed-data-size").textContent = data.indexed_data_size_in_mb + " MB used";
|
||||||
@@ -815,7 +815,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function removeFile(path) {
|
function removeFile(path) {
|
||||||
fetch('/api/config/data/file?filename=' + path, {
|
fetch('/api/config/content/file?filename=' + path, {
|
||||||
method: 'DELETE',
|
method: 'DELETE',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
|
|||||||
@@ -32,7 +32,7 @@
|
|||||||
</style>
|
</style>
|
||||||
<script>
|
<script>
|
||||||
function removeFile(path) {
|
function removeFile(path) {
|
||||||
fetch('/api/config/data/file?filename=' + path, {
|
fetch('/api/config/content/file?filename=' + path, {
|
||||||
method: 'DELETE',
|
method: 'DELETE',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
@@ -48,7 +48,7 @@
|
|||||||
|
|
||||||
// Get all currently indexed files
|
// Get all currently indexed files
|
||||||
function getAllComputerFilenames() {
|
function getAllComputerFilenames() {
|
||||||
fetch('/api/config/data/computer')
|
fetch('/api/config/content/computer')
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(data => {
|
.then(data => {
|
||||||
var indexedFiles = document.getElementsByClassName("indexed-files")[0];
|
var indexedFiles = document.getElementsByClassName("indexed-files")[0];
|
||||||
@@ -122,7 +122,7 @@
|
|||||||
deleteAllComputerFilesButton.textContent = "🗑️ Deleting...";
|
deleteAllComputerFilesButton.textContent = "🗑️ Deleting...";
|
||||||
deleteAllComputerFilesButton.disabled = true;
|
deleteAllComputerFilesButton.disabled = true;
|
||||||
|
|
||||||
fetch('/api/config/data/content-source/computer', {
|
fetch('/api/config/content/computer', {
|
||||||
method: 'DELETE',
|
method: 'DELETE',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
|
|||||||
@@ -165,7 +165,7 @@
|
|||||||
|
|
||||||
// Save Github config on server
|
// Save Github config on server
|
||||||
const csrfToken = document.cookie.split('; ').find(row => row.startsWith('csrftoken'))?.split('=')[1];
|
const csrfToken = document.cookie.split('; ').find(row => row.startsWith('csrftoken'))?.split('=')[1];
|
||||||
fetch('/api/config/data/content-source/github', {
|
fetch('/api/config/content/github', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
|
|||||||
@@ -45,7 +45,7 @@
|
|||||||
|
|
||||||
// Save Notion config on server
|
// Save Notion config on server
|
||||||
const csrfToken = document.cookie.split('; ').find(row => row.startsWith('csrftoken'))?.split('=')[1];
|
const csrfToken = document.cookie.split('; ').find(row => row.startsWith('csrftoken'))?.split('=')[1];
|
||||||
fetch('/api/config/data/content-source/notion', {
|
fetch('/api/config/content/notion', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
|
|||||||
@@ -98,9 +98,9 @@ def _initialize_config():
|
|||||||
state.config.search_type = SearchConfig.model_validate(constants.default_config["search-type"])
|
state.config.search_type = SearchConfig.model_validate(constants.default_config["search-type"])
|
||||||
|
|
||||||
|
|
||||||
@api_config.post("/data/content-source/github", status_code=200)
|
@api_config.post("/content/github", status_code=200)
|
||||||
@requires(["authenticated"])
|
@requires(["authenticated"])
|
||||||
async def set_content_config_github_data(
|
async def set_content_github(
|
||||||
request: Request,
|
request: Request,
|
||||||
updated_config: Union[GithubContentConfig, None],
|
updated_config: Union[GithubContentConfig, None],
|
||||||
client: Optional[str] = None,
|
client: Optional[str] = None,
|
||||||
@@ -130,9 +130,9 @@ async def set_content_config_github_data(
|
|||||||
return {"status": "ok"}
|
return {"status": "ok"}
|
||||||
|
|
||||||
|
|
||||||
@api_config.post("/data/content-source/notion", status_code=200)
|
@api_config.post("/content/notion", status_code=200)
|
||||||
@requires(["authenticated"])
|
@requires(["authenticated"])
|
||||||
async def set_content_config_notion_data(
|
async def set_content_notion(
|
||||||
request: Request,
|
request: Request,
|
||||||
updated_config: Union[NotionContentConfig, None],
|
updated_config: Union[NotionContentConfig, None],
|
||||||
client: Optional[str] = None,
|
client: Optional[str] = None,
|
||||||
@@ -161,9 +161,9 @@ async def set_content_config_notion_data(
|
|||||||
return {"status": "ok"}
|
return {"status": "ok"}
|
||||||
|
|
||||||
|
|
||||||
@api_config.delete("/data/content-source/{content_source}", status_code=200)
|
@api_config.delete("/content/{content_source}", status_code=200)
|
||||||
@requires(["authenticated"])
|
@requires(["authenticated"])
|
||||||
async def remove_content_source_data(
|
async def delete_content_source(
|
||||||
request: Request,
|
request: Request,
|
||||||
content_source: str,
|
content_source: str,
|
||||||
client: Optional[str] = None,
|
client: Optional[str] = None,
|
||||||
@@ -189,9 +189,9 @@ async def remove_content_source_data(
|
|||||||
return {"status": "ok"}
|
return {"status": "ok"}
|
||||||
|
|
||||||
|
|
||||||
@api_config.delete("/data/file", status_code=200)
|
@api_config.delete("/content/file", status_code=201)
|
||||||
@requires(["authenticated"])
|
@requires(["authenticated"])
|
||||||
async def remove_file_data(
|
async def delete_content_file(
|
||||||
request: Request,
|
request: Request,
|
||||||
filename: str,
|
filename: str,
|
||||||
client: Optional[str] = None,
|
client: Optional[str] = None,
|
||||||
@@ -210,9 +210,9 @@ async def remove_file_data(
|
|||||||
return {"status": "ok"}
|
return {"status": "ok"}
|
||||||
|
|
||||||
|
|
||||||
@api_config.get("/data/{content_source}", response_model=List[str])
|
@api_config.get("/content/{content_source}", response_model=List[str])
|
||||||
@requires(["authenticated"])
|
@requires(["authenticated"])
|
||||||
async def get_all_filenames(
|
async def get_content_source(
|
||||||
request: Request,
|
request: Request,
|
||||||
content_source: str,
|
content_source: str,
|
||||||
client: Optional[str] = None,
|
client: Optional[str] = None,
|
||||||
@@ -229,7 +229,7 @@ async def get_all_filenames(
|
|||||||
return await sync_to_async(list)(EntryAdapters.get_all_filenames_by_source(user, content_source)) # type: ignore[call-arg]
|
return await sync_to_async(list)(EntryAdapters.get_all_filenames_by_source(user, content_source)) # type: ignore[call-arg]
|
||||||
|
|
||||||
|
|
||||||
@api_config.get("/data/conversation/model/options", response_model=Dict[str, Union[str, int]])
|
@api_config.get("/chat/model/options", response_model=Dict[str, Union[str, int]])
|
||||||
def get_chat_model_options(
|
def get_chat_model_options(
|
||||||
request: Request,
|
request: Request,
|
||||||
client: Optional[str] = None,
|
client: Optional[str] = None,
|
||||||
@@ -243,7 +243,7 @@ def get_chat_model_options(
|
|||||||
return Response(content=json.dumps(all_conversation_options), media_type="application/json", status_code=200)
|
return Response(content=json.dumps(all_conversation_options), media_type="application/json", status_code=200)
|
||||||
|
|
||||||
|
|
||||||
@api_config.get("/data/conversation/model")
|
@api_config.get("/chat/model")
|
||||||
@requires(["authenticated"])
|
@requires(["authenticated"])
|
||||||
def get_user_chat_model(
|
def get_user_chat_model(
|
||||||
request: Request,
|
request: Request,
|
||||||
@@ -259,7 +259,7 @@ def get_user_chat_model(
|
|||||||
return Response(status_code=200, content=json.dumps({"id": chat_model.id, "chat_model": chat_model.chat_model}))
|
return Response(status_code=200, content=json.dumps({"id": chat_model.id, "chat_model": chat_model.chat_model}))
|
||||||
|
|
||||||
|
|
||||||
@api_config.post("/data/conversation/model", status_code=200)
|
@api_config.post("/chat/model", status_code=200)
|
||||||
@requires(["authenticated", "premium"])
|
@requires(["authenticated", "premium"])
|
||||||
async def update_chat_model(
|
async def update_chat_model(
|
||||||
request: Request,
|
request: Request,
|
||||||
@@ -284,7 +284,7 @@ async def update_chat_model(
|
|||||||
return {"status": "ok"}
|
return {"status": "ok"}
|
||||||
|
|
||||||
|
|
||||||
@api_config.post("/data/voice/model", status_code=200)
|
@api_config.post("/voice/model", status_code=200)
|
||||||
@requires(["authenticated", "premium"])
|
@requires(["authenticated", "premium"])
|
||||||
async def update_voice_model(
|
async def update_voice_model(
|
||||||
request: Request,
|
request: Request,
|
||||||
@@ -308,7 +308,7 @@ async def update_voice_model(
|
|||||||
return Response(status_code=202, content=json.dumps({"status": "ok"}))
|
return Response(status_code=202, content=json.dumps({"status": "ok"}))
|
||||||
|
|
||||||
|
|
||||||
@api_config.post("/data/search/model", status_code=200)
|
@api_config.post("/search/model", status_code=200)
|
||||||
@requires(["authenticated"])
|
@requires(["authenticated"])
|
||||||
async def update_search_model(
|
async def update_search_model(
|
||||||
request: Request,
|
request: Request,
|
||||||
@@ -341,7 +341,7 @@ async def update_search_model(
|
|||||||
return {"status": "ok"}
|
return {"status": "ok"}
|
||||||
|
|
||||||
|
|
||||||
@api_config.post("/data/paint/model", status_code=200)
|
@api_config.post("/paint/model", status_code=200)
|
||||||
@requires(["authenticated"])
|
@requires(["authenticated"])
|
||||||
async def update_paint_model(
|
async def update_paint_model(
|
||||||
request: Request,
|
request: Request,
|
||||||
@@ -370,9 +370,9 @@ async def update_paint_model(
|
|||||||
return {"status": "ok"}
|
return {"status": "ok"}
|
||||||
|
|
||||||
|
|
||||||
@api_config.get("/index/size", response_model=Dict[str, int])
|
@api_config.get("/content/size", response_model=Dict[str, int])
|
||||||
@requires(["authenticated"])
|
@requires(["authenticated"])
|
||||||
async def get_indexed_data_size(request: Request, common: CommonQueryParams):
|
async def get_content_size(request: Request, common: CommonQueryParams):
|
||||||
user = request.user.object
|
user = request.user.object
|
||||||
indexed_data_size_in_mb = await sync_to_async(EntryAdapters.get_size_of_indexed_data_in_mb)(user)
|
indexed_data_size_in_mb = await sync_to_async(EntryAdapters.get_size_of_indexed_data_in_mb)(user)
|
||||||
return Response(
|
return Response(
|
||||||
|
|||||||
Reference in New Issue
Block a user