Handle subscribe renew date, langchain, pydantic & logger.warn warnings

- 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
This commit is contained in:
Debanjum Singh Solanky
2024-01-12 01:32:46 +05:30
parent 5f97357fe0
commit 7dfbcd2e5a
6 changed files with 11 additions and 6 deletions

View File

@@ -55,7 +55,7 @@ dependencies = [
"torch == 2.0.1", "torch == 2.0.1",
"uvicorn == 0.17.6", "uvicorn == 0.17.6",
"aiohttp ~= 3.9.0", "aiohttp ~= 3.9.0",
"langchain >= 0.0.331", "langchain <= 0.2.0",
"requests >= 2.26.0", "requests >= 2.26.0",
"bs4 >= 0.0.1", "bs4 >= 0.0.1",
"anyio == 3.7.1", "anyio == 3.7.1",

View File

@@ -1,12 +1,14 @@
import json import json
import logging import logging
import os import os
from datetime import datetime
from enum import Enum from enum import Enum
from typing import Optional from typing import Optional
import openai import openai
import requests import requests
import schedule import schedule
from django.utils.timezone import make_aware
from starlette.authentication import ( from starlette.authentication import (
AuthCredentials, AuthCredentials,
AuthenticationBackend, AuthenticationBackend,
@@ -59,7 +61,8 @@ class UserAuthenticationBackend(AuthenticationBackend):
email="default@example.com", email="default@example.com",
password="default", 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): async def authenticate(self, request: HTTPConnection):
current_user = request.session.get("user") current_user = request.session.get("user")

View File

@@ -349,7 +349,7 @@ def get_config_types(
configured_content_types = list(enabled_file_types) configured_content_types = list(enabled_file_types)
if state.config and state.config.content_type: 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) configured_content_types.append(ctype)
return [ return [

View File

@@ -26,7 +26,7 @@ logger = logging.getLogger(__name__)
auth_router = APIRouter() auth_router = APIRouter()
if not state.anonymous_mode and not (os.environ.get("GOOGLE_CLIENT_ID") and os.environ.get("GOOGLE_CLIENT_SECRET")): 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" "🚨 Use --anonymous-mode flag to disable Google OAuth or set GOOGLE_CLIENT_ID, GOOGLE_CLIENT_SECRET environment variables to enable it"
) )
else: else:

View File

@@ -37,7 +37,7 @@ async def subscribe(request: Request):
"customer.subscription.updated", "customer.subscription.updated",
"customer.subscription.deleted", "customer.subscription.deleted",
}: }:
logger.warn(f"Unhandled Stripe event type: {event['type']}") logger.warning(f"Unhandled Stripe event type: {event['type']}")
return {"success": False} return {"success": False}
# Retrieve the customer's details # Retrieve the customer's details

View File

@@ -1,6 +1,8 @@
import os import os
from datetime import datetime
import factory import factory
from django.utils.timezone import make_aware
from khoj.database.models import ( from khoj.database.models import (
ChatModelOptions, ChatModelOptions,
@@ -90,4 +92,4 @@ class SubscriptionFactory(factory.django.DjangoModelFactory):
user = factory.SubFactory(UserFactory) user = factory.SubFactory(UserFactory)
type = "standard" type = "standard"
is_recurring = False is_recurring = False
renewal_date = "2100-04-01" renewal_date = make_aware(datetime.strptime("2100-04-01", "%Y-%m-%d"))