khoj 1.16.1.dev15__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- khoj/__init__.py +0 -0
- khoj/app/README.md +94 -0
- khoj/app/__init__.py +0 -0
- khoj/app/asgi.py +16 -0
- khoj/app/settings.py +192 -0
- khoj/app/urls.py +25 -0
- khoj/configure.py +424 -0
- khoj/database/__init__.py +0 -0
- khoj/database/adapters/__init__.py +1234 -0
- khoj/database/admin.py +290 -0
- khoj/database/apps.py +6 -0
- khoj/database/management/__init__.py +0 -0
- khoj/database/management/commands/__init__.py +0 -0
- khoj/database/management/commands/change_generated_images_url.py +61 -0
- khoj/database/management/commands/convert_images_png_to_webp.py +99 -0
- khoj/database/migrations/0001_khojuser.py +98 -0
- khoj/database/migrations/0002_googleuser.py +32 -0
- khoj/database/migrations/0003_vector_extension.py +10 -0
- khoj/database/migrations/0004_content_types_and_more.py +181 -0
- khoj/database/migrations/0005_embeddings_corpus_id.py +19 -0
- khoj/database/migrations/0006_embeddingsdates.py +33 -0
- khoj/database/migrations/0007_add_conversation.py +27 -0
- khoj/database/migrations/0008_alter_conversation_conversation_log.py +17 -0
- khoj/database/migrations/0009_khojapiuser.py +24 -0
- khoj/database/migrations/0010_chatmodeloptions_and_more.py +83 -0
- khoj/database/migrations/0010_rename_embeddings_entry_and_more.py +30 -0
- khoj/database/migrations/0011_merge_20231102_0138.py +14 -0
- khoj/database/migrations/0012_entry_file_source.py +21 -0
- khoj/database/migrations/0013_subscription.py +37 -0
- khoj/database/migrations/0014_alter_googleuser_picture.py +17 -0
- khoj/database/migrations/0015_alter_subscription_user.py +21 -0
- khoj/database/migrations/0016_alter_subscription_renewal_date.py +17 -0
- khoj/database/migrations/0017_searchmodel.py +32 -0
- khoj/database/migrations/0018_searchmodelconfig_delete_searchmodel.py +30 -0
- khoj/database/migrations/0019_alter_googleuser_family_name_and_more.py +27 -0
- khoj/database/migrations/0020_reflectivequestion.py +36 -0
- khoj/database/migrations/0021_speechtotextmodeloptions_and_more.py +42 -0
- khoj/database/migrations/0022_texttoimagemodelconfig.py +25 -0
- khoj/database/migrations/0023_usersearchmodelconfig.py +33 -0
- khoj/database/migrations/0024_alter_entry_embeddings.py +18 -0
- khoj/database/migrations/0025_clientapplication_khojuser_phone_number_and_more.py +46 -0
- khoj/database/migrations/0025_searchmodelconfig_embeddings_inference_endpoint_and_more.py +22 -0
- khoj/database/migrations/0026_searchmodelconfig_cross_encoder_inference_endpoint_and_more.py +22 -0
- khoj/database/migrations/0027_merge_20240118_1324.py +13 -0
- khoj/database/migrations/0028_khojuser_verified_phone_number.py +17 -0
- khoj/database/migrations/0029_userrequests.py +27 -0
- khoj/database/migrations/0030_conversation_slug_and_title.py +38 -0
- khoj/database/migrations/0031_agent_conversation_agent.py +53 -0
- khoj/database/migrations/0031_alter_googleuser_locale.py +30 -0
- khoj/database/migrations/0032_merge_20240322_0427.py +14 -0
- khoj/database/migrations/0033_rename_tuning_agent_personality.py +17 -0
- khoj/database/migrations/0034_alter_chatmodeloptions_chat_model.py +32 -0
- khoj/database/migrations/0035_processlock.py +26 -0
- khoj/database/migrations/0036_alter_processlock_name.py +19 -0
- khoj/database/migrations/0036_delete_offlinechatprocessorconversationconfig.py +15 -0
- khoj/database/migrations/0036_publicconversation.py +42 -0
- khoj/database/migrations/0037_chatmodeloptions_openai_config_and_more.py +51 -0
- khoj/database/migrations/0037_searchmodelconfig_bi_encoder_docs_encode_config_and_more.py +32 -0
- khoj/database/migrations/0038_merge_20240425_0857.py +14 -0
- khoj/database/migrations/0038_merge_20240426_1640.py +12 -0
- khoj/database/migrations/0039_merge_20240501_0301.py +12 -0
- khoj/database/migrations/0040_alter_processlock_name.py +26 -0
- khoj/database/migrations/0040_merge_20240504_1010.py +14 -0
- khoj/database/migrations/0041_merge_20240505_1234.py +14 -0
- khoj/database/migrations/0042_serverchatsettings.py +46 -0
- khoj/database/migrations/0043_alter_chatmodeloptions_model_type.py +21 -0
- khoj/database/migrations/0044_conversation_file_filters.py +17 -0
- khoj/database/migrations/0045_fileobject.py +37 -0
- khoj/database/migrations/0046_khojuser_email_verification_code_and_more.py +22 -0
- khoj/database/migrations/0047_alter_entry_file_type.py +31 -0
- khoj/database/migrations/0048_voicemodeloption_uservoicemodelconfig.py +52 -0
- khoj/database/migrations/0049_datastore.py +38 -0
- khoj/database/migrations/0049_texttoimagemodelconfig_api_key_and_more.py +58 -0
- khoj/database/migrations/0050_alter_processlock_name.py +25 -0
- khoj/database/migrations/0051_merge_20240702_1220.py +14 -0
- khoj/database/migrations/0052_alter_searchmodelconfig_bi_encoder_docs_encode_config_and_more.py +27 -0
- khoj/database/migrations/__init__.py +0 -0
- khoj/database/models/__init__.py +402 -0
- khoj/database/tests.py +3 -0
- khoj/interface/email/feedback.html +34 -0
- khoj/interface/email/magic_link.html +17 -0
- khoj/interface/email/task.html +40 -0
- khoj/interface/email/welcome.html +61 -0
- khoj/interface/web/404.html +56 -0
- khoj/interface/web/agent.html +312 -0
- khoj/interface/web/agents.html +276 -0
- khoj/interface/web/assets/icons/agents.svg +6 -0
- khoj/interface/web/assets/icons/automation.svg +37 -0
- khoj/interface/web/assets/icons/cancel.svg +3 -0
- khoj/interface/web/assets/icons/chat.svg +24 -0
- khoj/interface/web/assets/icons/collapse.svg +17 -0
- khoj/interface/web/assets/icons/computer.png +0 -0
- khoj/interface/web/assets/icons/confirm-icon.svg +1 -0
- khoj/interface/web/assets/icons/copy-button-success.svg +6 -0
- khoj/interface/web/assets/icons/copy-button.svg +5 -0
- khoj/interface/web/assets/icons/credit-card.png +0 -0
- khoj/interface/web/assets/icons/delete.svg +26 -0
- khoj/interface/web/assets/icons/docx.svg +7 -0
- khoj/interface/web/assets/icons/edit.svg +4 -0
- khoj/interface/web/assets/icons/favicon-128x128.ico +0 -0
- khoj/interface/web/assets/icons/favicon-128x128.png +0 -0
- khoj/interface/web/assets/icons/favicon-256x256.png +0 -0
- khoj/interface/web/assets/icons/favicon.icns +0 -0
- khoj/interface/web/assets/icons/github.svg +1 -0
- khoj/interface/web/assets/icons/key.svg +4 -0
- khoj/interface/web/assets/icons/khoj-logo-sideways-200.png +0 -0
- khoj/interface/web/assets/icons/khoj-logo-sideways-500.png +0 -0
- khoj/interface/web/assets/icons/khoj-logo-sideways.svg +5385 -0
- khoj/interface/web/assets/icons/logotype.svg +1 -0
- khoj/interface/web/assets/icons/markdown.svg +1 -0
- khoj/interface/web/assets/icons/new.svg +23 -0
- khoj/interface/web/assets/icons/notion.svg +4 -0
- khoj/interface/web/assets/icons/openai-logomark.svg +1 -0
- khoj/interface/web/assets/icons/org.svg +1 -0
- khoj/interface/web/assets/icons/pdf.svg +23 -0
- khoj/interface/web/assets/icons/pencil-edit.svg +5 -0
- khoj/interface/web/assets/icons/plaintext.svg +1 -0
- khoj/interface/web/assets/icons/question-mark-icon.svg +1 -0
- khoj/interface/web/assets/icons/search.svg +25 -0
- khoj/interface/web/assets/icons/send.svg +1 -0
- khoj/interface/web/assets/icons/share.svg +8 -0
- khoj/interface/web/assets/icons/speaker.svg +4 -0
- khoj/interface/web/assets/icons/stop-solid.svg +37 -0
- khoj/interface/web/assets/icons/sync.svg +4 -0
- khoj/interface/web/assets/icons/thumbs-down-svgrepo-com.svg +6 -0
- khoj/interface/web/assets/icons/thumbs-up-svgrepo-com.svg +6 -0
- khoj/interface/web/assets/icons/user-silhouette.svg +4 -0
- khoj/interface/web/assets/icons/voice.svg +8 -0
- khoj/interface/web/assets/icons/web.svg +2 -0
- khoj/interface/web/assets/icons/whatsapp.svg +17 -0
- khoj/interface/web/assets/khoj.css +237 -0
- khoj/interface/web/assets/markdown-it.min.js +8476 -0
- khoj/interface/web/assets/natural-cron.min.js +1 -0
- khoj/interface/web/assets/org.min.js +1823 -0
- khoj/interface/web/assets/pico.min.css +5 -0
- khoj/interface/web/assets/purify.min.js +3 -0
- khoj/interface/web/assets/samples/desktop-browse-draw-sample.png +0 -0
- khoj/interface/web/assets/samples/desktop-plain-chat-sample.png +0 -0
- khoj/interface/web/assets/samples/desktop-remember-plan-sample.png +0 -0
- khoj/interface/web/assets/samples/phone-browse-draw-sample.png +0 -0
- khoj/interface/web/assets/samples/phone-plain-chat-sample.png +0 -0
- khoj/interface/web/assets/samples/phone-remember-plan-sample.png +0 -0
- khoj/interface/web/assets/utils.js +33 -0
- khoj/interface/web/base_config.html +445 -0
- khoj/interface/web/chat.html +3546 -0
- khoj/interface/web/config.html +1011 -0
- khoj/interface/web/config_automation.html +1103 -0
- khoj/interface/web/content_source_computer_input.html +139 -0
- khoj/interface/web/content_source_github_input.html +216 -0
- khoj/interface/web/content_source_notion_input.html +94 -0
- khoj/interface/web/khoj.webmanifest +51 -0
- khoj/interface/web/login.html +219 -0
- khoj/interface/web/public_conversation.html +2006 -0
- khoj/interface/web/search.html +470 -0
- khoj/interface/web/utils.html +48 -0
- khoj/main.py +241 -0
- khoj/manage.py +22 -0
- khoj/migrations/__init__.py +0 -0
- khoj/migrations/migrate_offline_chat_default_model.py +69 -0
- khoj/migrations/migrate_offline_chat_default_model_2.py +71 -0
- khoj/migrations/migrate_offline_chat_schema.py +83 -0
- khoj/migrations/migrate_offline_model.py +29 -0
- khoj/migrations/migrate_processor_config_openai.py +67 -0
- khoj/migrations/migrate_server_pg.py +138 -0
- khoj/migrations/migrate_version.py +17 -0
- khoj/processor/__init__.py +0 -0
- khoj/processor/content/__init__.py +0 -0
- khoj/processor/content/docx/__init__.py +0 -0
- khoj/processor/content/docx/docx_to_entries.py +110 -0
- khoj/processor/content/github/__init__.py +0 -0
- khoj/processor/content/github/github_to_entries.py +224 -0
- khoj/processor/content/images/__init__.py +0 -0
- khoj/processor/content/images/image_to_entries.py +118 -0
- khoj/processor/content/markdown/__init__.py +0 -0
- khoj/processor/content/markdown/markdown_to_entries.py +165 -0
- khoj/processor/content/notion/notion_to_entries.py +260 -0
- khoj/processor/content/org_mode/__init__.py +0 -0
- khoj/processor/content/org_mode/org_to_entries.py +231 -0
- khoj/processor/content/org_mode/orgnode.py +532 -0
- khoj/processor/content/pdf/__init__.py +0 -0
- khoj/processor/content/pdf/pdf_to_entries.py +116 -0
- khoj/processor/content/plaintext/__init__.py +0 -0
- khoj/processor/content/plaintext/plaintext_to_entries.py +122 -0
- khoj/processor/content/text_to_entries.py +297 -0
- khoj/processor/conversation/__init__.py +0 -0
- khoj/processor/conversation/anthropic/__init__.py +0 -0
- khoj/processor/conversation/anthropic/anthropic_chat.py +206 -0
- khoj/processor/conversation/anthropic/utils.py +114 -0
- khoj/processor/conversation/offline/__init__.py +0 -0
- khoj/processor/conversation/offline/chat_model.py +231 -0
- khoj/processor/conversation/offline/utils.py +78 -0
- khoj/processor/conversation/offline/whisper.py +15 -0
- khoj/processor/conversation/openai/__init__.py +0 -0
- khoj/processor/conversation/openai/gpt.py +187 -0
- khoj/processor/conversation/openai/utils.py +129 -0
- khoj/processor/conversation/openai/whisper.py +13 -0
- khoj/processor/conversation/prompts.py +758 -0
- khoj/processor/conversation/utils.py +262 -0
- khoj/processor/embeddings.py +117 -0
- khoj/processor/speech/__init__.py +0 -0
- khoj/processor/speech/text_to_speech.py +51 -0
- khoj/processor/tools/__init__.py +0 -0
- khoj/processor/tools/online_search.py +225 -0
- khoj/routers/__init__.py +0 -0
- khoj/routers/api.py +626 -0
- khoj/routers/api_agents.py +43 -0
- khoj/routers/api_chat.py +1180 -0
- khoj/routers/api_config.py +434 -0
- khoj/routers/api_phone.py +86 -0
- khoj/routers/auth.py +181 -0
- khoj/routers/email.py +133 -0
- khoj/routers/helpers.py +1188 -0
- khoj/routers/indexer.py +349 -0
- khoj/routers/notion.py +91 -0
- khoj/routers/storage.py +35 -0
- khoj/routers/subscription.py +104 -0
- khoj/routers/twilio.py +36 -0
- khoj/routers/web_client.py +471 -0
- khoj/search_filter/__init__.py +0 -0
- khoj/search_filter/base_filter.py +15 -0
- khoj/search_filter/date_filter.py +217 -0
- khoj/search_filter/file_filter.py +30 -0
- khoj/search_filter/word_filter.py +29 -0
- khoj/search_type/__init__.py +0 -0
- khoj/search_type/text_search.py +241 -0
- khoj/utils/__init__.py +0 -0
- khoj/utils/cli.py +93 -0
- khoj/utils/config.py +81 -0
- khoj/utils/constants.py +24 -0
- khoj/utils/fs_syncer.py +249 -0
- khoj/utils/helpers.py +418 -0
- khoj/utils/initialization.py +146 -0
- khoj/utils/jsonl.py +43 -0
- khoj/utils/models.py +47 -0
- khoj/utils/rawconfig.py +160 -0
- khoj/utils/state.py +46 -0
- khoj/utils/yaml.py +43 -0
- khoj-1.16.1.dev15.dist-info/METADATA +178 -0
- khoj-1.16.1.dev15.dist-info/RECORD +242 -0
- khoj-1.16.1.dev15.dist-info/WHEEL +4 -0
- khoj-1.16.1.dev15.dist-info/entry_points.txt +2 -0
- khoj-1.16.1.dev15.dist-info/licenses/LICENSE +661 -0
|
@@ -0,0 +1,471 @@
|
|
|
1
|
+
# System Packages
|
|
2
|
+
import json
|
|
3
|
+
import os
|
|
4
|
+
from datetime import timedelta
|
|
5
|
+
from typing import Optional
|
|
6
|
+
|
|
7
|
+
from fastapi import APIRouter, Request
|
|
8
|
+
from fastapi.responses import FileResponse, HTMLResponse, RedirectResponse
|
|
9
|
+
from fastapi.templating import Jinja2Templates
|
|
10
|
+
from starlette.authentication import has_required_scope, requires
|
|
11
|
+
|
|
12
|
+
from khoj.database import adapters
|
|
13
|
+
from khoj.database.adapters import (
|
|
14
|
+
AgentAdapters,
|
|
15
|
+
ConversationAdapters,
|
|
16
|
+
EntryAdapters,
|
|
17
|
+
PublicConversationAdapters,
|
|
18
|
+
get_user_github_config,
|
|
19
|
+
get_user_name,
|
|
20
|
+
get_user_notion_config,
|
|
21
|
+
get_user_subscription_state,
|
|
22
|
+
)
|
|
23
|
+
from khoj.database.models import KhojUser
|
|
24
|
+
from khoj.processor.speech.text_to_speech import is_eleven_labs_enabled
|
|
25
|
+
from khoj.routers.helpers import get_next_url
|
|
26
|
+
from khoj.routers.notion import get_notion_auth_url
|
|
27
|
+
from khoj.routers.twilio import is_twilio_enabled
|
|
28
|
+
from khoj.utils import constants, state
|
|
29
|
+
from khoj.utils.rawconfig import (
|
|
30
|
+
GithubContentConfig,
|
|
31
|
+
GithubRepoConfig,
|
|
32
|
+
NotionContentConfig,
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
# Initialize Router
|
|
36
|
+
web_client = APIRouter()
|
|
37
|
+
templates = Jinja2Templates([constants.web_directory, constants.next_js_directory])
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
# Create Routes
|
|
41
|
+
@web_client.get("/", response_class=FileResponse)
|
|
42
|
+
@requires(["authenticated"], redirect="login_page")
|
|
43
|
+
def index(request: Request):
|
|
44
|
+
user = request.user.object
|
|
45
|
+
user_picture = request.session.get("user", {}).get("picture")
|
|
46
|
+
has_documents = EntryAdapters.user_has_entries(user=user)
|
|
47
|
+
|
|
48
|
+
return templates.TemplateResponse(
|
|
49
|
+
"chat.html",
|
|
50
|
+
context={
|
|
51
|
+
"request": request,
|
|
52
|
+
"username": user.username,
|
|
53
|
+
"user_photo": user_picture,
|
|
54
|
+
"is_active": has_required_scope(request, ["premium"]),
|
|
55
|
+
"has_documents": has_documents,
|
|
56
|
+
"khoj_version": state.khoj_version,
|
|
57
|
+
},
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
@web_client.post("/", response_class=FileResponse)
|
|
62
|
+
@requires(["authenticated"], redirect="login_page")
|
|
63
|
+
def index_post(request: Request):
|
|
64
|
+
user = request.user.object
|
|
65
|
+
user_picture = request.session.get("user", {}).get("picture")
|
|
66
|
+
has_documents = EntryAdapters.user_has_entries(user=user)
|
|
67
|
+
|
|
68
|
+
return templates.TemplateResponse(
|
|
69
|
+
"chat.html",
|
|
70
|
+
context={
|
|
71
|
+
"request": request,
|
|
72
|
+
"username": user.username,
|
|
73
|
+
"user_photo": user_picture,
|
|
74
|
+
"is_active": has_required_scope(request, ["premium"]),
|
|
75
|
+
"has_documents": has_documents,
|
|
76
|
+
"khoj_version": state.khoj_version,
|
|
77
|
+
},
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
@web_client.get("/search", response_class=FileResponse)
|
|
82
|
+
@requires(["authenticated"], redirect="login_page")
|
|
83
|
+
def search_page(request: Request):
|
|
84
|
+
user = request.user.object
|
|
85
|
+
user_picture = request.session.get("user", {}).get("picture")
|
|
86
|
+
has_documents = EntryAdapters.user_has_entries(user=user)
|
|
87
|
+
|
|
88
|
+
return templates.TemplateResponse(
|
|
89
|
+
"search.html",
|
|
90
|
+
context={
|
|
91
|
+
"request": request,
|
|
92
|
+
"username": user.username,
|
|
93
|
+
"user_photo": user_picture,
|
|
94
|
+
"is_active": has_required_scope(request, ["premium"]),
|
|
95
|
+
"has_documents": has_documents,
|
|
96
|
+
"khoj_version": state.khoj_version,
|
|
97
|
+
},
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
@web_client.get("/chat", response_class=FileResponse)
|
|
102
|
+
@requires(["authenticated"], redirect="login_page")
|
|
103
|
+
def chat_page(request: Request):
|
|
104
|
+
user = request.user.object
|
|
105
|
+
user_picture = request.session.get("user", {}).get("picture")
|
|
106
|
+
has_documents = EntryAdapters.user_has_entries(user=user)
|
|
107
|
+
|
|
108
|
+
return templates.TemplateResponse(
|
|
109
|
+
"chat.html",
|
|
110
|
+
context={
|
|
111
|
+
"request": request,
|
|
112
|
+
"username": user.username,
|
|
113
|
+
"user_photo": user_picture,
|
|
114
|
+
"is_active": has_required_scope(request, ["premium"]),
|
|
115
|
+
"has_documents": has_documents,
|
|
116
|
+
"khoj_version": state.khoj_version,
|
|
117
|
+
},
|
|
118
|
+
)
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
@web_client.get("/experimental", response_class=FileResponse)
|
|
122
|
+
@requires(["authenticated"], redirect="login_page")
|
|
123
|
+
def experimental_page(request: Request):
|
|
124
|
+
return templates.TemplateResponse(
|
|
125
|
+
"index.html",
|
|
126
|
+
context={
|
|
127
|
+
"request": request,
|
|
128
|
+
},
|
|
129
|
+
)
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
@web_client.get("/factchecker", response_class=FileResponse)
|
|
133
|
+
def fact_checker_page(request: Request):
|
|
134
|
+
return templates.TemplateResponse(
|
|
135
|
+
"factchecker/index.html",
|
|
136
|
+
context={
|
|
137
|
+
"request": request,
|
|
138
|
+
},
|
|
139
|
+
)
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
@web_client.get("/login", response_class=FileResponse)
|
|
143
|
+
def login_page(request: Request):
|
|
144
|
+
next_url = get_next_url(request)
|
|
145
|
+
if request.user.is_authenticated:
|
|
146
|
+
return RedirectResponse(url=next_url)
|
|
147
|
+
google_client_id = os.environ.get("GOOGLE_CLIENT_ID")
|
|
148
|
+
redirect_uri = str(request.app.url_path_for("auth"))
|
|
149
|
+
return templates.TemplateResponse(
|
|
150
|
+
"login.html",
|
|
151
|
+
context={
|
|
152
|
+
"request": request,
|
|
153
|
+
"google_client_id": google_client_id,
|
|
154
|
+
"redirect_uri": f"{redirect_uri}?next={next_url}",
|
|
155
|
+
},
|
|
156
|
+
)
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
@web_client.get("/agents", response_class=HTMLResponse)
|
|
160
|
+
def agents_page(request: Request):
|
|
161
|
+
return templates.TemplateResponse(
|
|
162
|
+
"agents/index.html",
|
|
163
|
+
context={
|
|
164
|
+
"request": request,
|
|
165
|
+
},
|
|
166
|
+
)
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
@web_client.get("/agent/{agent_slug}", response_class=HTMLResponse)
|
|
170
|
+
def agent_page(request: Request, agent_slug: str):
|
|
171
|
+
user: KhojUser = request.user.object if request.user.is_authenticated else None
|
|
172
|
+
user_picture = request.session.get("user", {}).get("picture") if user else None
|
|
173
|
+
|
|
174
|
+
agent = AgentAdapters.get_agent_by_slug(agent_slug)
|
|
175
|
+
has_documents = EntryAdapters.user_has_entries(user=user)
|
|
176
|
+
|
|
177
|
+
if agent == None:
|
|
178
|
+
return templates.TemplateResponse(
|
|
179
|
+
"404.html",
|
|
180
|
+
context={
|
|
181
|
+
"request": request,
|
|
182
|
+
"khoj_version": state.khoj_version,
|
|
183
|
+
"username": user.username if user else None,
|
|
184
|
+
"has_documents": False,
|
|
185
|
+
"is_active": has_required_scope(request, ["premium"]),
|
|
186
|
+
"user_photo": user_picture,
|
|
187
|
+
},
|
|
188
|
+
)
|
|
189
|
+
|
|
190
|
+
agent_metadata = {
|
|
191
|
+
"slug": agent.slug,
|
|
192
|
+
"avatar": agent.avatar,
|
|
193
|
+
"name": agent.name,
|
|
194
|
+
"personality": agent.personality,
|
|
195
|
+
"public": agent.public,
|
|
196
|
+
"creator": agent.creator.username if agent.creator else None,
|
|
197
|
+
"managed_by_admin": agent.managed_by_admin,
|
|
198
|
+
"chat_model": agent.chat_model.chat_model,
|
|
199
|
+
"creator_not_self": agent.creator != user,
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
return templates.TemplateResponse(
|
|
203
|
+
"agent.html",
|
|
204
|
+
context={
|
|
205
|
+
"request": request,
|
|
206
|
+
"agent": agent_metadata,
|
|
207
|
+
"khoj_version": state.khoj_version,
|
|
208
|
+
"username": user.username if user else None,
|
|
209
|
+
"has_documents": has_documents,
|
|
210
|
+
"is_active": has_required_scope(request, ["premium"]),
|
|
211
|
+
"user_photo": user_picture,
|
|
212
|
+
},
|
|
213
|
+
)
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
@web_client.get("/config", response_class=HTMLResponse)
|
|
217
|
+
@requires(["authenticated"], redirect="login_page")
|
|
218
|
+
def config_page(request: Request):
|
|
219
|
+
user: KhojUser = request.user.object
|
|
220
|
+
user_picture = request.session.get("user", {}).get("picture")
|
|
221
|
+
has_documents = EntryAdapters.user_has_entries(user=user)
|
|
222
|
+
|
|
223
|
+
user_subscription_state = get_user_subscription_state(user.email)
|
|
224
|
+
user_subscription = adapters.get_user_subscription(user.email)
|
|
225
|
+
subscription_renewal_date = (
|
|
226
|
+
user_subscription.renewal_date.strftime("%d %b %Y")
|
|
227
|
+
if user_subscription and user_subscription.renewal_date
|
|
228
|
+
else (user_subscription.created_at + timedelta(days=7)).strftime("%d %b %Y")
|
|
229
|
+
)
|
|
230
|
+
given_name = get_user_name(user)
|
|
231
|
+
|
|
232
|
+
enabled_content_source = set(EntryAdapters.get_unique_file_sources(user))
|
|
233
|
+
successfully_configured = {
|
|
234
|
+
"computer": ("computer" in enabled_content_source),
|
|
235
|
+
"github": ("github" in enabled_content_source),
|
|
236
|
+
"notion": ("notion" in enabled_content_source),
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
selected_conversation_config = ConversationAdapters.get_conversation_config(user)
|
|
240
|
+
conversation_options = ConversationAdapters.get_conversation_processor_options().all()
|
|
241
|
+
all_conversation_options = list()
|
|
242
|
+
for conversation_option in conversation_options:
|
|
243
|
+
all_conversation_options.append({"chat_model": conversation_option.chat_model, "id": conversation_option.id})
|
|
244
|
+
|
|
245
|
+
search_model_options = adapters.get_or_create_search_models().all()
|
|
246
|
+
all_search_model_options = list()
|
|
247
|
+
for search_model_option in search_model_options:
|
|
248
|
+
all_search_model_options.append({"name": search_model_option.name, "id": search_model_option.id})
|
|
249
|
+
|
|
250
|
+
current_search_model_option = adapters.get_user_search_model_or_default(user)
|
|
251
|
+
|
|
252
|
+
selected_paint_model_config = ConversationAdapters.get_user_text_to_image_model_config(user)
|
|
253
|
+
paint_model_options = ConversationAdapters.get_text_to_image_model_options().all()
|
|
254
|
+
all_paint_model_options = list()
|
|
255
|
+
for paint_model in paint_model_options:
|
|
256
|
+
all_paint_model_options.append({"model_name": paint_model.model_name, "id": paint_model.id})
|
|
257
|
+
|
|
258
|
+
notion_oauth_url = get_notion_auth_url(user)
|
|
259
|
+
|
|
260
|
+
eleven_labs_enabled = is_eleven_labs_enabled()
|
|
261
|
+
|
|
262
|
+
voice_models = ConversationAdapters.get_voice_model_options()
|
|
263
|
+
voice_model_options = list()
|
|
264
|
+
for voice_model in voice_models:
|
|
265
|
+
voice_model_options.append({"name": voice_model.name, "id": voice_model.model_id})
|
|
266
|
+
|
|
267
|
+
if len(voice_model_options) == 0:
|
|
268
|
+
eleven_labs_enabled = False
|
|
269
|
+
|
|
270
|
+
selected_voice_config = ConversationAdapters.get_voice_model_config(user)
|
|
271
|
+
|
|
272
|
+
return templates.TemplateResponse(
|
|
273
|
+
"config.html",
|
|
274
|
+
context={
|
|
275
|
+
"request": request,
|
|
276
|
+
"current_model_state": successfully_configured,
|
|
277
|
+
"anonymous_mode": state.anonymous_mode,
|
|
278
|
+
"username": user.username,
|
|
279
|
+
"given_name": given_name,
|
|
280
|
+
"search_model_options": all_search_model_options,
|
|
281
|
+
"selected_search_model_config": current_search_model_option.id,
|
|
282
|
+
"conversation_options": all_conversation_options,
|
|
283
|
+
"selected_conversation_config": selected_conversation_config.id if selected_conversation_config else None,
|
|
284
|
+
"paint_model_options": all_paint_model_options,
|
|
285
|
+
"selected_paint_model_config": selected_paint_model_config.id if selected_paint_model_config else None,
|
|
286
|
+
"user_photo": user_picture,
|
|
287
|
+
"billing_enabled": state.billing_enabled,
|
|
288
|
+
"subscription_state": user_subscription_state,
|
|
289
|
+
"subscription_renewal_date": subscription_renewal_date,
|
|
290
|
+
"khoj_cloud_subscription_url": os.getenv("KHOJ_CLOUD_SUBSCRIPTION_URL"),
|
|
291
|
+
"is_active": has_required_scope(request, ["premium"]),
|
|
292
|
+
"has_documents": has_documents,
|
|
293
|
+
"is_twilio_enabled": is_twilio_enabled(),
|
|
294
|
+
"is_eleven_labs_enabled": eleven_labs_enabled,
|
|
295
|
+
"voice_model_options": voice_model_options,
|
|
296
|
+
"selected_voice_config": selected_voice_config.model_id if selected_voice_config else None,
|
|
297
|
+
"phone_number": user.phone_number,
|
|
298
|
+
"is_phone_number_verified": user.verified_phone_number,
|
|
299
|
+
"khoj_version": state.khoj_version,
|
|
300
|
+
"notion_oauth_url": notion_oauth_url,
|
|
301
|
+
},
|
|
302
|
+
)
|
|
303
|
+
|
|
304
|
+
|
|
305
|
+
@web_client.get("/config/content-source/github", response_class=HTMLResponse)
|
|
306
|
+
@requires(["authenticated"], redirect="login_page")
|
|
307
|
+
def github_config_page(request: Request):
|
|
308
|
+
user = request.user.object
|
|
309
|
+
user_picture = request.session.get("user", {}).get("picture")
|
|
310
|
+
has_documents = EntryAdapters.user_has_entries(user=user)
|
|
311
|
+
current_github_config = get_user_github_config(user)
|
|
312
|
+
|
|
313
|
+
if current_github_config:
|
|
314
|
+
raw_repos = current_github_config.githubrepoconfig.all()
|
|
315
|
+
repos = []
|
|
316
|
+
for repo in raw_repos:
|
|
317
|
+
repos.append(
|
|
318
|
+
GithubRepoConfig(
|
|
319
|
+
name=repo.name,
|
|
320
|
+
owner=repo.owner,
|
|
321
|
+
branch=repo.branch,
|
|
322
|
+
)
|
|
323
|
+
)
|
|
324
|
+
current_config = GithubContentConfig(
|
|
325
|
+
pat_token=current_github_config.pat_token,
|
|
326
|
+
repos=repos,
|
|
327
|
+
)
|
|
328
|
+
current_config = json.loads(current_config.json())
|
|
329
|
+
else:
|
|
330
|
+
current_config = {} # type: ignore
|
|
331
|
+
|
|
332
|
+
return templates.TemplateResponse(
|
|
333
|
+
"content_source_github_input.html",
|
|
334
|
+
context={
|
|
335
|
+
"request": request,
|
|
336
|
+
"current_config": current_config,
|
|
337
|
+
"username": user.username,
|
|
338
|
+
"user_photo": user_picture,
|
|
339
|
+
"is_active": has_required_scope(request, ["premium"]),
|
|
340
|
+
"has_documents": has_documents,
|
|
341
|
+
"khoj_version": state.khoj_version,
|
|
342
|
+
},
|
|
343
|
+
)
|
|
344
|
+
|
|
345
|
+
|
|
346
|
+
@web_client.get("/config/content-source/notion", response_class=HTMLResponse)
|
|
347
|
+
@requires(["authenticated"], redirect="login_page")
|
|
348
|
+
def notion_config_page(request: Request):
|
|
349
|
+
user = request.user.object
|
|
350
|
+
user_picture = request.session.get("user", {}).get("picture")
|
|
351
|
+
has_documents = EntryAdapters.user_has_entries(user=user)
|
|
352
|
+
current_notion_config = get_user_notion_config(user)
|
|
353
|
+
|
|
354
|
+
current_config = NotionContentConfig(
|
|
355
|
+
token=current_notion_config.token if current_notion_config else "",
|
|
356
|
+
)
|
|
357
|
+
|
|
358
|
+
current_config = json.loads(current_config.model_dump_json())
|
|
359
|
+
|
|
360
|
+
return templates.TemplateResponse(
|
|
361
|
+
"content_source_notion_input.html",
|
|
362
|
+
context={
|
|
363
|
+
"request": request,
|
|
364
|
+
"current_config": current_config,
|
|
365
|
+
"username": user.username,
|
|
366
|
+
"user_photo": user_picture,
|
|
367
|
+
"is_active": has_required_scope(request, ["premium"]),
|
|
368
|
+
"has_documents": has_documents,
|
|
369
|
+
"khoj_version": state.khoj_version,
|
|
370
|
+
},
|
|
371
|
+
)
|
|
372
|
+
|
|
373
|
+
|
|
374
|
+
@web_client.get("/config/content-source/computer", response_class=HTMLResponse)
|
|
375
|
+
@requires(["authenticated"], redirect="login_page")
|
|
376
|
+
def computer_config_page(request: Request):
|
|
377
|
+
user = request.user.object if request.user.is_authenticated else None
|
|
378
|
+
user_picture = request.session.get("user", {}).get("picture") if user else None
|
|
379
|
+
has_documents = EntryAdapters.user_has_entries(user=user) if user else False
|
|
380
|
+
|
|
381
|
+
return templates.TemplateResponse(
|
|
382
|
+
"content_source_computer_input.html",
|
|
383
|
+
context={
|
|
384
|
+
"request": request,
|
|
385
|
+
"username": user.username,
|
|
386
|
+
"user_photo": user_picture,
|
|
387
|
+
"is_active": has_required_scope(request, ["premium"]),
|
|
388
|
+
"has_documents": has_documents,
|
|
389
|
+
"khoj_version": state.khoj_version,
|
|
390
|
+
},
|
|
391
|
+
)
|
|
392
|
+
|
|
393
|
+
|
|
394
|
+
@web_client.get("/share/chat/{public_conversation_slug}", response_class=HTMLResponse)
|
|
395
|
+
def view_public_conversation(request: Request):
|
|
396
|
+
public_conversation_slug = request.path_params.get("public_conversation_slug")
|
|
397
|
+
public_conversation = PublicConversationAdapters.get_public_conversation_by_slug(public_conversation_slug)
|
|
398
|
+
if not public_conversation:
|
|
399
|
+
return templates.TemplateResponse(
|
|
400
|
+
"404.html",
|
|
401
|
+
context={
|
|
402
|
+
"request": request,
|
|
403
|
+
"khoj_version": state.khoj_version,
|
|
404
|
+
},
|
|
405
|
+
)
|
|
406
|
+
user = request.user.object if request.user.is_authenticated else None
|
|
407
|
+
user_picture = request.session.get("user", {}).get("picture") if user else None
|
|
408
|
+
has_documents = EntryAdapters.user_has_entries(user=user) if user else False
|
|
409
|
+
|
|
410
|
+
all_agents = AgentAdapters.get_all_accessible_agents(request.user.object if request.user.is_authenticated else None)
|
|
411
|
+
|
|
412
|
+
# Filter out the current agent
|
|
413
|
+
all_agents = [agent for agent in all_agents if agent != public_conversation.agent]
|
|
414
|
+
agents_packet = []
|
|
415
|
+
for agent in all_agents:
|
|
416
|
+
agents_packet.append(
|
|
417
|
+
{
|
|
418
|
+
"slug": agent.slug,
|
|
419
|
+
"avatar": agent.avatar,
|
|
420
|
+
"name": agent.name,
|
|
421
|
+
}
|
|
422
|
+
)
|
|
423
|
+
|
|
424
|
+
google_client_id = os.environ.get("GOOGLE_CLIENT_ID")
|
|
425
|
+
redirect_uri = str(request.app.url_path_for("auth"))
|
|
426
|
+
next_url = str(
|
|
427
|
+
request.app.url_path_for("view_public_conversation", public_conversation_slug=public_conversation_slug)
|
|
428
|
+
)
|
|
429
|
+
|
|
430
|
+
return templates.TemplateResponse(
|
|
431
|
+
"public_conversation.html",
|
|
432
|
+
context={
|
|
433
|
+
"request": request,
|
|
434
|
+
"username": user.username if user else None,
|
|
435
|
+
"user_photo": user_picture,
|
|
436
|
+
"is_active": has_required_scope(request, ["premium"]),
|
|
437
|
+
"has_documents": has_documents,
|
|
438
|
+
"khoj_version": state.khoj_version,
|
|
439
|
+
"public_conversation_slug": public_conversation_slug,
|
|
440
|
+
"agents": agents_packet,
|
|
441
|
+
"google_client_id": google_client_id,
|
|
442
|
+
"redirect_uri": f"{redirect_uri}?next={next_url}",
|
|
443
|
+
},
|
|
444
|
+
)
|
|
445
|
+
|
|
446
|
+
|
|
447
|
+
@web_client.get("/automations", response_class=HTMLResponse)
|
|
448
|
+
def automations_config_page(
|
|
449
|
+
request: Request,
|
|
450
|
+
subject: Optional[str] = None,
|
|
451
|
+
crontime: Optional[str] = None,
|
|
452
|
+
queryToRun: Optional[str] = None,
|
|
453
|
+
):
|
|
454
|
+
user = request.user.object if request.user.is_authenticated else None
|
|
455
|
+
user_picture = request.session.get("user", {}).get("picture")
|
|
456
|
+
has_documents = EntryAdapters.user_has_entries(user=user) if user else False
|
|
457
|
+
|
|
458
|
+
return templates.TemplateResponse(
|
|
459
|
+
"config_automation.html",
|
|
460
|
+
context={
|
|
461
|
+
"request": request,
|
|
462
|
+
"username": user.username if user else None,
|
|
463
|
+
"user_photo": user_picture,
|
|
464
|
+
"is_active": has_required_scope(request, ["premium"]),
|
|
465
|
+
"has_documents": has_documents,
|
|
466
|
+
"khoj_version": state.khoj_version,
|
|
467
|
+
"subject": subject if subject else "",
|
|
468
|
+
"crontime": crontime if crontime else "",
|
|
469
|
+
"queryToRun": queryToRun if queryToRun else "",
|
|
470
|
+
},
|
|
471
|
+
)
|
|
File without changes
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
from abc import ABC, abstractmethod
|
|
2
|
+
from typing import List
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class BaseFilter(ABC):
|
|
6
|
+
@abstractmethod
|
|
7
|
+
def get_filter_terms(self, query: str) -> List[str]:
|
|
8
|
+
...
|
|
9
|
+
|
|
10
|
+
def can_filter(self, raw_query: str) -> bool:
|
|
11
|
+
return len(self.get_filter_terms(raw_query)) > 0
|
|
12
|
+
|
|
13
|
+
@abstractmethod
|
|
14
|
+
def defilter(self, query: str) -> str:
|
|
15
|
+
...
|