mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-07 21:29:13 +00:00
Resolve merge conflicts with master
This commit is contained in:
@@ -6,5 +6,5 @@
|
|||||||
"description": "An AI copilot for your Second Brain",
|
"description": "An AI copilot for your Second Brain",
|
||||||
"author": "Khoj Inc.",
|
"author": "Khoj Inc.",
|
||||||
"authorUrl": "https://github.com/khoj-ai",
|
"authorUrl": "https://github.com/khoj-ai",
|
||||||
"isDesktopOnly": true
|
"isDesktopOnly": false
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ COPY . .
|
|||||||
RUN apt install vim -y
|
RUN apt install vim -y
|
||||||
|
|
||||||
# Set the PYTHONPATH environment variable in order for it to find the Django app.
|
# Set the PYTHONPATH environment variable in order for it to find the Django app.
|
||||||
ENV PYTHONPATH=/app/src/khoj:$PYTHONPATH
|
ENV PYTHONPATH=/app/src:$PYTHONPATH
|
||||||
|
|
||||||
# Run the Application
|
# Run the Application
|
||||||
# There are more arguments required for the application to run,
|
# There are more arguments required for the application to run,
|
||||||
|
|||||||
@@ -120,7 +120,8 @@
|
|||||||
// Create a new div for the chat message text and append it to the chat message
|
// Create a new div for the chat message text and append it to the chat message
|
||||||
let chatMessageText = document.createElement('div');
|
let chatMessageText = document.createElement('div');
|
||||||
chatMessageText.className = `chat-message-text ${by}`;
|
chatMessageText.className = `chat-message-text ${by}`;
|
||||||
chatMessageText.innerHTML = formattedMessage;
|
let textNode = document.createTextNode(formattedMessage);
|
||||||
|
chatMessageText.appendChild(textNode);
|
||||||
chatMessage.appendChild(chatMessageText);
|
chatMessage.appendChild(chatMessageText);
|
||||||
|
|
||||||
// Append annotations div to the chat message
|
// Append annotations div to the chat message
|
||||||
|
|||||||
@@ -112,14 +112,14 @@
|
|||||||
} else if (
|
} else if (
|
||||||
item.additional.file.endsWith(".md") ||
|
item.additional.file.endsWith(".md") ||
|
||||||
item.additional.file.endsWith(".markdown") ||
|
item.additional.file.endsWith(".markdown") ||
|
||||||
(item.additional.file.includes("issues") && item.additional.file.includes("github.com")) ||
|
(item.additional.file.includes("issues") && item.additional.source === "github") ||
|
||||||
(item.additional.file.includes("commit") && item.additional.file.includes("github.com"))
|
(item.additional.file.includes("commit") && item.additional.source === "github")
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
html += render_markdown(query, [item]);
|
html += render_markdown(query, [item]);
|
||||||
} else if (item.additional.file.endsWith(".pdf")) {
|
} else if (item.additional.file.endsWith(".pdf")) {
|
||||||
html += render_pdf(query, [item]);
|
html += render_pdf(query, [item]);
|
||||||
} else if (item.additional.file.includes("notion.so")) {
|
} else if (item.additional.source == "notion") {
|
||||||
html += `<div class="results-notion">` + `<b><a href="${item.additional.file}">${item.additional.heading}</a></b>` + `<p>${item.entry}</p>` + `</div>`;
|
html += `<div class="results-notion">` + `<b><a href="${item.additional.file}">${item.additional.heading}</a></b>` + `<p>${item.entry}</p>` + `</div>`;
|
||||||
} else if (item.additional.file.endsWith(".html")) {
|
} else if (item.additional.file.endsWith(".html")) {
|
||||||
html += render_html(query, [item]);
|
html += render_html(query, [item]);
|
||||||
|
|||||||
@@ -6,5 +6,5 @@
|
|||||||
"description": "An AI copilot for your Second Brain",
|
"description": "An AI copilot for your Second Brain",
|
||||||
"author": "Khoj Inc.",
|
"author": "Khoj Inc.",
|
||||||
"authorUrl": "https://github.com/khoj-ai",
|
"authorUrl": "https://github.com/khoj-ai",
|
||||||
"isDesktopOnly": true
|
"isDesktopOnly": false
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ from pathlib import Path
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
||||||
BASE_DIR = Path(__file__).resolve().parent.parent.parent.parent
|
BASE_DIR = Path(__file__).resolve().parent.parent
|
||||||
|
|
||||||
|
|
||||||
# Quick-start development settings - unsuitable for production
|
# Quick-start development settings - unsuitable for production
|
||||||
@@ -24,15 +24,15 @@ BASE_DIR = Path(__file__).resolve().parent.parent.parent.parent
|
|||||||
SECRET_KEY = os.getenv("KHOJ_DJANGO_SECRET_KEY")
|
SECRET_KEY = os.getenv("KHOJ_DJANGO_SECRET_KEY")
|
||||||
|
|
||||||
# SECURITY WARNING: don't run with debug turned on in production!
|
# SECURITY WARNING: don't run with debug turned on in production!
|
||||||
DEBUG = os.getenv("KHOJ_DEBUG", "False") == "True"
|
DEBUG = os.getenv("KHOJ_DEBUG") == "True"
|
||||||
|
|
||||||
ALLOWED_HOSTS = [".khoj.dev", "localhost", "127.0.0.1", "[::1]", "beta.khoj.dev"]
|
# All Subdomains of KHOJ_DOMAIN are trusted
|
||||||
|
KHOJ_DOMAIN = os.getenv("KHOJ_DOMAIN", "khoj.dev")
|
||||||
|
ALLOWED_HOSTS = [f".{KHOJ_DOMAIN}", "localhost", "127.0.0.1", "[::1]"]
|
||||||
|
|
||||||
CSRF_TRUSTED_ORIGINS = [
|
CSRF_TRUSTED_ORIGINS = [
|
||||||
"https://app.khoj.dev",
|
f"https://*.{KHOJ_DOMAIN}",
|
||||||
"https://beta.khoj.dev",
|
f"https://{KHOJ_DOMAIN}",
|
||||||
"https://khoj.dev",
|
|
||||||
"https://*.khoj.dev",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
COOKIE_SAMESITE = "None"
|
COOKIE_SAMESITE = "None"
|
||||||
@@ -40,8 +40,8 @@ if DEBUG:
|
|||||||
SESSION_COOKIE_DOMAIN = "localhost"
|
SESSION_COOKIE_DOMAIN = "localhost"
|
||||||
CSRF_COOKIE_DOMAIN = "localhost"
|
CSRF_COOKIE_DOMAIN = "localhost"
|
||||||
else:
|
else:
|
||||||
SESSION_COOKIE_DOMAIN = "khoj.dev"
|
SESSION_COOKIE_DOMAIN = KHOJ_DOMAIN
|
||||||
CSRF_COOKIE_DOMAIN = "khoj.dev"
|
CSRF_COOKIE_DOMAIN = KHOJ_DOMAIN
|
||||||
|
|
||||||
SESSION_COOKIE_SECURE = True
|
SESSION_COOKIE_SECURE = True
|
||||||
CSRF_COOKIE_SECURE = True
|
CSRF_COOKIE_SECURE = True
|
||||||
@@ -143,7 +143,7 @@ USE_TZ = True
|
|||||||
# https://docs.djangoproject.com/en/4.2/howto/static-files/
|
# https://docs.djangoproject.com/en/4.2/howto/static-files/
|
||||||
|
|
||||||
STATIC_ROOT = BASE_DIR / "static"
|
STATIC_ROOT = BASE_DIR / "static"
|
||||||
STATICFILES_DIRS = [BASE_DIR / "src/khoj/interface/web"]
|
STATICFILES_DIRS = [BASE_DIR / "interface/web"]
|
||||||
STATIC_URL = "/static/"
|
STATIC_URL = "/static/"
|
||||||
|
|
||||||
# Default primary key field type
|
# Default primary key field type
|
||||||
|
|||||||
@@ -112,14 +112,14 @@
|
|||||||
} else if (
|
} else if (
|
||||||
item.additional.file.endsWith(".md") ||
|
item.additional.file.endsWith(".md") ||
|
||||||
item.additional.file.endsWith(".markdown") ||
|
item.additional.file.endsWith(".markdown") ||
|
||||||
(item.additional.file.includes("issues") && item.additional.file.includes("github.com")) ||
|
(item.additional.file.includes("issues") && item.additional.source === "github") ||
|
||||||
(item.additional.file.includes("commit") && item.additional.file.includes("github.com"))
|
(item.additional.file.includes("commit") && item.additional.source === "github")
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
html += render_markdown(query, [item]);
|
html += render_markdown(query, [item]);
|
||||||
} else if (item.additional.file.endsWith(".pdf")) {
|
} else if (item.additional.file.endsWith(".pdf")) {
|
||||||
html += render_pdf(query, [item]);
|
html += render_pdf(query, [item]);
|
||||||
} else if (item.additional.file.includes("notion.so")) {
|
} else if (item.additional.source === "notion") {
|
||||||
html += `<div class="results-notion">` + `<b><a href="${item.additional.file}">${item.additional.heading}</a></b>` + `<p>${item.entry}</p>` + `</div>`;
|
html += `<div class="results-notion">` + `<b><a href="${item.additional.file}">${item.additional.heading}</a></b>` + `<p>${item.entry}</p>` + `</div>`;
|
||||||
} else if (item.additional.file.endsWith(".html")) {
|
} else if (item.additional.file.endsWith(".html")) {
|
||||||
html += render_html(query, [item]);
|
html += render_html(query, [item]);
|
||||||
|
|||||||
@@ -3,6 +3,8 @@
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
# Standard Packages
|
# Standard Packages
|
||||||
|
from contextlib import redirect_stdout
|
||||||
|
import io
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import locale
|
import locale
|
||||||
@@ -33,10 +35,14 @@ os.environ.setdefault("DJANGO_SETTINGS_MODULE", "khoj.app.settings")
|
|||||||
django.setup()
|
django.setup()
|
||||||
|
|
||||||
# Initialize Django Database
|
# Initialize Django Database
|
||||||
call_command("migrate", "--noinput")
|
db_migrate_output = io.StringIO()
|
||||||
|
with redirect_stdout(db_migrate_output):
|
||||||
|
call_command("migrate", "--noinput")
|
||||||
|
|
||||||
# Initialize Django Static Files
|
# Initialize Django Static Files
|
||||||
call_command("collectstatic", "--noinput")
|
collectstatic_output = io.StringIO()
|
||||||
|
with redirect_stdout(collectstatic_output):
|
||||||
|
call_command("collectstatic", "--noinput")
|
||||||
|
|
||||||
# Initialize the Application Server
|
# Initialize the Application Server
|
||||||
app = FastAPI()
|
app = FastAPI()
|
||||||
@@ -45,9 +51,16 @@ app = FastAPI()
|
|||||||
django_app = get_asgi_application()
|
django_app = get_asgi_application()
|
||||||
|
|
||||||
# Add CORS middleware
|
# Add CORS middleware
|
||||||
|
KHOJ_DOMAIN = os.getenv("KHOJ_DOMAIN", "app.khoj.dev")
|
||||||
app.add_middleware(
|
app.add_middleware(
|
||||||
CORSMiddleware,
|
CORSMiddleware,
|
||||||
allow_origins=["app://obsidian.md", "http://localhost:*", "https://app.khoj.dev/*", "app://khoj.dev"],
|
allow_origins=[
|
||||||
|
"app://obsidian.md",
|
||||||
|
"http://localhost:*",
|
||||||
|
"http://127.0.0.1:*",
|
||||||
|
f"https://{KHOJ_DOMAIN}",
|
||||||
|
"app://khoj.dev",
|
||||||
|
],
|
||||||
allow_credentials=True,
|
allow_credentials=True,
|
||||||
allow_methods=["*"],
|
allow_methods=["*"],
|
||||||
allow_headers=["*"],
|
allow_headers=["*"],
|
||||||
@@ -79,14 +92,16 @@ def run(should_start_server=True):
|
|||||||
args = cli(state.cli_args)
|
args = cli(state.cli_args)
|
||||||
set_state(args)
|
set_state(args)
|
||||||
|
|
||||||
logger.info(f"🚒 Initializing Khoj v{state.khoj_version}")
|
|
||||||
|
|
||||||
# Set Logging Level
|
# Set Logging Level
|
||||||
if args.verbose == 0:
|
if args.verbose == 0:
|
||||||
logger.setLevel(logging.INFO)
|
logger.setLevel(logging.INFO)
|
||||||
elif args.verbose >= 1:
|
elif args.verbose >= 1:
|
||||||
logger.setLevel(logging.DEBUG)
|
logger.setLevel(logging.DEBUG)
|
||||||
|
|
||||||
|
logger.info(f"🚒 Initializing Khoj v{state.khoj_version}")
|
||||||
|
logger.info(f"📦 Initializing DB:\n{db_migrate_output.getvalue().strip()}")
|
||||||
|
logger.debug(f"🌍 Initializing Web Client:\n{collectstatic_output.getvalue().strip()}")
|
||||||
|
|
||||||
initialization()
|
initialization()
|
||||||
|
|
||||||
# Create app directory, if it doesn't exist
|
# Create app directory, if it doesn't exist
|
||||||
@@ -107,10 +122,10 @@ def run(should_start_server=True):
|
|||||||
|
|
||||||
# Mount Django and Static Files
|
# Mount Django and Static Files
|
||||||
app.mount("/server", django_app, name="server")
|
app.mount("/server", django_app, name="server")
|
||||||
static_dir = "static"
|
static_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "static")
|
||||||
if not os.path.exists(static_dir):
|
if not os.path.exists(static_dir):
|
||||||
os.mkdir(static_dir)
|
os.mkdir(static_dir)
|
||||||
app.mount(f"/{static_dir}", StaticFiles(directory=static_dir), name=static_dir)
|
app.mount(f"/static", StaticFiles(directory=static_dir), name=static_dir)
|
||||||
|
|
||||||
# Configure Middleware
|
# Configure Middleware
|
||||||
configure_middleware(app)
|
configure_middleware(app)
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ from sentence_transformers import SentenceTransformer, util
|
|||||||
from PIL import Image
|
from PIL import Image
|
||||||
from tqdm import trange
|
from tqdm import trange
|
||||||
import torch
|
import torch
|
||||||
from khoj.utils import state
|
|
||||||
|
|
||||||
# Internal Packages
|
# Internal Packages
|
||||||
from khoj.utils.helpers import get_absolute_path, get_from_dict, resolve_absolute_path, load_model, timer
|
from khoj.utils.helpers import get_absolute_path, get_from_dict, resolve_absolute_path, load_model, timer
|
||||||
@@ -26,9 +25,6 @@ logger = logging.getLogger(__name__)
|
|||||||
|
|
||||||
|
|
||||||
def initialize_model(search_config: ImageSearchConfig):
|
def initialize_model(search_config: ImageSearchConfig):
|
||||||
# Initialize Model
|
|
||||||
torch.set_num_threads(4)
|
|
||||||
|
|
||||||
# Convert model directory to absolute path
|
# Convert model directory to absolute path
|
||||||
search_config.model_directory = resolve_absolute_path(search_config.model_directory)
|
search_config.model_directory = resolve_absolute_path(search_config.model_directory)
|
||||||
|
|
||||||
|
|||||||
@@ -147,6 +147,7 @@ def collate_results(hits, dedupe=True):
|
|||||||
"score": hit.distance,
|
"score": hit.distance,
|
||||||
"corpus_id": str(hit.corpus_id),
|
"corpus_id": str(hit.corpus_id),
|
||||||
"additional": {
|
"additional": {
|
||||||
|
"source": hit.file_source,
|
||||||
"file": hit.file_path,
|
"file": hit.file_path,
|
||||||
"compiled": hit.compiled,
|
"compiled": hit.compiled,
|
||||||
"heading": hit.heading,
|
"heading": hit.heading,
|
||||||
@@ -169,6 +170,7 @@ def deduplicated_search_responses(hits: List[SearchResponse]):
|
|||||||
"score": hit.score,
|
"score": hit.score,
|
||||||
"corpus_id": hit.corpus_id,
|
"corpus_id": hit.corpus_id,
|
||||||
"additional": {
|
"additional": {
|
||||||
|
"source": hit.additional["source"],
|
||||||
"file": hit.additional["file"],
|
"file": hit.additional["file"],
|
||||||
"compiled": hit.additional["compiled"],
|
"compiled": hit.additional["compiled"],
|
||||||
"heading": hit.additional["heading"],
|
"heading": hit.additional["heading"],
|
||||||
|
|||||||
@@ -72,6 +72,9 @@ class ImageSearchConfig(ConfigBase):
|
|||||||
encoder_type: Optional[str] = None
|
encoder_type: Optional[str] = None
|
||||||
model_directory: Optional[Path] = None
|
model_directory: Optional[Path] = None
|
||||||
|
|
||||||
|
class Config:
|
||||||
|
protected_namespaces = ()
|
||||||
|
|
||||||
|
|
||||||
class SearchConfig(ConfigBase):
|
class SearchConfig(ConfigBase):
|
||||||
image: Optional[ImageSearchConfig] = None
|
image: Optional[ImageSearchConfig] = None
|
||||||
|
|||||||
Reference in New Issue
Block a user