2023-10-26 20:37:41 +02:00
|
|
|
import factory
|
|
|
|
import os
|
|
|
|
|
2023-11-21 19:56:04 +01:00
|
|
|
from khoj.database.models import (
|
2023-10-26 20:37:41 +02:00
|
|
|
KhojUser,
|
2023-10-26 21:33:03 +02:00
|
|
|
KhojApiUser,
|
2023-11-02 18:43:27 +01:00
|
|
|
ChatModelOptions,
|
2023-10-26 20:37:41 +02:00
|
|
|
OfflineChatProcessorConversationConfig,
|
|
|
|
OpenAIProcessorConversationConfig,
|
2023-11-16 02:12:54 +01:00
|
|
|
SearchModelConfig,
|
2023-11-02 18:43:27 +01:00
|
|
|
UserConversationConfig,
|
2023-10-26 20:37:41 +02:00
|
|
|
Conversation,
|
2023-11-11 07:38:28 +01:00
|
|
|
Subscription,
|
2023-10-26 20:37:41 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
class UserFactory(factory.django.DjangoModelFactory):
|
|
|
|
class Meta:
|
|
|
|
model = KhojUser
|
|
|
|
|
|
|
|
username = factory.Faker("name")
|
|
|
|
email = factory.Faker("email")
|
|
|
|
password = factory.Faker("password")
|
|
|
|
uuid = factory.Faker("uuid4")
|
|
|
|
|
|
|
|
|
2023-10-26 21:33:03 +02:00
|
|
|
class ApiUserFactory(factory.django.DjangoModelFactory):
|
|
|
|
class Meta:
|
|
|
|
model = KhojApiUser
|
|
|
|
|
|
|
|
user = None
|
|
|
|
name = factory.Faker("name")
|
|
|
|
token = factory.Faker("password")
|
|
|
|
|
|
|
|
|
2023-11-02 18:43:27 +01:00
|
|
|
class ChatModelOptionsFactory(factory.django.DjangoModelFactory):
|
2023-10-26 20:37:41 +02:00
|
|
|
class Meta:
|
2023-11-02 18:43:27 +01:00
|
|
|
model = ChatModelOptions
|
2023-10-26 20:37:41 +02:00
|
|
|
|
|
|
|
max_prompt_size = 2000
|
|
|
|
tokenizer = None
|
2023-11-03 06:44:25 +01:00
|
|
|
chat_model = "mistral-7b-instruct-v0.1.Q4_0.gguf"
|
2023-11-02 18:43:27 +01:00
|
|
|
model_type = "offline"
|
|
|
|
|
|
|
|
|
|
|
|
class UserConversationProcessorConfigFactory(factory.django.DjangoModelFactory):
|
|
|
|
class Meta:
|
|
|
|
model = UserConversationConfig
|
|
|
|
|
|
|
|
user = factory.SubFactory(UserFactory)
|
|
|
|
setting = factory.SubFactory(ChatModelOptionsFactory)
|
2023-10-26 20:37:41 +02:00
|
|
|
|
|
|
|
|
|
|
|
class OfflineChatProcessorConversationConfigFactory(factory.django.DjangoModelFactory):
|
|
|
|
class Meta:
|
|
|
|
model = OfflineChatProcessorConversationConfig
|
|
|
|
|
2023-11-02 18:43:27 +01:00
|
|
|
enabled = True
|
2023-10-26 20:37:41 +02:00
|
|
|
|
|
|
|
|
|
|
|
class OpenAIProcessorConversationConfigFactory(factory.django.DjangoModelFactory):
|
|
|
|
class Meta:
|
|
|
|
model = OpenAIProcessorConversationConfig
|
|
|
|
|
|
|
|
api_key = os.getenv("OPENAI_API_KEY")
|
|
|
|
|
|
|
|
|
|
|
|
class ConversationFactory(factory.django.DjangoModelFactory):
|
|
|
|
class Meta:
|
|
|
|
model = Conversation
|
|
|
|
|
|
|
|
user = factory.SubFactory(UserFactory)
|
2023-11-11 07:38:28 +01:00
|
|
|
|
|
|
|
|
2023-11-15 01:56:26 +01:00
|
|
|
class SearchModelFactory(factory.django.DjangoModelFactory):
|
|
|
|
class Meta:
|
2023-11-16 02:12:54 +01:00
|
|
|
model = SearchModelConfig
|
2023-11-15 01:56:26 +01:00
|
|
|
|
|
|
|
name = "default"
|
|
|
|
model_type = "text"
|
|
|
|
bi_encoder = "thenlper/gte-small"
|
|
|
|
cross_encoder = "cross-encoder/ms-marco-MiniLM-L-6-v2"
|
|
|
|
|
|
|
|
|
2023-11-11 07:38:28 +01:00
|
|
|
class SubscriptionFactory(factory.django.DjangoModelFactory):
|
|
|
|
class Meta:
|
|
|
|
model = Subscription
|
|
|
|
|
|
|
|
user = factory.SubFactory(UserFactory)
|
2023-11-15 01:20:55 +01:00
|
|
|
type = "standard"
|
2023-11-11 07:38:28 +01:00
|
|
|
is_recurring = False
|
2023-11-15 01:20:55 +01:00
|
|
|
renewal_date = "2100-04-01"
|