mirror of
https://github.com/khoj-ai/khoj.git
synced 2024-11-23 15:38:55 +01:00
Add isort to the pre-commit configuration and apply it to the whole project (#595)
* Apply isort to the entire repository * Fix missing import issues in text_to_entries * Fix imports in migration files
This commit is contained in:
parent
738f050086
commit
79913d4c17
87 changed files with 274 additions and 374 deletions
|
@ -15,6 +15,13 @@ repos:
|
||||||
- id: check-toml
|
- id: check-toml
|
||||||
- id: check-yaml
|
- id: check-yaml
|
||||||
|
|
||||||
|
- repo: https://github.com/pycqa/isort
|
||||||
|
rev: 5.12.0
|
||||||
|
hooks:
|
||||||
|
- id: isort
|
||||||
|
name: isort (python)
|
||||||
|
args: ["--profile", "black", "--filter-files"]
|
||||||
|
|
||||||
- repo: https://github.com/pre-commit/mirrors-mypy
|
- repo: https://github.com/pre-commit/mirrors-mypy
|
||||||
rev: v1.0.0
|
rev: v1.0.0
|
||||||
hooks:
|
hooks:
|
||||||
|
|
|
@ -10,8 +10,8 @@ For the full list of settings and their values, see
|
||||||
https://docs.djangoproject.com/en/4.2/ref/settings/
|
https://docs.djangoproject.com/en/4.2/ref/settings/
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from pathlib import Path
|
|
||||||
import os
|
import os
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
# 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
|
BASE_DIR = Path(__file__).resolve().parent.parent
|
||||||
|
|
|
@ -15,8 +15,8 @@ Including another URLconf
|
||||||
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
|
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
|
||||||
"""
|
"""
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from django.urls import path
|
|
||||||
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
|
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
|
||||||
|
from django.urls import path
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path("admin/", admin.site.urls),
|
path("admin/", admin.site.urls),
|
||||||
|
|
|
@ -1,44 +1,37 @@
|
||||||
# Standard Packages
|
|
||||||
import logging
|
|
||||||
import json
|
import json
|
||||||
|
import logging
|
||||||
|
import os
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
import requests
|
|
||||||
import os
|
|
||||||
|
|
||||||
# External Packages
|
|
||||||
import openai
|
import openai
|
||||||
|
import requests
|
||||||
import schedule
|
import schedule
|
||||||
from starlette.middleware.sessions import SessionMiddleware
|
|
||||||
from starlette.middleware.authentication import AuthenticationMiddleware
|
|
||||||
from starlette.requests import HTTPConnection
|
|
||||||
|
|
||||||
from starlette.authentication import (
|
from starlette.authentication import (
|
||||||
AuthCredentials,
|
AuthCredentials,
|
||||||
AuthenticationBackend,
|
AuthenticationBackend,
|
||||||
SimpleUser,
|
SimpleUser,
|
||||||
UnauthenticatedUser,
|
UnauthenticatedUser,
|
||||||
)
|
)
|
||||||
|
from starlette.middleware.authentication import AuthenticationMiddleware
|
||||||
|
from starlette.middleware.sessions import SessionMiddleware
|
||||||
|
from starlette.requests import HTTPConnection
|
||||||
|
|
||||||
# Internal Packages
|
|
||||||
from khoj.database.models import KhojUser, Subscription
|
|
||||||
from khoj.database.adapters import (
|
from khoj.database.adapters import (
|
||||||
ConversationAdapters,
|
ConversationAdapters,
|
||||||
|
SubscriptionState,
|
||||||
|
aget_user_subscription_state,
|
||||||
get_all_users,
|
get_all_users,
|
||||||
get_or_create_search_models,
|
get_or_create_search_models,
|
||||||
aget_user_subscription_state,
|
|
||||||
SubscriptionState,
|
|
||||||
)
|
)
|
||||||
|
from khoj.database.models import KhojUser, Subscription
|
||||||
from khoj.processor.embeddings import CrossEncoderModel, EmbeddingsModel
|
from khoj.processor.embeddings import CrossEncoderModel, EmbeddingsModel
|
||||||
from khoj.routers.indexer import configure_content, load_content, configure_search
|
from khoj.routers.indexer import configure_content, configure_search, load_content
|
||||||
from khoj.utils import constants, state
|
from khoj.utils import constants, state
|
||||||
from khoj.utils.config import (
|
from khoj.utils.config import SearchType
|
||||||
SearchType,
|
|
||||||
)
|
|
||||||
from khoj.utils.fs_syncer import collect_files
|
from khoj.utils.fs_syncer import collect_files
|
||||||
from khoj.utils.rawconfig import FullConfig
|
from khoj.utils.rawconfig import FullConfig
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
@ -52,7 +45,7 @@ class UserAuthenticationBackend(AuthenticationBackend):
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
):
|
):
|
||||||
from khoj.database.models import KhojUser, KhojApiUser
|
from khoj.database.models import KhojApiUser, KhojUser
|
||||||
|
|
||||||
self.khojuser_manager = KhojUser.objects
|
self.khojuser_manager = KhojUser.objects
|
||||||
self.khojapiuser_manager = KhojApiUser.objects
|
self.khojapiuser_manager = KhojApiUser.objects
|
||||||
|
@ -190,10 +183,10 @@ def configure_routes(app):
|
||||||
# Import APIs here to setup search types before while configuring server
|
# Import APIs here to setup search types before while configuring server
|
||||||
from khoj.routers.api import api
|
from khoj.routers.api import api
|
||||||
from khoj.routers.api_beta import api_beta
|
from khoj.routers.api_beta import api_beta
|
||||||
from khoj.routers.web_client import web_client
|
|
||||||
from khoj.routers.indexer import indexer
|
|
||||||
from khoj.routers.auth import auth_router
|
from khoj.routers.auth import auth_router
|
||||||
|
from khoj.routers.indexer import indexer
|
||||||
from khoj.routers.subscription import subscription_router
|
from khoj.routers.subscription import subscription_router
|
||||||
|
from khoj.routers.web_client import web_client
|
||||||
|
|
||||||
app.include_router(api, prefix="/api")
|
app.include_router(api, prefix="/api")
|
||||||
app.include_router(api_beta, prefix="/api/beta")
|
app.include_router(api_beta, prefix="/api/beta")
|
||||||
|
|
|
@ -2,9 +2,9 @@ import math
|
||||||
import random
|
import random
|
||||||
import secrets
|
import secrets
|
||||||
import sys
|
import sys
|
||||||
from datetime import date, datetime, timezone, timedelta
|
from datetime import date, datetime, timedelta, timezone
|
||||||
from typing import List, Optional, Type
|
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
|
from typing import List, Optional, Type
|
||||||
|
|
||||||
from asgiref.sync import sync_to_async
|
from asgiref.sync import sync_to_async
|
||||||
from django.contrib.sessions.backends.db import SessionStore
|
from django.contrib.sessions.backends.db import SessionStore
|
||||||
|
@ -22,20 +22,18 @@ from khoj.database.models import (
|
||||||
GithubConfig,
|
GithubConfig,
|
||||||
GithubRepoConfig,
|
GithubRepoConfig,
|
||||||
GoogleUser,
|
GoogleUser,
|
||||||
TextToImageModelConfig,
|
|
||||||
KhojApiUser,
|
KhojApiUser,
|
||||||
KhojUser,
|
KhojUser,
|
||||||
NotionConfig,
|
NotionConfig,
|
||||||
OfflineChatProcessorConversationConfig,
|
OfflineChatProcessorConversationConfig,
|
||||||
OpenAIProcessorConversationConfig,
|
OpenAIProcessorConversationConfig,
|
||||||
|
ReflectiveQuestion,
|
||||||
SearchModelConfig,
|
SearchModelConfig,
|
||||||
SpeechToTextModelOptions,
|
SpeechToTextModelOptions,
|
||||||
Subscription,
|
Subscription,
|
||||||
|
TextToImageModelConfig,
|
||||||
UserConversationConfig,
|
UserConversationConfig,
|
||||||
UserSearchModelConfig,
|
UserSearchModelConfig,
|
||||||
OpenAIProcessorConversationConfig,
|
|
||||||
OfflineChatProcessorConversationConfig,
|
|
||||||
ReflectiveQuestion,
|
|
||||||
)
|
)
|
||||||
from khoj.search_filter.date_filter import DateFilter
|
from khoj.search_filter.date_filter import DateFilter
|
||||||
from khoj.search_filter.file_filter import FileFilter
|
from khoj.search_filter.file_filter import FileFilter
|
||||||
|
|
|
@ -5,22 +5,23 @@ from django.contrib import admin
|
||||||
from django.contrib.auth.admin import UserAdmin
|
from django.contrib.auth.admin import UserAdmin
|
||||||
from django.http import HttpResponse
|
from django.http import HttpResponse
|
||||||
|
|
||||||
# Register your models here.
|
|
||||||
|
|
||||||
from khoj.database.models import (
|
from khoj.database.models import (
|
||||||
KhojUser,
|
|
||||||
ChatModelOptions,
|
ChatModelOptions,
|
||||||
OpenAIProcessorConversationConfig,
|
Conversation,
|
||||||
|
KhojUser,
|
||||||
OfflineChatProcessorConversationConfig,
|
OfflineChatProcessorConversationConfig,
|
||||||
|
OpenAIProcessorConversationConfig,
|
||||||
|
ReflectiveQuestion,
|
||||||
SearchModelConfig,
|
SearchModelConfig,
|
||||||
SpeechToTextModelOptions,
|
SpeechToTextModelOptions,
|
||||||
Subscription,
|
Subscription,
|
||||||
ReflectiveQuestion,
|
|
||||||
UserSearchModelConfig,
|
|
||||||
TextToImageModelConfig,
|
TextToImageModelConfig,
|
||||||
Conversation,
|
UserSearchModelConfig,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Register your models here.
|
||||||
|
|
||||||
|
|
||||||
admin.site.register(KhojUser, UserAdmin)
|
admin.site.register(KhojUser, UserAdmin)
|
||||||
|
|
||||||
admin.site.register(ChatModelOptions)
|
admin.site.register(ChatModelOptions)
|
||||||
|
|
|
@ -2,8 +2,8 @@
|
||||||
|
|
||||||
import django.contrib.auth.models
|
import django.contrib.auth.models
|
||||||
import django.contrib.auth.validators
|
import django.contrib.auth.validators
|
||||||
from django.db import migrations, models
|
|
||||||
import django.utils.timezone
|
import django.utils.timezone
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
# Generated by Django 4.2.4 on 2023-09-18 23:24
|
# Generated by Django 4.2.4 on 2023-09-18 23:24
|
||||||
|
|
||||||
|
import django.db.models.deletion
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.db import migrations, models
|
from django.db import migrations, models
|
||||||
import django.db.models.deletion
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
# Generated by Django 4.2.5 on 2023-10-11 22:24
|
# Generated by Django 4.2.5 on 2023-10-11 22:24
|
||||||
|
|
||||||
from django.conf import settings
|
import uuid
|
||||||
from django.db import migrations, models
|
|
||||||
import django.db.models.deletion
|
import django.db.models.deletion
|
||||||
import pgvector.django
|
import pgvector.django
|
||||||
import uuid
|
from django.conf import settings
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
# Generated by Django 4.2.5 on 2023-10-13 02:39
|
# Generated by Django 4.2.5 on 2023-10-13 02:39
|
||||||
|
|
||||||
from django.db import migrations, models
|
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
# Generated by Django 4.2.5 on 2023-10-13 19:28
|
# Generated by Django 4.2.5 on 2023-10-13 19:28
|
||||||
|
|
||||||
from django.db import migrations, models
|
|
||||||
import django.db.models.deletion
|
import django.db.models.deletion
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
# Generated by Django 4.2.5 on 2023-10-18 05:31
|
# Generated by Django 4.2.5 on 2023-10-18 05:31
|
||||||
|
|
||||||
|
import django.db.models.deletion
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.db import migrations, models
|
from django.db import migrations, models
|
||||||
import django.db.models.deletion
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
# Generated by Django 4.2.5 on 2023-10-26 17:02
|
# Generated by Django 4.2.5 on 2023-10-26 17:02
|
||||||
|
|
||||||
|
import django.db.models.deletion
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.db import migrations, models
|
from django.db import migrations, models
|
||||||
import django.db.models.deletion
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
# Generated by Django 4.2.4 on 2023-11-01 17:41
|
# Generated by Django 4.2.4 on 2023-11-01 17:41
|
||||||
|
|
||||||
|
import django.db.models.deletion
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.db import migrations, models
|
from django.db import migrations, models
|
||||||
import django.db.models.deletion
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
# Generated by Django 4.2.5 on 2023-11-02 01:38
|
# Generated by Django 4.2.5 on 2023-11-02 01:38
|
||||||
|
|
||||||
from django.db import migrations
|
from typing import Any, List
|
||||||
|
|
||||||
from typing import List, Any
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
# Generated by Django 4.2.5 on 2023-11-09 01:27
|
# Generated by Django 4.2.5 on 2023-11-09 01:27
|
||||||
|
|
||||||
|
import django.db.models.deletion
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.db import migrations, models
|
from django.db import migrations, models
|
||||||
import django.db.models.deletion
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
# Generated by Django 4.2.5 on 2023-11-11 05:39
|
# Generated by Django 4.2.5 on 2023-11-11 05:39
|
||||||
|
|
||||||
|
import django.db.models.deletion
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.db import migrations, models
|
from django.db import migrations, models
|
||||||
import django.db.models.deletion
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
# Generated by Django 4.2.7 on 2023-11-20 01:13
|
# Generated by Django 4.2.7 on 2023-11-20 01:13
|
||||||
|
|
||||||
|
import django.db.models.deletion
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.db import migrations, models
|
from django.db import migrations, models
|
||||||
import django.db.models.deletion
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
# Generated by Django 4.2.7 on 2023-12-19 15:44
|
# Generated by Django 4.2.7 on 2023-12-19 15:44
|
||||||
|
|
||||||
|
import django.db.models.deletion
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.db import migrations, models
|
from django.db import migrations, models
|
||||||
import django.db.models.deletion
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
# Generated by Django 4.2.7 on 2023-12-20 07:27
|
# Generated by Django 4.2.7 on 2023-12-20 07:27
|
||||||
|
|
||||||
from django.db import migrations
|
|
||||||
import pgvector.django
|
import pgvector.django
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from django.db import models
|
|
||||||
from django.contrib.auth.models import AbstractUser
|
from django.contrib.auth.models import AbstractUser
|
||||||
|
from django.db import models
|
||||||
from pgvector.django import VectorField
|
from pgvector.django import VectorField
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
isort:skip_file
|
isort:skip_file
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# Standard Packages
|
|
||||||
from contextlib import redirect_stdout
|
from contextlib import redirect_stdout
|
||||||
import io
|
import io
|
||||||
import os
|
import os
|
||||||
|
@ -18,7 +18,7 @@ from importlib.metadata import version
|
||||||
warnings.filterwarnings("ignore", message=r"snapshot_download.py has been made private", category=FutureWarning)
|
warnings.filterwarnings("ignore", message=r"snapshot_download.py has been made private", category=FutureWarning)
|
||||||
warnings.filterwarnings("ignore", message=r"legacy way to download files from the HF hub,", category=FutureWarning)
|
warnings.filterwarnings("ignore", message=r"legacy way to download files from the HF hub,", category=FutureWarning)
|
||||||
|
|
||||||
# External Packages
|
|
||||||
import uvicorn
|
import uvicorn
|
||||||
import django
|
import django
|
||||||
from fastapi import FastAPI
|
from fastapi import FastAPI
|
||||||
|
@ -69,7 +69,7 @@ app.add_middleware(
|
||||||
# Set Locale
|
# Set Locale
|
||||||
locale.setlocale(locale.LC_ALL, "")
|
locale.setlocale(locale.LC_ALL, "")
|
||||||
|
|
||||||
# Internal Packages. We do this after setting up Django so that Django features are accessible to the app.
|
# We import these packages after setting up Django so that Django features are accessible to the app.
|
||||||
from khoj.configure import configure_routes, initialize_server, configure_middleware
|
from khoj.configure import configure_routes, initialize_server, configure_middleware
|
||||||
from khoj.utils import state
|
from khoj.utils import state
|
||||||
from khoj.utils.cli import cli
|
from khoj.utils.cli import cli
|
||||||
|
|
|
@ -30,11 +30,11 @@ search-type:
|
||||||
...
|
...
|
||||||
"""
|
"""
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from packaging import version
|
from packaging import version
|
||||||
|
|
||||||
from khoj.utils.yaml import load_config_from_file, save_config_to_file
|
from khoj.utils.yaml import load_config_from_file, save_config_to_file
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -34,11 +34,11 @@ search-type:
|
||||||
...
|
...
|
||||||
"""
|
"""
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from packaging import version
|
from packaging import version
|
||||||
|
|
||||||
from khoj.utils.yaml import load_config_from_file, save_config_to_file
|
from khoj.utils.yaml import load_config_from_file, save_config_to_file
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import os
|
|
||||||
import logging
|
import logging
|
||||||
|
import os
|
||||||
|
|
||||||
from packaging import version
|
from packaging import version
|
||||||
|
|
||||||
from khoj.utils.yaml import load_config_from_file, save_config_to_file
|
from khoj.utils.yaml import load_config_from_file, save_config_to_file
|
||||||
|
|
|
@ -57,15 +57,16 @@ version: 0.15.0
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from packaging import version
|
from packaging import version
|
||||||
|
|
||||||
from khoj.utils.yaml import load_config_from_file, save_config_to_file
|
|
||||||
from khoj.database.models import (
|
from khoj.database.models import (
|
||||||
OpenAIProcessorConversationConfig,
|
|
||||||
OfflineChatProcessorConversationConfig,
|
|
||||||
ChatModelOptions,
|
ChatModelOptions,
|
||||||
|
OfflineChatProcessorConversationConfig,
|
||||||
|
OpenAIProcessorConversationConfig,
|
||||||
SearchModelConfig,
|
SearchModelConfig,
|
||||||
)
|
)
|
||||||
|
from khoj.utils.yaml import load_config_from_file, save_config_to_file
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,8 @@
|
||||||
# Standard Packages
|
|
||||||
import logging
|
import logging
|
||||||
import time
|
import time
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from typing import Dict, List, Tuple, Union
|
from typing import Dict, List, Tuple, Union
|
||||||
|
|
||||||
# External Packages
|
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
from khoj.database.models import Entry as DbEntry
|
from khoj.database.models import Entry as DbEntry
|
||||||
|
@ -12,8 +10,6 @@ from khoj.database.models import GithubConfig, KhojUser
|
||||||
from khoj.processor.content.markdown.markdown_to_entries import MarkdownToEntries
|
from khoj.processor.content.markdown.markdown_to_entries import MarkdownToEntries
|
||||||
from khoj.processor.content.org_mode.org_to_entries import OrgToEntries
|
from khoj.processor.content.org_mode.org_to_entries import OrgToEntries
|
||||||
from khoj.processor.content.text_to_entries import TextToEntries
|
from khoj.processor.content.text_to_entries import TextToEntries
|
||||||
|
|
||||||
# Internal Packages
|
|
||||||
from khoj.utils.helpers import timer
|
from khoj.utils.helpers import timer
|
||||||
from khoj.utils.rawconfig import Entry, GithubContentConfig, GithubRepoConfig
|
from khoj.utils.rawconfig import Entry, GithubContentConfig, GithubRepoConfig
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
# Standard Packages
|
|
||||||
import logging
|
import logging
|
||||||
import re
|
import re
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
@ -8,8 +7,6 @@ import urllib3
|
||||||
|
|
||||||
from khoj.database.models import Entry as DbEntry
|
from khoj.database.models import Entry as DbEntry
|
||||||
from khoj.database.models import KhojUser
|
from khoj.database.models import KhojUser
|
||||||
|
|
||||||
# Internal Packages
|
|
||||||
from khoj.processor.content.text_to_entries import TextToEntries
|
from khoj.processor.content.text_to_entries import TextToEntries
|
||||||
from khoj.utils.constants import empty_escape_sequences
|
from khoj.utils.constants import empty_escape_sequences
|
||||||
from khoj.utils.helpers import timer
|
from khoj.utils.helpers import timer
|
||||||
|
|
|
@ -1,16 +1,12 @@
|
||||||
# Standard Packages
|
|
||||||
import logging
|
import logging
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
from typing import Tuple
|
from typing import Tuple
|
||||||
|
|
||||||
# External Packages
|
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
from khoj.database.models import Entry as DbEntry
|
from khoj.database.models import Entry as DbEntry
|
||||||
from khoj.database.models import KhojUser, NotionConfig
|
from khoj.database.models import KhojUser, NotionConfig
|
||||||
from khoj.processor.content.text_to_entries import TextToEntries
|
from khoj.processor.content.text_to_entries import TextToEntries
|
||||||
|
|
||||||
# Internal Packages
|
|
||||||
from khoj.utils.helpers import timer
|
from khoj.utils.helpers import timer
|
||||||
from khoj.utils.rawconfig import Entry, NotionContentConfig
|
from khoj.utils.rawconfig import Entry, NotionContentConfig
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,9 @@
|
||||||
# Standard Packages
|
|
||||||
import logging
|
import logging
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Iterable, List, Tuple
|
from typing import Iterable, List, Tuple
|
||||||
|
|
||||||
from khoj.database.models import Entry as DbEntry
|
from khoj.database.models import Entry as DbEntry
|
||||||
from khoj.database.models import KhojUser
|
from khoj.database.models import KhojUser
|
||||||
|
|
||||||
# Internal Packages
|
|
||||||
from khoj.processor.content.org_mode import orgnode
|
from khoj.processor.content.org_mode import orgnode
|
||||||
from khoj.processor.content.text_to_entries import TextToEntries
|
from khoj.processor.content.text_to_entries import TextToEntries
|
||||||
from khoj.utils import state
|
from khoj.utils import state
|
||||||
|
|
|
@ -33,10 +33,10 @@ headline and associated text from an org-mode file, and routines for
|
||||||
constructing data structures of these classes.
|
constructing data structures of these classes.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import re
|
|
||||||
import datetime
|
import datetime
|
||||||
from pathlib import Path
|
import re
|
||||||
from os.path import relpath
|
from os.path import relpath
|
||||||
|
from pathlib import Path
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
indent_regex = re.compile(r"^ *")
|
indent_regex = re.compile(r"^ *")
|
||||||
|
|
|
@ -1,17 +1,13 @@
|
||||||
# Standard Packages
|
|
||||||
import base64
|
import base64
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
from typing import List, Tuple
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
from typing import List, Tuple
|
||||||
|
|
||||||
# External Packages
|
|
||||||
from langchain.document_loaders import PyMuPDFLoader
|
from langchain.document_loaders import PyMuPDFLoader
|
||||||
|
|
||||||
from khoj.database.models import Entry as DbEntry
|
from khoj.database.models import Entry as DbEntry
|
||||||
from khoj.database.models import KhojUser
|
from khoj.database.models import KhojUser
|
||||||
|
|
||||||
# Internal Packages
|
|
||||||
from khoj.processor.content.text_to_entries import TextToEntries
|
from khoj.processor.content.text_to_entries import TextToEntries
|
||||||
from khoj.utils.helpers import timer
|
from khoj.utils.helpers import timer
|
||||||
from khoj.utils.rawconfig import Entry
|
from khoj.utils.rawconfig import Entry
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
# Standard Packages
|
|
||||||
import logging
|
import logging
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import List, Tuple
|
from typing import List, Tuple
|
||||||
|
@ -7,8 +6,6 @@ from bs4 import BeautifulSoup
|
||||||
|
|
||||||
from khoj.database.models import Entry as DbEntry
|
from khoj.database.models import Entry as DbEntry
|
||||||
from khoj.database.models import KhojUser
|
from khoj.database.models import KhojUser
|
||||||
|
|
||||||
# Internal Packages
|
|
||||||
from khoj.processor.content.text_to_entries import TextToEntries
|
from khoj.processor.content.text_to_entries import TextToEntries
|
||||||
from khoj.utils.helpers import timer
|
from khoj.utils.helpers import timer
|
||||||
from khoj.utils.rawconfig import Entry
|
from khoj.utils.rawconfig import Entry
|
||||||
|
|
|
@ -1,21 +1,19 @@
|
||||||
# Standard Packages
|
|
||||||
from abc import ABC, abstractmethod
|
|
||||||
import hashlib
|
import hashlib
|
||||||
from itertools import repeat
|
|
||||||
import logging
|
import logging
|
||||||
import uuid
|
import uuid
|
||||||
|
from abc import ABC, abstractmethod
|
||||||
|
from itertools import repeat
|
||||||
|
from typing import Any, Callable, List, Set, Tuple
|
||||||
|
|
||||||
from tqdm import tqdm
|
from tqdm import tqdm
|
||||||
from typing import Callable, List, Tuple, Set, Any
|
|
||||||
from khoj.utils import state
|
|
||||||
from khoj.utils.helpers import is_none_or_empty, timer, batcher
|
|
||||||
|
|
||||||
|
|
||||||
# Internal Packages
|
|
||||||
from khoj.utils.rawconfig import Entry
|
|
||||||
from khoj.search_filter.date_filter import DateFilter
|
|
||||||
from khoj.database.models import KhojUser, Entry as DbEntry, EntryDates
|
|
||||||
from khoj.database.adapters import EntryAdapters, get_user_search_model_or_default
|
from khoj.database.adapters import EntryAdapters, get_user_search_model_or_default
|
||||||
|
from khoj.database.models import Entry as DbEntry
|
||||||
|
from khoj.database.models import EntryDates, KhojUser
|
||||||
|
from khoj.search_filter.date_filter import DateFilter
|
||||||
|
from khoj.utils import state
|
||||||
|
from khoj.utils.helpers import batcher, is_none_or_empty, timer
|
||||||
|
from khoj.utils.rawconfig import Entry
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
|
@ -1,14 +1,17 @@
|
||||||
from typing import Iterator, Union, List, Any
|
|
||||||
from datetime import datetime
|
|
||||||
import logging
|
import logging
|
||||||
|
from datetime import datetime
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
|
from typing import Any, Iterator, List, Union
|
||||||
|
|
||||||
from langchain.schema import ChatMessage
|
from langchain.schema import ChatMessage
|
||||||
|
|
||||||
from khoj.processor.conversation.utils import ThreadedGenerator, generate_chatml_messages_with_context
|
|
||||||
from khoj.processor.conversation import prompts
|
from khoj.processor.conversation import prompts
|
||||||
from khoj.utils.constants import empty_escape_sequences
|
from khoj.processor.conversation.utils import (
|
||||||
|
ThreadedGenerator,
|
||||||
|
generate_chatml_messages_with_context,
|
||||||
|
)
|
||||||
from khoj.utils import state
|
from khoj.utils import state
|
||||||
|
from khoj.utils.constants import empty_escape_sequences
|
||||||
from khoj.utils.helpers import ConversationCommand, is_none_or_empty
|
from khoj.utils.helpers import ConversationCommand, is_none_or_empty
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
# External Packages
|
|
||||||
from asgiref.sync import sync_to_async
|
|
||||||
import whisper
|
import whisper
|
||||||
|
from asgiref.sync import sync_to_async
|
||||||
|
|
||||||
# Internal Packages
|
|
||||||
from khoj.utils import state
|
from khoj.utils import state
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,23 +1,19 @@
|
||||||
# Standard Packages
|
|
||||||
import logging
|
|
||||||
import json
|
import json
|
||||||
|
import logging
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
# External Packages
|
|
||||||
from langchain.schema import ChatMessage
|
from langchain.schema import ChatMessage
|
||||||
|
|
||||||
# Internal Packages
|
|
||||||
from khoj.utils.constants import empty_escape_sequences
|
|
||||||
from khoj.processor.conversation import prompts
|
from khoj.processor.conversation import prompts
|
||||||
from khoj.processor.conversation.openai.utils import (
|
from khoj.processor.conversation.openai.utils import (
|
||||||
chat_completion_with_backoff,
|
chat_completion_with_backoff,
|
||||||
completion_with_backoff,
|
completion_with_backoff,
|
||||||
)
|
)
|
||||||
from khoj.processor.conversation.utils import generate_chatml_messages_with_context
|
from khoj.processor.conversation.utils import generate_chatml_messages_with_context
|
||||||
|
from khoj.utils.constants import empty_escape_sequences
|
||||||
from khoj.utils.helpers import ConversationCommand, is_none_or_empty
|
from khoj.utils.helpers import ConversationCommand, is_none_or_empty
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,14 +1,12 @@
|
||||||
# Standard Packages
|
|
||||||
import os
|
|
||||||
import logging
|
import logging
|
||||||
from typing import Any
|
import os
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
# External Packages
|
|
||||||
from langchain.chat_models import ChatOpenAI
|
|
||||||
from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler
|
|
||||||
from langchain.callbacks.base import BaseCallbackManager
|
|
||||||
import openai
|
import openai
|
||||||
|
from langchain.callbacks.base import BaseCallbackManager
|
||||||
|
from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler
|
||||||
|
from langchain.chat_models import ChatOpenAI
|
||||||
from tenacity import (
|
from tenacity import (
|
||||||
before_sleep_log,
|
before_sleep_log,
|
||||||
retry,
|
retry,
|
||||||
|
@ -18,10 +16,8 @@ from tenacity import (
|
||||||
wait_random_exponential,
|
wait_random_exponential,
|
||||||
)
|
)
|
||||||
|
|
||||||
# Internal Packages
|
|
||||||
from khoj.processor.conversation.utils import ThreadedGenerator
|
from khoj.processor.conversation.utils import ThreadedGenerator
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
# Standard Packages
|
|
||||||
from io import BufferedReader
|
from io import BufferedReader
|
||||||
|
|
||||||
# External Packages
|
|
||||||
from asgiref.sync import sync_to_async
|
from asgiref.sync import sync_to_async
|
||||||
from openai import OpenAI
|
from openai import OpenAI
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
# External Packages
|
|
||||||
from langchain.prompts import PromptTemplate
|
from langchain.prompts import PromptTemplate
|
||||||
|
|
||||||
|
|
||||||
## Personality
|
## Personality
|
||||||
## --
|
## --
|
||||||
personality = PromptTemplate.from_template(
|
personality = PromptTemplate.from_template(
|
||||||
|
|
|
@ -1,22 +1,18 @@
|
||||||
# Standard Packages
|
|
||||||
import logging
|
|
||||||
from time import perf_counter
|
|
||||||
import json
|
import json
|
||||||
from datetime import datetime
|
import logging
|
||||||
import queue
|
import queue
|
||||||
|
from datetime import datetime
|
||||||
|
from time import perf_counter
|
||||||
from typing import Any, Dict, List
|
from typing import Any, Dict, List
|
||||||
import tiktoken
|
|
||||||
|
|
||||||
# External packages
|
import tiktoken
|
||||||
from langchain.schema import ChatMessage
|
from langchain.schema import ChatMessage
|
||||||
from transformers import AutoTokenizer
|
from transformers import AutoTokenizer
|
||||||
|
|
||||||
# Internal Packages
|
|
||||||
from khoj.database.adapters import ConversationAdapters
|
from khoj.database.adapters import ConversationAdapters
|
||||||
from khoj.database.models import KhojUser
|
from khoj.database.models import KhojUser
|
||||||
from khoj.utils.helpers import merge_dicts
|
from khoj.utils.helpers import merge_dicts
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
model_to_prompt_size = {
|
model_to_prompt_size = {
|
||||||
"gpt-3.5-turbo": 4096,
|
"gpt-3.5-turbo": 4096,
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
from sentence_transformers import SentenceTransformer, CrossEncoder
|
from sentence_transformers import CrossEncoder, SentenceTransformer
|
||||||
from torch import nn
|
from torch import nn
|
||||||
|
|
||||||
from khoj.utils.helpers import get_device
|
from khoj.utils.helpers import get_device
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
import requests
|
|
||||||
import json
|
import json
|
||||||
import os
|
|
||||||
import logging
|
import logging
|
||||||
|
import os
|
||||||
|
|
||||||
|
import requests
|
||||||
|
|
||||||
from khoj.routers.helpers import generate_online_subqueries
|
from khoj.routers.helpers import generate_online_subqueries
|
||||||
|
|
||||||
|
|
|
@ -1,25 +1,26 @@
|
||||||
# Standard Packages
|
|
||||||
import concurrent.futures
|
import concurrent.futures
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
import math
|
import math
|
||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
from typing import Any, Dict, List, Optional, Union
|
|
||||||
import uuid
|
import uuid
|
||||||
|
from typing import Any, Dict, List, Optional, Union
|
||||||
|
|
||||||
# External Packages
|
|
||||||
from fastapi import APIRouter, Depends, File, HTTPException, Request, UploadFile
|
|
||||||
from asgiref.sync import sync_to_async
|
from asgiref.sync import sync_to_async
|
||||||
|
from fastapi import APIRouter, Depends, File, HTTPException, Request, UploadFile
|
||||||
from fastapi.requests import Request
|
from fastapi.requests import Request
|
||||||
from fastapi.responses import Response, StreamingResponse
|
from fastapi.responses import Response, StreamingResponse
|
||||||
from starlette.authentication import requires
|
from starlette.authentication import requires
|
||||||
|
|
||||||
# Internal Packages
|
|
||||||
from khoj.configure import configure_server
|
from khoj.configure import configure_server
|
||||||
from khoj.database import adapters
|
from khoj.database import adapters
|
||||||
from khoj.database.adapters import ConversationAdapters, EntryAdapters, get_user_search_model_or_default
|
from khoj.database.adapters import (
|
||||||
from khoj.database.models import ChatModelOptions, SpeechToTextModelOptions
|
ConversationAdapters,
|
||||||
|
EntryAdapters,
|
||||||
|
get_user_search_model_or_default,
|
||||||
|
)
|
||||||
|
from khoj.database.models import ChatModelOptions
|
||||||
from khoj.database.models import Entry as DbEntry
|
from khoj.database.models import Entry as DbEntry
|
||||||
from khoj.database.models import (
|
from khoj.database.models import (
|
||||||
GithubConfig,
|
GithubConfig,
|
||||||
|
@ -29,6 +30,7 @@ from khoj.database.models import (
|
||||||
LocalPdfConfig,
|
LocalPdfConfig,
|
||||||
LocalPlaintextConfig,
|
LocalPlaintextConfig,
|
||||||
NotionConfig,
|
NotionConfig,
|
||||||
|
SpeechToTextModelOptions,
|
||||||
)
|
)
|
||||||
from khoj.processor.conversation.offline.chat_model import extract_questions_offline
|
from khoj.processor.conversation.offline.chat_model import extract_questions_offline
|
||||||
from khoj.processor.conversation.offline.whisper import transcribe_audio_offline
|
from khoj.processor.conversation.offline.whisper import transcribe_audio_offline
|
||||||
|
@ -40,13 +42,13 @@ from khoj.processor.tools.online_search import search_with_google
|
||||||
from khoj.routers.helpers import (
|
from khoj.routers.helpers import (
|
||||||
ApiUserRateLimiter,
|
ApiUserRateLimiter,
|
||||||
CommonQueryParams,
|
CommonQueryParams,
|
||||||
|
ConversationCommandRateLimiter,
|
||||||
agenerate_chat_response,
|
agenerate_chat_response,
|
||||||
get_conversation_command,
|
get_conversation_command,
|
||||||
text_to_image,
|
|
||||||
is_ready_to_chat,
|
is_ready_to_chat,
|
||||||
|
text_to_image,
|
||||||
update_telemetry_state,
|
update_telemetry_state,
|
||||||
validate_conversation_config,
|
validate_conversation_config,
|
||||||
ConversationCommandRateLimiter,
|
|
||||||
)
|
)
|
||||||
from khoj.search_filter.date_filter import DateFilter
|
from khoj.search_filter.date_filter import DateFilter
|
||||||
from khoj.search_filter.file_filter import FileFilter
|
from khoj.search_filter.file_filter import FileFilter
|
||||||
|
@ -62,7 +64,13 @@ from khoj.utils.helpers import (
|
||||||
is_none_or_empty,
|
is_none_or_empty,
|
||||||
timer,
|
timer,
|
||||||
)
|
)
|
||||||
from khoj.utils.rawconfig import FullConfig, GithubContentConfig, NotionContentConfig, SearchConfig, SearchResponse
|
from khoj.utils.rawconfig import (
|
||||||
|
FullConfig,
|
||||||
|
GithubContentConfig,
|
||||||
|
NotionContentConfig,
|
||||||
|
SearchConfig,
|
||||||
|
SearchResponse,
|
||||||
|
)
|
||||||
from khoj.utils.state import SearchType
|
from khoj.utils.state import SearchType
|
||||||
|
|
||||||
# Initialize Router
|
# Initialize Router
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
# Standard Packages
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
# External Packages
|
|
||||||
from fastapi import APIRouter
|
from fastapi import APIRouter
|
||||||
|
|
||||||
# Initialize Router
|
# Initialize Router
|
||||||
|
|
|
@ -1,26 +1,26 @@
|
||||||
# Standard Packages
|
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
# External Packages
|
from authlib.integrations.starlette_client import OAuth, OAuthError
|
||||||
from fastapi import APIRouter
|
from fastapi import APIRouter
|
||||||
|
from google.auth.transport import requests as google_requests
|
||||||
|
from google.oauth2 import id_token
|
||||||
|
from starlette.authentication import requires
|
||||||
from starlette.config import Config
|
from starlette.config import Config
|
||||||
from starlette.requests import Request
|
from starlette.requests import Request
|
||||||
from starlette.responses import HTMLResponse, RedirectResponse, Response
|
from starlette.responses import HTMLResponse, RedirectResponse, Response
|
||||||
from starlette.authentication import requires
|
|
||||||
from authlib.integrations.starlette_client import OAuth, OAuthError
|
|
||||||
|
|
||||||
from google.oauth2 import id_token
|
from khoj.database.adapters import (
|
||||||
from google.auth.transport import requests as google_requests
|
create_khoj_token,
|
||||||
|
delete_khoj_token,
|
||||||
# Internal Packages
|
get_khoj_tokens,
|
||||||
from khoj.database.adapters import get_khoj_tokens, get_or_create_user, create_khoj_token, delete_khoj_token
|
get_or_create_user,
|
||||||
|
)
|
||||||
from khoj.database.models import KhojApiUser
|
from khoj.database.models import KhojApiUser
|
||||||
from khoj.routers.helpers import update_telemetry_state
|
from khoj.routers.helpers import update_telemetry_state
|
||||||
from khoj.utils import state
|
from khoj.utils import state
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
auth_router = APIRouter()
|
auth_router = APIRouter()
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
# Standard Packages
|
|
||||||
import asyncio
|
import asyncio
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
|
@ -9,23 +8,26 @@ from functools import partial
|
||||||
from time import time
|
from time import time
|
||||||
from typing import Annotated, Any, Dict, Iterator, List, Optional, Tuple, Union
|
from typing import Annotated, Any, Dict, Iterator, List, Optional, Tuple, Union
|
||||||
|
|
||||||
# External Packages
|
|
||||||
from fastapi import Depends, Header, HTTPException, Request, UploadFile
|
|
||||||
import openai
|
import openai
|
||||||
|
from fastapi import Depends, Header, HTTPException, Request, UploadFile
|
||||||
from starlette.authentication import has_required_scope
|
from starlette.authentication import has_required_scope
|
||||||
|
|
||||||
# Internal Packages
|
|
||||||
from khoj.database.adapters import ConversationAdapters, EntryAdapters
|
from khoj.database.adapters import ConversationAdapters, EntryAdapters
|
||||||
from khoj.database.models import KhojUser, Subscription, TextToImageModelConfig
|
from khoj.database.models import KhojUser, Subscription, TextToImageModelConfig
|
||||||
from khoj.processor.conversation import prompts
|
from khoj.processor.conversation import prompts
|
||||||
from khoj.processor.conversation.offline.chat_model import converse_offline, send_message_to_model_offline
|
from khoj.processor.conversation.offline.chat_model import (
|
||||||
|
converse_offline,
|
||||||
|
send_message_to_model_offline,
|
||||||
|
)
|
||||||
from khoj.processor.conversation.openai.gpt import converse, send_message_to_model
|
from khoj.processor.conversation.openai.gpt import converse, send_message_to_model
|
||||||
from khoj.processor.conversation.utils import ThreadedGenerator, save_to_conversation_log
|
from khoj.processor.conversation.utils import (
|
||||||
|
ThreadedGenerator,
|
||||||
|
save_to_conversation_log,
|
||||||
|
)
|
||||||
from khoj.utils import state
|
from khoj.utils import state
|
||||||
from khoj.utils.config import GPT4AllProcessorModel
|
from khoj.utils.config import GPT4AllProcessorModel
|
||||||
from khoj.utils.helpers import ConversationCommand, log_telemetry
|
from khoj.utils.helpers import ConversationCommand, log_telemetry
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
executor = ThreadPoolExecutor(max_workers=1)
|
executor = ThreadPoolExecutor(max_workers=1)
|
||||||
|
|
|
@ -2,7 +2,7 @@ import asyncio
|
||||||
import logging
|
import logging
|
||||||
from typing import Dict, Optional, Union
|
from typing import Dict, Optional, Union
|
||||||
|
|
||||||
from fastapi import APIRouter, Header, Request, Response, UploadFile, Depends
|
from fastapi import APIRouter, Depends, Header, Request, Response, UploadFile
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
from starlette.authentication import requires
|
from starlette.authentication import requires
|
||||||
|
|
||||||
|
@ -13,12 +13,11 @@ from khoj.processor.content.notion.notion_to_entries import NotionToEntries
|
||||||
from khoj.processor.content.org_mode.org_to_entries import OrgToEntries
|
from khoj.processor.content.org_mode.org_to_entries import OrgToEntries
|
||||||
from khoj.processor.content.pdf.pdf_to_entries import PdfToEntries
|
from khoj.processor.content.pdf.pdf_to_entries import PdfToEntries
|
||||||
from khoj.processor.content.plaintext.plaintext_to_entries import PlaintextToEntries
|
from khoj.processor.content.plaintext.plaintext_to_entries import PlaintextToEntries
|
||||||
from khoj.routers.helpers import update_telemetry_state
|
from khoj.routers.helpers import ApiIndexedDataLimiter, update_telemetry_state
|
||||||
from khoj.search_type import image_search, text_search
|
from khoj.search_type import image_search, text_search
|
||||||
from khoj.utils import constants, state
|
from khoj.utils import constants, state
|
||||||
from khoj.utils.config import ContentIndex, SearchModels
|
from khoj.utils.config import ContentIndex, SearchModels
|
||||||
from khoj.utils.helpers import LRU, get_file_type
|
from khoj.utils.helpers import LRU, get_file_type
|
||||||
from khoj.routers.helpers import ApiIndexedDataLimiter
|
|
||||||
from khoj.utils.rawconfig import ContentConfig, FullConfig, SearchConfig
|
from khoj.utils.rawconfig import ContentConfig, FullConfig, SearchConfig
|
||||||
from khoj.utils.yaml import save_config_to_file_updated_state
|
from khoj.utils.yaml import save_config_to_file_updated_state
|
||||||
|
|
||||||
|
|
|
@ -1,18 +1,14 @@
|
||||||
# Standard Packages
|
|
||||||
from datetime import datetime, timezone
|
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
from datetime import datetime, timezone
|
||||||
|
|
||||||
# External Packages
|
import stripe
|
||||||
from asgiref.sync import sync_to_async
|
from asgiref.sync import sync_to_async
|
||||||
from fastapi import APIRouter, Request
|
from fastapi import APIRouter, Request
|
||||||
from starlette.authentication import requires
|
from starlette.authentication import requires
|
||||||
import stripe
|
|
||||||
|
|
||||||
# Internal Packages
|
|
||||||
from khoj.database import adapters
|
from khoj.database import adapters
|
||||||
|
|
||||||
|
|
||||||
# Stripe integration for Khoj Cloud Subscription
|
# Stripe integration for Khoj Cloud Subscription
|
||||||
stripe.api_key = os.getenv("STRIPE_API_KEY")
|
stripe.api_key = os.getenv("STRIPE_API_KEY")
|
||||||
endpoint_secret = os.getenv("STRIPE_SIGNING_SECRET")
|
endpoint_secret = os.getenv("STRIPE_SIGNING_SECRET")
|
||||||
|
|
|
@ -1,33 +1,30 @@
|
||||||
# System Packages
|
# System Packages
|
||||||
import json
|
import json
|
||||||
import os
|
|
||||||
import math
|
import math
|
||||||
|
import os
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
|
||||||
# External Packages
|
from fastapi import APIRouter, Request
|
||||||
from fastapi import APIRouter
|
from fastapi.responses import FileResponse, HTMLResponse, RedirectResponse
|
||||||
from fastapi import Request
|
|
||||||
from fastapi.responses import HTMLResponse, FileResponse, RedirectResponse
|
|
||||||
from fastapi.templating import Jinja2Templates
|
from fastapi.templating import Jinja2Templates
|
||||||
from starlette.authentication import requires, has_required_scope
|
from starlette.authentication import has_required_scope, requires
|
||||||
|
|
||||||
from khoj.database import adapters
|
from khoj.database import adapters
|
||||||
|
from khoj.database.adapters import (
|
||||||
|
ConversationAdapters,
|
||||||
|
EntryAdapters,
|
||||||
|
get_user_github_config,
|
||||||
|
get_user_notion_config,
|
||||||
|
get_user_subscription_state,
|
||||||
|
)
|
||||||
from khoj.database.models import KhojUser
|
from khoj.database.models import KhojUser
|
||||||
|
from khoj.utils import constants, state
|
||||||
from khoj.utils.rawconfig import (
|
from khoj.utils.rawconfig import (
|
||||||
GithubContentConfig,
|
GithubContentConfig,
|
||||||
GithubRepoConfig,
|
GithubRepoConfig,
|
||||||
NotionContentConfig,
|
NotionContentConfig,
|
||||||
)
|
)
|
||||||
|
|
||||||
# Internal Packages
|
|
||||||
from khoj.utils import constants, state
|
|
||||||
from khoj.database.adapters import (
|
|
||||||
EntryAdapters,
|
|
||||||
get_user_github_config,
|
|
||||||
get_user_notion_config,
|
|
||||||
ConversationAdapters,
|
|
||||||
get_user_subscription_state,
|
|
||||||
)
|
|
||||||
|
|
||||||
# Initialize Router
|
# Initialize Router
|
||||||
web_client = APIRouter()
|
web_client = APIRouter()
|
||||||
templates = Jinja2Templates(directory=constants.web_directory)
|
templates = Jinja2Templates(directory=constants.web_directory)
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
# Standard Packages
|
|
||||||
from abc import ABC, abstractmethod
|
from abc import ABC, abstractmethod
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
|
|
|
@ -1,20 +1,16 @@
|
||||||
# Standard Packages
|
|
||||||
import re
|
|
||||||
import logging
|
import logging
|
||||||
|
import re
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from datetime import timedelta, datetime
|
from datetime import datetime, timedelta
|
||||||
from typing import List
|
|
||||||
from dateutil.relativedelta import relativedelta
|
|
||||||
from math import inf
|
from math import inf
|
||||||
|
from typing import List
|
||||||
|
|
||||||
# External Packages
|
|
||||||
import dateparser as dtparse
|
import dateparser as dtparse
|
||||||
|
from dateutil.relativedelta import relativedelta
|
||||||
|
|
||||||
# Internal Packages
|
|
||||||
from khoj.search_filter.base_filter import BaseFilter
|
from khoj.search_filter.base_filter import BaseFilter
|
||||||
from khoj.utils.helpers import LRU, timer
|
from khoj.utils.helpers import LRU, timer
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,15 +1,12 @@
|
||||||
# Standard Packages
|
|
||||||
import re
|
|
||||||
import fnmatch
|
import fnmatch
|
||||||
import logging
|
import logging
|
||||||
|
import re
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
# Internal Packages
|
|
||||||
from khoj.search_filter.base_filter import BaseFilter
|
from khoj.search_filter.base_filter import BaseFilter
|
||||||
from khoj.utils.helpers import LRU, timer
|
from khoj.utils.helpers import LRU, timer
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,14 +1,11 @@
|
||||||
# Standard Packages
|
|
||||||
import re
|
|
||||||
import logging
|
import logging
|
||||||
|
import re
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
# Internal Packages
|
|
||||||
from khoj.search_filter.base_filter import BaseFilter
|
from khoj.search_filter.base_filter import BaseFilter
|
||||||
from khoj.utils.helpers import LRU
|
from khoj.utils.helpers import LRU
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,25 +1,27 @@
|
||||||
# Standard Packages
|
import copy
|
||||||
import glob
|
import glob
|
||||||
|
import logging
|
||||||
import math
|
import math
|
||||||
import pathlib
|
import pathlib
|
||||||
import copy
|
|
||||||
import shutil
|
import shutil
|
||||||
import logging
|
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
# External Packages
|
|
||||||
from sentence_transformers import SentenceTransformer, util
|
|
||||||
from PIL import Image
|
|
||||||
from tqdm import trange
|
|
||||||
import torch
|
import torch
|
||||||
|
from PIL import Image
|
||||||
|
from sentence_transformers import SentenceTransformer, util
|
||||||
|
from tqdm import trange
|
||||||
|
|
||||||
# Internal Packages
|
|
||||||
from khoj.utils.helpers import get_absolute_path, get_from_dict, resolve_absolute_path, load_model, timer
|
|
||||||
from khoj.utils.config import ImageContent, ImageSearchModel
|
from khoj.utils.config import ImageContent, ImageSearchModel
|
||||||
|
from khoj.utils.helpers import (
|
||||||
|
get_absolute_path,
|
||||||
|
get_from_dict,
|
||||||
|
load_model,
|
||||||
|
resolve_absolute_path,
|
||||||
|
timer,
|
||||||
|
)
|
||||||
from khoj.utils.models import BaseEncoder
|
from khoj.utils.models import BaseEncoder
|
||||||
from khoj.utils.rawconfig import ImageContentConfig, ImageSearchConfig, SearchResponse
|
from khoj.utils.rawconfig import ImageContentConfig, ImageSearchConfig, SearchResponse
|
||||||
|
|
||||||
|
|
||||||
# Create Logger
|
# Create Logger
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
|
@ -1,26 +1,22 @@
|
||||||
# Standard Packages
|
|
||||||
import logging
|
import logging
|
||||||
import math
|
import math
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import List, Tuple, Type, Union
|
from typing import List, Tuple, Type, Union
|
||||||
|
|
||||||
# External Packages
|
|
||||||
import torch
|
import torch
|
||||||
|
from asgiref.sync import sync_to_async
|
||||||
from sentence_transformers import util
|
from sentence_transformers import util
|
||||||
|
|
||||||
from asgiref.sync import sync_to_async
|
from khoj.database.adapters import EntryAdapters, get_user_search_model_or_default
|
||||||
|
from khoj.database.models import Entry as DbEntry
|
||||||
|
from khoj.database.models import KhojUser
|
||||||
# Internal Packages
|
from khoj.processor.content.text_to_entries import TextToEntries
|
||||||
from khoj.utils import state
|
from khoj.utils import state
|
||||||
from khoj.utils.helpers import get_absolute_path, timer
|
from khoj.utils.helpers import get_absolute_path, timer
|
||||||
from khoj.utils.models import BaseEncoder
|
|
||||||
from khoj.utils.state import SearchType
|
|
||||||
from khoj.utils.rawconfig import SearchResponse, Entry
|
|
||||||
from khoj.utils.jsonl import load_jsonl
|
from khoj.utils.jsonl import load_jsonl
|
||||||
from khoj.processor.content.text_to_entries import TextToEntries
|
from khoj.utils.models import BaseEncoder
|
||||||
from khoj.database.adapters import EntryAdapters, get_user_search_model_or_default
|
from khoj.utils.rawconfig import Entry, SearchResponse
|
||||||
from khoj.database.models import KhojUser, Entry as DbEntry
|
from khoj.utils.state import SearchType
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
|
@ -1,21 +1,23 @@
|
||||||
# Standard Packages
|
|
||||||
import argparse
|
import argparse
|
||||||
|
import logging
|
||||||
|
import os
|
||||||
import pathlib
|
import pathlib
|
||||||
from importlib.metadata import version
|
from importlib.metadata import version
|
||||||
import os
|
|
||||||
import logging
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
# Internal Packages
|
from khoj.migrations.migrate_offline_chat_default_model import (
|
||||||
|
migrate_offline_chat_default_model,
|
||||||
|
)
|
||||||
|
from khoj.migrations.migrate_offline_chat_schema import migrate_offline_chat_schema
|
||||||
|
from khoj.migrations.migrate_offline_model import migrate_offline_model
|
||||||
|
from khoj.migrations.migrate_processor_config_openai import (
|
||||||
|
migrate_processor_conversation_schema,
|
||||||
|
)
|
||||||
|
from khoj.migrations.migrate_server_pg import migrate_server_pg
|
||||||
|
from khoj.migrations.migrate_version import migrate_config_to_version
|
||||||
from khoj.utils.helpers import resolve_absolute_path
|
from khoj.utils.helpers import resolve_absolute_path
|
||||||
from khoj.utils.yaml import parse_config_from_file
|
from khoj.utils.yaml import parse_config_from_file
|
||||||
from khoj.migrations.migrate_version import migrate_config_to_version
|
|
||||||
from khoj.migrations.migrate_processor_config_openai import migrate_processor_conversation_schema
|
|
||||||
from khoj.migrations.migrate_offline_model import migrate_offline_model
|
|
||||||
from khoj.migrations.migrate_offline_chat_schema import migrate_offline_chat_schema
|
|
||||||
from khoj.migrations.migrate_offline_chat_default_model import migrate_offline_chat_default_model
|
|
||||||
from khoj.migrations.migrate_server_pg import migrate_server_pg
|
|
||||||
|
|
||||||
|
|
||||||
def cli(args=None):
|
def cli(args=None):
|
||||||
|
|
|
@ -1,24 +1,21 @@
|
||||||
# System Packages
|
# System Packages
|
||||||
from __future__ import annotations # to avoid quoting type hints
|
from __future__ import annotations # to avoid quoting type hints
|
||||||
|
|
||||||
from enum import Enum
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from typing import TYPE_CHECKING, List, Optional, Union, Any
|
from enum import Enum
|
||||||
|
from typing import TYPE_CHECKING, Any, List, Optional, Union
|
||||||
|
|
||||||
# External Packages
|
|
||||||
import torch
|
import torch
|
||||||
|
|
||||||
# Internal Packages
|
|
||||||
from khoj.processor.conversation.offline.utils import download_model
|
from khoj.processor.conversation.offline.utils import download_model
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
# Internal Packages
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from sentence_transformers import CrossEncoder
|
from sentence_transformers import CrossEncoder
|
||||||
|
|
||||||
from khoj.utils.models import BaseEncoder
|
from khoj.utils.models import BaseEncoder
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,19 @@
|
||||||
import logging
|
|
||||||
import glob
|
import glob
|
||||||
|
import logging
|
||||||
import os
|
import os
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
|
|
||||||
|
from khoj.database.models import (
|
||||||
|
LocalMarkdownConfig,
|
||||||
|
LocalOrgConfig,
|
||||||
|
LocalPdfConfig,
|
||||||
|
LocalPlaintextConfig,
|
||||||
|
)
|
||||||
|
from khoj.utils.config import SearchType
|
||||||
from khoj.utils.helpers import get_absolute_path, is_none_or_empty
|
from khoj.utils.helpers import get_absolute_path, is_none_or_empty
|
||||||
from khoj.utils.rawconfig import TextContentConfig
|
from khoj.utils.rawconfig import TextContentConfig
|
||||||
from khoj.utils.config import SearchType
|
|
||||||
from khoj.database.models import LocalMarkdownConfig, LocalOrgConfig, LocalPdfConfig, LocalPlaintextConfig
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
|
@ -1,32 +1,29 @@
|
||||||
# Standard Packages
|
|
||||||
from __future__ import annotations # to avoid quoting type hints
|
from __future__ import annotations # to avoid quoting type hints
|
||||||
from collections import OrderedDict
|
|
||||||
import datetime
|
import datetime
|
||||||
|
import logging
|
||||||
|
import os
|
||||||
|
import platform
|
||||||
|
import random
|
||||||
|
import uuid
|
||||||
|
from collections import OrderedDict
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
from importlib import import_module
|
from importlib import import_module
|
||||||
from importlib.metadata import version
|
from importlib.metadata import version
|
||||||
from itertools import islice
|
from itertools import islice
|
||||||
import logging
|
|
||||||
from os import path
|
from os import path
|
||||||
import os
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import platform
|
|
||||||
import random
|
|
||||||
from time import perf_counter
|
from time import perf_counter
|
||||||
|
from typing import TYPE_CHECKING, Optional, Union
|
||||||
|
|
||||||
import torch
|
import torch
|
||||||
from typing import Optional, Union, TYPE_CHECKING
|
|
||||||
import uuid
|
|
||||||
from asgiref.sync import sync_to_async
|
from asgiref.sync import sync_to_async
|
||||||
|
|
||||||
# Internal Packages
|
|
||||||
from khoj.utils import constants
|
from khoj.utils import constants
|
||||||
|
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
# External Packages
|
from sentence_transformers import CrossEncoder, SentenceTransformer
|
||||||
from sentence_transformers import SentenceTransformer, CrossEncoder
|
|
||||||
|
|
||||||
# Internal Packages
|
|
||||||
from khoj.utils.models import BaseEncoder
|
from khoj.utils.models import BaseEncoder
|
||||||
from khoj.utils.rawconfig import AppConfig
|
from khoj.utils.rawconfig import AppConfig
|
||||||
|
|
||||||
|
|
|
@ -1,20 +1,17 @@
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
from khoj.database.adapters import ConversationAdapters
|
||||||
from khoj.database.models import (
|
from khoj.database.models import (
|
||||||
|
ChatModelOptions,
|
||||||
KhojUser,
|
KhojUser,
|
||||||
OfflineChatProcessorConversationConfig,
|
OfflineChatProcessorConversationConfig,
|
||||||
OpenAIProcessorConversationConfig,
|
OpenAIProcessorConversationConfig,
|
||||||
ChatModelOptions,
|
|
||||||
SpeechToTextModelOptions,
|
SpeechToTextModelOptions,
|
||||||
TextToImageModelConfig,
|
TextToImageModelConfig,
|
||||||
)
|
)
|
||||||
|
|
||||||
from khoj.utils.constants import default_offline_chat_model, default_online_chat_model
|
|
||||||
from khoj.processor.conversation.utils import model_to_prompt_size, model_to_tokenizer
|
from khoj.processor.conversation.utils import model_to_prompt_size, model_to_tokenizer
|
||||||
|
from khoj.utils.constants import default_offline_chat_model, default_online_chat_model
|
||||||
from khoj.database.adapters import ConversationAdapters
|
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,10 @@
|
||||||
# Standard Packages
|
|
||||||
import json
|
|
||||||
import gzip
|
import gzip
|
||||||
|
import json
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
# Internal Packages
|
|
||||||
from khoj.utils.constants import empty_escape_sequences
|
from khoj.utils.constants import empty_escape_sequences
|
||||||
from khoj.utils.helpers import get_absolute_path
|
from khoj.utils.helpers import get_absolute_path
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,10 @@
|
||||||
# Standard Packages
|
|
||||||
from abc import ABC, abstractmethod
|
from abc import ABC, abstractmethod
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
# External Packages
|
|
||||||
import openai
|
import openai
|
||||||
import torch
|
import torch
|
||||||
from tqdm import trange
|
from tqdm import trange
|
||||||
|
|
||||||
# Internal Packages
|
|
||||||
from khoj.utils import state
|
from khoj.utils import state
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,11 @@
|
||||||
# System Packages
|
# System Packages
|
||||||
import json
|
import json
|
||||||
from pathlib import Path
|
|
||||||
from typing import List, Dict, Optional
|
|
||||||
import uuid
|
import uuid
|
||||||
|
from pathlib import Path
|
||||||
|
from typing import Dict, List, Optional
|
||||||
|
|
||||||
# External Packages
|
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
|
|
||||||
# Internal Packages
|
|
||||||
from khoj.utils.helpers import to_snake_case_from_dash
|
from khoj.utils.helpers import to_snake_case_from_dash
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,18 +1,15 @@
|
||||||
# Standard Packages
|
|
||||||
from collections import defaultdict
|
|
||||||
import os
|
import os
|
||||||
from pathlib import Path
|
|
||||||
import threading
|
import threading
|
||||||
from typing import List, Dict
|
from collections import defaultdict
|
||||||
|
from pathlib import Path
|
||||||
|
from typing import Dict, List
|
||||||
|
|
||||||
# External Packages
|
|
||||||
from openai import OpenAI
|
from openai import OpenAI
|
||||||
from whisper import Whisper
|
from whisper import Whisper
|
||||||
|
|
||||||
# Internal Packages
|
|
||||||
from khoj.processor.embeddings import CrossEncoderModel, EmbeddingsModel
|
from khoj.processor.embeddings import CrossEncoderModel, EmbeddingsModel
|
||||||
from khoj.utils import config as utils_config
|
from khoj.utils import config as utils_config
|
||||||
from khoj.utils.config import ContentIndex, SearchModels, GPT4AllProcessorModel
|
from khoj.utils.config import ContentIndex, GPT4AllProcessorModel, SearchModels
|
||||||
from khoj.utils.helpers import LRU, get_device
|
from khoj.utils.helpers import LRU, get_device
|
||||||
from khoj.utils.rawconfig import FullConfig
|
from khoj.utils.rawconfig import FullConfig
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,9 @@
|
||||||
# Standard Packages
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
# External Packages
|
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
# Internal Packages
|
|
||||||
from khoj.utils.rawconfig import FullConfig
|
|
||||||
from khoj.utils import state
|
from khoj.utils import state
|
||||||
|
from khoj.utils.rawconfig import FullConfig
|
||||||
|
|
||||||
# Do not emit tags when dumping to YAML
|
# Do not emit tags when dumping to YAML
|
||||||
yaml.emitter.Emitter.process_tag = lambda self, *args, **kwargs: None # type: ignore[assignment]
|
yaml.emitter.Emitter.process_tag = lambda self, *args, **kwargs: None # type: ignore[assignment]
|
||||||
|
|
|
@ -1,17 +1,13 @@
|
||||||
# Standard Packages
|
|
||||||
import argparse
|
import argparse
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
import sqlite3
|
||||||
from typing import Dict, List
|
from typing import Dict, List
|
||||||
|
|
||||||
# External Packages
|
|
||||||
from fastapi import FastAPI
|
|
||||||
from fastapi import HTTPException
|
|
||||||
from posthog import Posthog
|
|
||||||
from dotenv import load_dotenv
|
|
||||||
import sqlite3
|
|
||||||
import uvicorn
|
import uvicorn
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
from fastapi import FastAPI, HTTPException
|
||||||
|
from posthog import Posthog
|
||||||
|
|
||||||
# Initialize Global App Variables
|
# Initialize Global App Variables
|
||||||
app = FastAPI()
|
app = FastAPI()
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
# External Packages
|
|
||||||
import os
|
import os
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
@ -7,8 +6,11 @@ from fastapi import FastAPI
|
||||||
from fastapi.staticfiles import StaticFiles
|
from fastapi.staticfiles import StaticFiles
|
||||||
from fastapi.testclient import TestClient
|
from fastapi.testclient import TestClient
|
||||||
|
|
||||||
# Internal Packages
|
from khoj.configure import (
|
||||||
from khoj.configure import configure_middleware, configure_routes, configure_search_types
|
configure_middleware,
|
||||||
|
configure_routes,
|
||||||
|
configure_search_types,
|
||||||
|
)
|
||||||
from khoj.database.models import (
|
from khoj.database.models import (
|
||||||
GithubConfig,
|
GithubConfig,
|
||||||
GithubRepoConfig,
|
GithubRepoConfig,
|
||||||
|
@ -27,7 +29,12 @@ from khoj.utils import fs_syncer, state
|
||||||
from khoj.utils.config import SearchModels
|
from khoj.utils.config import SearchModels
|
||||||
from khoj.utils.constants import web_directory
|
from khoj.utils.constants import web_directory
|
||||||
from khoj.utils.helpers import resolve_absolute_path
|
from khoj.utils.helpers import resolve_absolute_path
|
||||||
from khoj.utils.rawconfig import ContentConfig, ImageContentConfig, ImageSearchConfig, SearchConfig
|
from khoj.utils.rawconfig import (
|
||||||
|
ContentConfig,
|
||||||
|
ImageContentConfig,
|
||||||
|
ImageSearchConfig,
|
||||||
|
SearchConfig,
|
||||||
|
)
|
||||||
from tests.helpers import (
|
from tests.helpers import (
|
||||||
ChatModelOptionsFactory,
|
ChatModelOptionsFactory,
|
||||||
OfflineChatProcessorConversationConfigFactory,
|
OfflineChatProcessorConversationConfigFactory,
|
||||||
|
|
|
@ -1,16 +1,17 @@
|
||||||
import factory
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
import factory
|
||||||
|
|
||||||
from khoj.database.models import (
|
from khoj.database.models import (
|
||||||
KhojUser,
|
|
||||||
KhojApiUser,
|
|
||||||
ChatModelOptions,
|
ChatModelOptions,
|
||||||
|
Conversation,
|
||||||
|
KhojApiUser,
|
||||||
|
KhojUser,
|
||||||
OfflineChatProcessorConversationConfig,
|
OfflineChatProcessorConversationConfig,
|
||||||
OpenAIProcessorConversationConfig,
|
OpenAIProcessorConversationConfig,
|
||||||
SearchModelConfig,
|
SearchModelConfig,
|
||||||
UserConversationConfig,
|
|
||||||
Conversation,
|
|
||||||
Subscription,
|
Subscription,
|
||||||
|
UserConversationConfig,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from random import random
|
from random import random
|
||||||
|
|
||||||
# Internal Packages
|
|
||||||
from khoj.utils.cli import cli
|
from khoj.utils.cli import cli
|
||||||
from khoj.utils.helpers import resolve_absolute_path
|
from khoj.utils.helpers import resolve_absolute_path
|
||||||
|
|
||||||
|
|
|
@ -4,12 +4,9 @@ from urllib.parse import quote
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from fastapi import FastAPI
|
from fastapi import FastAPI
|
||||||
|
|
||||||
# External Packages
|
|
||||||
from fastapi.testclient import TestClient
|
from fastapi.testclient import TestClient
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
|
||||||
# Internal Packages
|
|
||||||
from khoj.configure import configure_routes, configure_search_types
|
from khoj.configure import configure_routes, configure_search_types
|
||||||
from khoj.database.adapters import EntryAdapters
|
from khoj.database.adapters import EntryAdapters
|
||||||
from khoj.database.models import KhojApiUser, KhojUser
|
from khoj.database.models import KhojApiUser, KhojUser
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
from khoj.processor.conversation import utils
|
|
||||||
from langchain.schema import ChatMessage
|
|
||||||
import factory
|
import factory
|
||||||
import tiktoken
|
import tiktoken
|
||||||
|
from langchain.schema import ChatMessage
|
||||||
|
|
||||||
|
from khoj.processor.conversation import utils
|
||||||
|
|
||||||
|
|
||||||
class ChatMessageFactory(factory.Factory):
|
class ChatMessageFactory(factory.Factory):
|
||||||
|
|
|
@ -1,11 +1,8 @@
|
||||||
# Standard Packages
|
|
||||||
import re
|
import re
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
# External Packages
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
# Internal Packages
|
|
||||||
from khoj.search_filter.date_filter import DateFilter
|
from khoj.search_filter.date_filter import DateFilter
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
# Standard Packages
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
# External Packages
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
SKIP_TESTS = True
|
SKIP_TESTS = True
|
||||||
|
@ -18,10 +16,13 @@ try:
|
||||||
except ModuleNotFoundError as e:
|
except ModuleNotFoundError as e:
|
||||||
print("There was an error importing GPT4All. Please run pip install gpt4all in order to install it.")
|
print("There was an error importing GPT4All. Please run pip install gpt4all in order to install it.")
|
||||||
|
|
||||||
# Internal Packages
|
|
||||||
from khoj.processor.conversation.offline.chat_model import converse_offline, extract_questions_offline, filter_questions
|
|
||||||
from khoj.processor.conversation.offline.utils import download_model
|
|
||||||
|
|
||||||
|
from khoj.processor.conversation.offline.chat_model import (
|
||||||
|
converse_offline,
|
||||||
|
extract_questions_offline,
|
||||||
|
filter_questions,
|
||||||
|
)
|
||||||
|
from khoj.processor.conversation.offline.utils import download_model
|
||||||
from khoj.processor.conversation.utils import message_to_log
|
from khoj.processor.conversation.utils import message_to_log
|
||||||
|
|
||||||
MODEL_NAME = "mistral-7b-instruct-v0.1.Q4_0.gguf"
|
MODEL_NAME = "mistral-7b-instruct-v0.1.Q4_0.gguf"
|
||||||
|
|
|
@ -1,13 +1,10 @@
|
||||||
# Standard Packages
|
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
from urllib.parse import quote
|
from urllib.parse import quote
|
||||||
|
|
||||||
# External Packages
|
|
||||||
import pytest
|
import pytest
|
||||||
from freezegun import freeze_time
|
|
||||||
from faker import Faker
|
from faker import Faker
|
||||||
|
from freezegun import freeze_time
|
||||||
|
|
||||||
# Internal Packages
|
|
||||||
from khoj.processor.conversation import prompts
|
from khoj.processor.conversation import prompts
|
||||||
from khoj.processor.conversation.utils import message_to_log
|
from khoj.processor.conversation.utils import message_to_log
|
||||||
from tests.helpers import ConversationFactory
|
from tests.helpers import ConversationFactory
|
||||||
|
|
|
@ -1,13 +1,10 @@
|
||||||
# Standard Packages
|
|
||||||
import numpy as np
|
|
||||||
import psutil
|
|
||||||
from scipy.stats import linregress
|
|
||||||
import secrets
|
import secrets
|
||||||
|
|
||||||
# External Packages
|
import numpy as np
|
||||||
|
import psutil
|
||||||
import pytest
|
import pytest
|
||||||
|
from scipy.stats import linregress
|
||||||
|
|
||||||
# Internal Packages
|
|
||||||
from khoj.processor.embeddings import EmbeddingsModel
|
from khoj.processor.embeddings import EmbeddingsModel
|
||||||
from khoj.utils import helpers
|
from khoj.utils import helpers
|
||||||
|
|
||||||
|
|
|
@ -1,18 +1,16 @@
|
||||||
# Standard Modules
|
# Standard Modules
|
||||||
import logging
|
import logging
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
import pytest
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
|
||||||
# External Packages
|
|
||||||
import pytest
|
|
||||||
from khoj.utils.config import SearchModels
|
|
||||||
|
|
||||||
# Internal Packages
|
|
||||||
from khoj.utils.state import content_index, search_models
|
|
||||||
from khoj.utils.constants import web_directory
|
|
||||||
from khoj.search_type import image_search
|
from khoj.search_type import image_search
|
||||||
|
from khoj.utils.config import SearchModels
|
||||||
|
from khoj.utils.constants import web_directory
|
||||||
from khoj.utils.helpers import resolve_absolute_path
|
from khoj.utils.helpers import resolve_absolute_path
|
||||||
from khoj.utils.rawconfig import ContentConfig, SearchConfig
|
from khoj.utils.rawconfig import ContentConfig, SearchConfig
|
||||||
|
from khoj.utils.state import content_index, search_models
|
||||||
|
|
||||||
|
|
||||||
# Test
|
# Test
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
# Standard Packages
|
|
||||||
import json
|
import json
|
||||||
from pathlib import Path
|
|
||||||
import os
|
import os
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
# Internal Packages
|
|
||||||
from khoj.processor.content.markdown.markdown_to_entries import MarkdownToEntries
|
from khoj.processor.content.markdown.markdown_to_entries import MarkdownToEntries
|
||||||
from khoj.utils.fs_syncer import get_markdown_files
|
from khoj.utils.fs_syncer import get_markdown_files
|
||||||
from khoj.utils.rawconfig import TextContentConfig
|
from khoj.utils.rawconfig import TextContentConfig
|
||||||
|
|
|
@ -1,13 +1,10 @@
|
||||||
# Standard Modules
|
# Standard Modules
|
||||||
from urllib.parse import quote
|
from urllib.parse import quote
|
||||||
|
|
||||||
# External Packages
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from khoj.database.models import KhojApiUser, KhojUser
|
from khoj.database.models import KhojApiUser, KhojUser
|
||||||
from khoj.processor.content.org_mode.org_to_entries import OrgToEntries
|
from khoj.processor.content.org_mode.org_to_entries import OrgToEntries
|
||||||
|
|
||||||
# Internal Packages
|
|
||||||
from khoj.search_type import text_search
|
from khoj.search_type import text_search
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,17 +1,13 @@
|
||||||
# Standard Packages
|
|
||||||
import os
|
import os
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
# External Packages
|
|
||||||
import pytest
|
|
||||||
import freezegun
|
import freezegun
|
||||||
|
import pytest
|
||||||
from freezegun import freeze_time
|
from freezegun import freeze_time
|
||||||
|
|
||||||
# Internal Packages
|
|
||||||
from khoj.processor.conversation.openai.gpt import converse, extract_questions
|
from khoj.processor.conversation.openai.gpt import converse, extract_questions
|
||||||
from khoj.processor.conversation.utils import message_to_log
|
from khoj.processor.conversation.utils import message_to_log
|
||||||
|
|
||||||
|
|
||||||
# Initialize variables for tests
|
# Initialize variables for tests
|
||||||
api_key = os.getenv("OPENAI_API_KEY")
|
api_key = os.getenv("OPENAI_API_KEY")
|
||||||
if api_key is None:
|
if api_key is None:
|
||||||
|
|
|
@ -1,17 +1,14 @@
|
||||||
# Standard Packages
|
|
||||||
import os
|
import os
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
from urllib.parse import quote
|
from urllib.parse import quote
|
||||||
|
|
||||||
# External Packages
|
|
||||||
import pytest
|
import pytest
|
||||||
from freezegun import freeze_time
|
from freezegun import freeze_time
|
||||||
from khoj.processor.conversation import prompts
|
|
||||||
|
|
||||||
# Internal Packages
|
from khoj.database.models import KhojUser
|
||||||
|
from khoj.processor.conversation import prompts
|
||||||
from khoj.processor.conversation.utils import message_to_log
|
from khoj.processor.conversation.utils import message_to_log
|
||||||
from tests.helpers import ConversationFactory
|
from tests.helpers import ConversationFactory
|
||||||
from khoj.database.models import KhojUser
|
|
||||||
|
|
||||||
# Initialize variables for tests
|
# Initialize variables for tests
|
||||||
api_key = os.getenv("OPENAI_API_KEY")
|
api_key = os.getenv("OPENAI_API_KEY")
|
||||||
|
|
|
@ -1,14 +1,11 @@
|
||||||
# Standard Packages
|
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
|
|
||||||
# Internal Packages
|
|
||||||
from khoj.processor.content.org_mode.org_to_entries import OrgToEntries
|
from khoj.processor.content.org_mode.org_to_entries import OrgToEntries
|
||||||
from khoj.processor.content.text_to_entries import TextToEntries
|
from khoj.processor.content.text_to_entries import TextToEntries
|
||||||
from khoj.utils.helpers import is_none_or_empty
|
|
||||||
from khoj.utils.rawconfig import Entry
|
|
||||||
from khoj.utils.fs_syncer import get_org_files
|
from khoj.utils.fs_syncer import get_org_files
|
||||||
from khoj.utils.rawconfig import TextContentConfig
|
from khoj.utils.helpers import is_none_or_empty
|
||||||
|
from khoj.utils.rawconfig import Entry, TextContentConfig
|
||||||
|
|
||||||
|
|
||||||
def test_configure_heading_entry_to_jsonl(tmp_path):
|
def test_configure_heading_entry_to_jsonl(tmp_path):
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
# Standard Packages
|
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
# Internal Packages
|
|
||||||
from khoj.processor.content.org_mode import orgnode
|
from khoj.processor.content.org_mode import orgnode
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,7 @@
|
||||||
# Standard Packages
|
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
|
|
||||||
# Internal Packages
|
|
||||||
from khoj.processor.content.pdf.pdf_to_entries import PdfToEntries
|
from khoj.processor.content.pdf.pdf_to_entries import PdfToEntries
|
||||||
|
|
||||||
from khoj.utils.fs_syncer import get_pdf_files
|
from khoj.utils.fs_syncer import get_pdf_files
|
||||||
from khoj.utils.rawconfig import TextContentConfig
|
from khoj.utils.rawconfig import TextContentConfig
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,9 @@
|
||||||
# Standard Packages
|
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from khoj.database.models import KhojUser, LocalPlaintextConfig
|
from khoj.database.models import KhojUser, LocalPlaintextConfig
|
||||||
from khoj.processor.content.plaintext.plaintext_to_entries import PlaintextToEntries
|
from khoj.processor.content.plaintext.plaintext_to_entries import PlaintextToEntries
|
||||||
|
|
||||||
# Internal Packages
|
|
||||||
from khoj.utils.fs_syncer import get_plaintext_files
|
from khoj.utils.fs_syncer import get_plaintext_files
|
||||||
from khoj.utils.rawconfig import TextContentConfig
|
from khoj.utils.rawconfig import TextContentConfig
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
# External Packages
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
# Internal Packages
|
from khoj.utils.rawconfig import ImageContentConfig, TextContentConfig
|
||||||
from khoj.utils.rawconfig import TextContentConfig, ImageContentConfig
|
|
||||||
|
|
||||||
|
|
||||||
# Test
|
# Test
|
||||||
|
|
|
@ -4,14 +4,11 @@ import logging
|
||||||
import os
|
import os
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
# External Packages
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from khoj.database.models import Entry, GithubConfig, KhojUser, LocalOrgConfig
|
from khoj.database.models import Entry, GithubConfig, KhojUser, LocalOrgConfig
|
||||||
from khoj.processor.content.github.github_to_entries import GithubToEntries
|
from khoj.processor.content.github.github_to_entries import GithubToEntries
|
||||||
from khoj.processor.content.org_mode.org_to_entries import OrgToEntries
|
from khoj.processor.content.org_mode.org_to_entries import OrgToEntries
|
||||||
|
|
||||||
# Internal Packages
|
|
||||||
from khoj.search_type import text_search
|
from khoj.search_type import text_search
|
||||||
from khoj.utils.fs_syncer import collect_files, get_org_files
|
from khoj.utils.fs_syncer import collect_files, get_org_files
|
||||||
from khoj.utils.rawconfig import ContentConfig, SearchConfig
|
from khoj.utils.rawconfig import ContentConfig, SearchConfig
|
||||||
|
|
Loading…
Reference in a new issue