2023-06-22 18:50:06 +03:00
|
|
|
from typing import Annotated
|
2023-06-19 23:46:25 +03:00
|
|
|
|
|
|
|
from fastapi import Depends
|
|
|
|
from langchain.embeddings.openai import OpenAIEmbeddings
|
2023-06-19 22:20:08 +03:00
|
|
|
from pydantic import BaseSettings
|
2023-06-19 23:46:25 +03:00
|
|
|
from supabase import Client, create_client
|
|
|
|
from vectorstore.supabase import SupabaseVectorStore
|
2023-06-19 22:20:08 +03:00
|
|
|
|
|
|
|
|
|
|
|
class BrainSettings(BaseSettings):
|
|
|
|
openai_api_key: str
|
|
|
|
anthropic_api_key: str
|
|
|
|
supabase_url: str
|
|
|
|
supabase_service_key: str
|
2023-06-19 23:46:25 +03:00
|
|
|
|
2023-06-22 18:50:06 +03:00
|
|
|
|
2023-06-22 11:45:35 +03:00
|
|
|
class LLMSettings(BaseSettings):
|
|
|
|
private: bool
|
|
|
|
model_path: str
|
|
|
|
model_n_ctx: int
|
|
|
|
model_n_batch: int
|
2023-06-19 23:46:25 +03:00
|
|
|
|
2023-06-22 18:50:06 +03:00
|
|
|
|
2023-06-19 23:46:25 +03:00
|
|
|
def common_dependencies() -> dict:
|
|
|
|
settings = BrainSettings()
|
|
|
|
embeddings = OpenAIEmbeddings(openai_api_key=settings.openai_api_key)
|
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-06-19 23:46:25 +03:00
|
|
|
summaries_vector_store = SupabaseVectorStore(
|
2023-06-22 18:50:06 +03:00
|
|
|
supabase_client, embeddings, table_name="summaries"
|
|
|
|
)
|
|
|
|
|
2023-06-19 23:46:25 +03:00
|
|
|
return {
|
|
|
|
"supabase": supabase_client,
|
|
|
|
"embeddings": embeddings,
|
|
|
|
"documents_vector_store": documents_vector_store,
|
2023-06-22 18:50:06 +03:00
|
|
|
"summaries_vector_store": summaries_vector_store,
|
2023-06-19 23:46:25 +03:00
|
|
|
}
|
|
|
|
|
2023-06-22 18:50:06 +03:00
|
|
|
|
|
|
|
CommonsDep = Annotated[dict, Depends(common_dependencies)]
|