2023-08-02 00:03:47 +03:00
|
|
|
from models.databases.supabase.supabase import SupabaseDB
|
2023-06-19 22:20:08 +03:00
|
|
|
from pydantic import BaseSettings
|
2023-07-10 15:27:49 +03:00
|
|
|
from supabase.client import Client, create_client
|
2023-06-19 23:46:25 +03:00
|
|
|
from vectorstore.supabase import SupabaseVectorStore
|
2023-11-29 02:07:04 +03:00
|
|
|
from langchain.embeddings.ollama import OllamaEmbeddings
|
|
|
|
from langchain.embeddings.openai import OpenAIEmbeddings
|
|
|
|
|
|
|
|
from logger import get_logger
|
2023-06-19 22:20:08 +03:00
|
|
|
|
2023-11-29 02:07:04 +03:00
|
|
|
logger = get_logger(__name__)
|
2023-06-19 22:20:08 +03:00
|
|
|
|
2023-07-20 19:17:55 +03:00
|
|
|
class BrainRateLimiting(BaseSettings):
|
2023-07-24 15:17:33 +03:00
|
|
|
max_brain_per_user: int = 5
|
2023-07-20 19:17:55 +03:00
|
|
|
|
|
|
|
|
2023-06-19 22:20:08 +03:00
|
|
|
class BrainSettings(BaseSettings):
|
|
|
|
openai_api_key: str
|
|
|
|
supabase_url: str
|
|
|
|
supabase_service_key: str
|
2023-07-17 16:45:31 +03:00
|
|
|
resend_api_key: str = "null"
|
2023-07-18 19:10:48 +03:00
|
|
|
resend_email_address: str = "brain@mail.quivr.app"
|
2023-11-29 02:07:04 +03:00
|
|
|
ollama_api_base_url: str = None
|
2023-06-19 23:46:25 +03:00
|
|
|
|
2023-11-19 20:46:12 +03:00
|
|
|
|
2023-10-23 18:58:45 +03:00
|
|
|
class ContactsSettings(BaseSettings):
|
|
|
|
resend_contact_sales_from: str = "null"
|
|
|
|
resend_contact_sales_to: str = "null"
|
2023-06-22 18:50:06 +03:00
|
|
|
|
2023-11-19 20:46:12 +03:00
|
|
|
|
2023-10-23 18:58:45 +03:00
|
|
|
class ResendSettings(BaseSettings):
|
|
|
|
resend_api_key: str = "null"
|
2023-06-22 18:50:06 +03:00
|
|
|
|
2023-11-19 20:46:12 +03:00
|
|
|
|
2023-08-03 21:24:42 +03:00
|
|
|
def get_supabase_client() -> Client:
|
|
|
|
settings = BrainSettings() # pyright: ignore reportPrivateUsage=none
|
|
|
|
supabase_client: Client = create_client(
|
|
|
|
settings.supabase_url, settings.supabase_service_key
|
|
|
|
)
|
|
|
|
return supabase_client
|
|
|
|
|
|
|
|
|
|
|
|
def get_supabase_db() -> SupabaseDB:
|
|
|
|
supabase_client = get_supabase_client()
|
|
|
|
return SupabaseDB(supabase_client)
|
2023-08-03 17:20:36 +03:00
|
|
|
|
|
|
|
|
2023-11-29 02:07:04 +03:00
|
|
|
def get_embeddings():
|
2023-07-10 15:27:49 +03:00
|
|
|
settings = BrainSettings() # pyright: ignore reportPrivateUsage=none
|
2023-11-29 02:07:04 +03:00
|
|
|
if settings.ollama_api_base_url:
|
|
|
|
embeddings = OllamaEmbeddings(
|
|
|
|
base_url=settings.ollama_api_base_url,
|
|
|
|
) # pyright: ignore reportPrivateUsage=none
|
|
|
|
else:
|
|
|
|
embeddings = OpenAIEmbeddings() # pyright: ignore reportPrivateUsage=none
|
2023-08-03 21:24:42 +03:00
|
|
|
return embeddings
|
|
|
|
|
|
|
|
|
|
|
|
def get_documents_vector_store() -> SupabaseVectorStore:
|
|
|
|
settings = BrainSettings() # pyright: ignore reportPrivateUsage=none
|
|
|
|
embeddings = get_embeddings()
|
2023-06-22 18:50:06 +03:00
|
|
|
supabase_client: Client = create_client(
|
|
|
|
settings.supabase_url, settings.supabase_service_key
|
|
|
|
)
|
2023-06-19 23:46:25 +03:00
|
|
|
documents_vector_store = SupabaseVectorStore(
|
2023-06-22 18:50:06 +03:00
|
|
|
supabase_client, embeddings, table_name="vectors"
|
|
|
|
)
|
2023-08-03 21:24:42 +03:00
|
|
|
return documents_vector_store
|