Skip to content

Commit

Permalink
Handle subscribe renew date, langchain, pydantic & logger.warn warnings
Browse files Browse the repository at this point in the history
- Ensure langchain less than 0.2.0 is used, to prevent breaking
  ChatOpenAI, PyMuPDF usage due to their deprecation after 0.2.0
- Set subscription renewal date to a timezone aware datetime
- Use logger.warning instead of logger.warn as latter is deprecated
- Use `model_dump' not deprecated dict to get all configured content_types
  • Loading branch information
debanjum committed Jan 11, 2024
1 parent 5f97357 commit 7dfbcd2
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ dependencies = [
"torch == 2.0.1",
"uvicorn == 0.17.6",
"aiohttp ~= 3.9.0",
"langchain >= 0.0.331",
"langchain <= 0.2.0",
"requests >= 2.26.0",
"bs4 >= 0.0.1",
"anyio == 3.7.1",
Expand Down
5 changes: 4 additions & 1 deletion src/khoj/configure.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import json
import logging
import os
from datetime import datetime
from enum import Enum
from typing import Optional

import openai
import requests
import schedule
from django.utils.timezone import make_aware
from starlette.authentication import (
AuthCredentials,
AuthenticationBackend,
Expand Down Expand Up @@ -59,7 +61,8 @@ def _initialize_default_user(self):
email="default@example.com",
password="default",
)
Subscription.objects.create(user=default_user, type="standard", renewal_date="2100-04-01")
renewal_date = make_aware(datetime.strptime("2100-04-01", "%Y-%m-%d"))
Subscription.objects.create(user=default_user, type="standard", renewal_date=renewal_date)

async def authenticate(self, request: HTTPConnection):
current_user = request.session.get("user")
Expand Down
2 changes: 1 addition & 1 deletion src/khoj/routers/api_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ def get_config_types(
configured_content_types = list(enabled_file_types)

if state.config and state.config.content_type:
for ctype in state.config.content_type.dict(exclude_none=True):
for ctype in state.config.content_type.model_dump(exclude_none=True):
configured_content_types.append(ctype)

return [
Expand Down
2 changes: 1 addition & 1 deletion src/khoj/routers/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
auth_router = APIRouter()

if not state.anonymous_mode and not (os.environ.get("GOOGLE_CLIENT_ID") and os.environ.get("GOOGLE_CLIENT_SECRET")):
logger.warn(
logger.warning(
"🚨 Use --anonymous-mode flag to disable Google OAuth or set GOOGLE_CLIENT_ID, GOOGLE_CLIENT_SECRET environment variables to enable it"
)
else:
Expand Down
2 changes: 1 addition & 1 deletion src/khoj/routers/subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ async def subscribe(request: Request):
"customer.subscription.updated",
"customer.subscription.deleted",
}:
logger.warn(f"Unhandled Stripe event type: {event['type']}")
logger.warning(f"Unhandled Stripe event type: {event['type']}")
return {"success": False}

# Retrieve the customer's details
Expand Down
4 changes: 3 additions & 1 deletion tests/helpers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import os
from datetime import datetime

import factory
from django.utils.timezone import make_aware

from khoj.database.models import (
ChatModelOptions,
Expand Down Expand Up @@ -90,4 +92,4 @@ class Meta:
user = factory.SubFactory(UserFactory)
type = "standard"
is_recurring = False
renewal_date = "2100-04-01"
renewal_date = make_aware(datetime.strptime("2100-04-01", "%Y-%m-%d"))

0 comments on commit 7dfbcd2

Please sign in to comment.