mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-07 21:29:13 +00:00
Return user's Notion token in API call for detailed user settings
This commit is contained in:
@@ -41,9 +41,11 @@ export interface UserConfig {
|
|||||||
given_name: string;
|
given_name: string;
|
||||||
phone_number: string;
|
phone_number: string;
|
||||||
is_phone_number_verified: boolean;
|
is_phone_number_verified: boolean;
|
||||||
// user content, model settings
|
// user content settings
|
||||||
enabled_content_source: SyncedContent;
|
enabled_content_source: SyncedContent;
|
||||||
has_documents: boolean;
|
has_documents: boolean;
|
||||||
|
notion_token: string | null;
|
||||||
|
// user model settings
|
||||||
search_model_options: ModelOptions[];
|
search_model_options: ModelOptions[];
|
||||||
selected_search_model_config: number;
|
selected_search_model_config: number;
|
||||||
chat_model_options: ModelOptions[];
|
chat_model_options: ModelOptions[];
|
||||||
|
|||||||
@@ -245,6 +245,18 @@ async def delete_content_source(
|
|||||||
):
|
):
|
||||||
user = request.user.object
|
user = request.user.object
|
||||||
|
|
||||||
|
content_object = map_config_to_object(content_source)
|
||||||
|
if content_object is None:
|
||||||
|
raise ValueError(f"Invalid content source: {content_source}")
|
||||||
|
elif content_object != "Computer":
|
||||||
|
await content_object.objects.filter(user=user).adelete()
|
||||||
|
await sync_to_async(EntryAdapters.delete_all_entries)(user, file_source=content_source)
|
||||||
|
|
||||||
|
if content_source == DbEntry.EntrySource.NOTION:
|
||||||
|
await NotionConfig.objects.filter(user=user).adelete()
|
||||||
|
elif content_source == DbEntry.EntrySource.GITHUB:
|
||||||
|
await GithubConfig.objects.filter(user=user).adelete()
|
||||||
|
|
||||||
update_telemetry_state(
|
update_telemetry_state(
|
||||||
request=request,
|
request=request,
|
||||||
telemetry_type="api",
|
telemetry_type="api",
|
||||||
@@ -253,13 +265,6 @@ async def delete_content_source(
|
|||||||
metadata={"content_source": content_source},
|
metadata={"content_source": content_source},
|
||||||
)
|
)
|
||||||
|
|
||||||
content_object = map_config_to_object(content_source)
|
|
||||||
if content_object is None:
|
|
||||||
raise ValueError(f"Invalid content source: {content_source}")
|
|
||||||
elif content_object != "Computer":
|
|
||||||
await content_object.objects.filter(user=user).adelete()
|
|
||||||
await sync_to_async(EntryAdapters.delete_all_entries)(user, file_source=content_source)
|
|
||||||
|
|
||||||
enabled_content = await sync_to_async(EntryAdapters.get_unique_file_types)(user)
|
enabled_content = await sync_to_async(EntryAdapters.get_unique_file_types)(user)
|
||||||
return {"status": "ok"}
|
return {"status": "ok"}
|
||||||
|
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ from khoj.database.adapters import (
|
|||||||
create_khoj_token,
|
create_khoj_token,
|
||||||
get_khoj_tokens,
|
get_khoj_tokens,
|
||||||
get_user_name,
|
get_user_name,
|
||||||
|
get_user_notion_config,
|
||||||
get_user_subscription_state,
|
get_user_subscription_state,
|
||||||
run_with_process_lock,
|
run_with_process_lock,
|
||||||
)
|
)
|
||||||
@@ -1254,6 +1255,10 @@ def get_user_config(user: KhojUser, request: Request, is_detailed: bool = False)
|
|||||||
"notion": ("notion" in enabled_content_sources_set),
|
"notion": ("notion" in enabled_content_sources_set),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
notion_oauth_url = get_notion_auth_url(user)
|
||||||
|
current_notion_config = get_user_notion_config(user)
|
||||||
|
notion_token = current_notion_config.token if current_notion_config else ""
|
||||||
|
|
||||||
selected_chat_model_config = ConversationAdapters.get_conversation_config(user)
|
selected_chat_model_config = ConversationAdapters.get_conversation_config(user)
|
||||||
chat_models = ConversationAdapters.get_conversation_processor_options().all()
|
chat_models = ConversationAdapters.get_conversation_processor_options().all()
|
||||||
chat_model_options = list()
|
chat_model_options = list()
|
||||||
@@ -1273,10 +1278,6 @@ def get_user_config(user: KhojUser, request: Request, is_detailed: bool = False)
|
|||||||
for paint_model in paint_model_options:
|
for paint_model in paint_model_options:
|
||||||
all_paint_model_options.append({"name": paint_model.model_name, "id": paint_model.id})
|
all_paint_model_options.append({"name": paint_model.model_name, "id": paint_model.id})
|
||||||
|
|
||||||
notion_oauth_url = get_notion_auth_url(user)
|
|
||||||
|
|
||||||
eleven_labs_enabled = is_eleven_labs_enabled()
|
|
||||||
|
|
||||||
voice_models = ConversationAdapters.get_voice_model_options()
|
voice_models = ConversationAdapters.get_voice_model_options()
|
||||||
voice_model_options = list()
|
voice_model_options = list()
|
||||||
for voice_model in voice_models:
|
for voice_model in voice_models:
|
||||||
@@ -1284,6 +1285,8 @@ def get_user_config(user: KhojUser, request: Request, is_detailed: bool = False)
|
|||||||
|
|
||||||
if len(voice_model_options) == 0:
|
if len(voice_model_options) == 0:
|
||||||
eleven_labs_enabled = False
|
eleven_labs_enabled = False
|
||||||
|
else:
|
||||||
|
eleven_labs_enabled = is_eleven_labs_enabled()
|
||||||
|
|
||||||
selected_voice_model_config = ConversationAdapters.get_voice_model_config(user)
|
selected_voice_model_config = ConversationAdapters.get_voice_model_config(user)
|
||||||
|
|
||||||
@@ -1296,9 +1299,11 @@ def get_user_config(user: KhojUser, request: Request, is_detailed: bool = False)
|
|||||||
"given_name": given_name,
|
"given_name": given_name,
|
||||||
"phone_number": user.phone_number,
|
"phone_number": user.phone_number,
|
||||||
"is_phone_number_verified": user.verified_phone_number,
|
"is_phone_number_verified": user.verified_phone_number,
|
||||||
# user content, model settings
|
# user content settings
|
||||||
"enabled_content_source": enabled_content_sources,
|
"enabled_content_source": enabled_content_sources,
|
||||||
"has_documents": has_documents,
|
"has_documents": has_documents,
|
||||||
|
"notion_token": notion_token,
|
||||||
|
# user model settings
|
||||||
"search_model_options": all_search_model_options,
|
"search_model_options": all_search_model_options,
|
||||||
"selected_search_model_config": current_search_model_option.id,
|
"selected_search_model_config": current_search_model_option.id,
|
||||||
"chat_model_options": chat_model_options,
|
"chat_model_options": chat_model_options,
|
||||||
|
|||||||
Reference in New Issue
Block a user