mirror of
https://github.com/QuivrHQ/quivr.git
synced 2024-08-16 18:00:23 +03:00
improve (importing): reorganization of the import structure (#964)
* reorganize import level * add __init__, reorganize import from __init__ * reorganize import level * reorganize import level * fix circular import error by keep the import deep as "from models.settings" * fix the relative import * restor unwanted staged files * add backend/venv and backend/.env to gitignore * clean importing
This commit is contained in:
parent
5b79025a03
commit
8af6d61e76
3
.gitignore
vendored
3
.gitignore
vendored
@ -6,6 +6,9 @@ toto.txt
|
||||
*.ipynb
|
||||
log.txt
|
||||
|
||||
backend/venv
|
||||
backend/.env
|
||||
|
||||
|
||||
|
||||
|
||||
|
8
.idea/.gitignore
vendored
Normal file
8
.idea/.gitignore
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
21
.idea/inspectionProfiles/Project_Default.xml
Normal file
21
.idea/inspectionProfiles/Project_Default.xml
Normal file
@ -0,0 +1,21 @@
|
||||
<component name="InspectionProjectProfileManager">
|
||||
<profile version="1.0">
|
||||
<option name="myName" value="Project Default" />
|
||||
<inspection_tool class="Eslint" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="PyPep8NamingInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true">
|
||||
<option name="ignoredErrors">
|
||||
<list>
|
||||
<option value="N803" />
|
||||
</list>
|
||||
</option>
|
||||
</inspection_tool>
|
||||
<inspection_tool class="PyUnresolvedReferencesInspection" enabled="true" level="WARNING" enabled_by_default="true">
|
||||
<option name="ignoredIdentifiers">
|
||||
<list>
|
||||
<option value="bytes.__await__" />
|
||||
</list>
|
||||
</option>
|
||||
</inspection_tool>
|
||||
<inspection_tool class="TsLint" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
</profile>
|
||||
</component>
|
6
.idea/inspectionProfiles/profiles_settings.xml
Normal file
6
.idea/inspectionProfiles/profiles_settings.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<component name="InspectionProjectProfileManager">
|
||||
<settings>
|
||||
<option name="USE_PROJECT_PROFILE" value="false" />
|
||||
<version value="1.0" />
|
||||
</settings>
|
||||
</component>
|
4
.idea/misc.xml
Normal file
4
.idea/misc.xml
Normal file
@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.11" project-jdk-type="Python SDK" />
|
||||
</project>
|
8
.idea/modules.xml
Normal file
8
.idea/modules.xml
Normal file
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/quivr-llm.iml" filepath="$PROJECT_DIR$/.idea/quivr-llm.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
15
.idea/quivr-llm.iml
Normal file
15
.idea/quivr-llm.iml
Normal file
@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="PYTHON_MODULE" version="4">
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/backend" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/backend/core" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="jdk" jdkName="Python 3.11" jdkType="Python SDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
<component name="PyDocumentationSettings">
|
||||
<option name="format" value="PLAIN" />
|
||||
<option name="myDocStringFormat" value="Plain" />
|
||||
</component>
|
||||
</module>
|
6
.idea/vcs.xml
Normal file
6
.idea/vcs.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
@ -5,7 +5,7 @@ from auth.api_key_handler import get_user_from_api_key, verify_api_key
|
||||
from auth.jwt_token_handler import decode_access_token, verify_token
|
||||
from fastapi import Depends, HTTPException, Request
|
||||
from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer
|
||||
from models.users import User
|
||||
from models import User
|
||||
|
||||
|
||||
class AuthBearer(HTTPBearer):
|
||||
|
@ -4,7 +4,7 @@ from typing import Optional
|
||||
|
||||
from jose import jwt
|
||||
from jose.exceptions import JWTError
|
||||
from models.users import User
|
||||
from models import User
|
||||
|
||||
SECRET_KEY = os.environ.get("JWT_SECRET_KEY")
|
||||
ALGORITHM = "HS256"
|
||||
|
@ -1,8 +1,10 @@
|
||||
import os
|
||||
|
||||
if __name__ == "__main__":
|
||||
# import needed here when running main.py to debug backend
|
||||
# you will need to run pip install python-dotenv
|
||||
from dotenv import load_dotenv
|
||||
|
||||
load_dotenv()
|
||||
import sentry_sdk
|
||||
from fastapi import FastAPI, HTTPException, Request, status
|
||||
@ -26,15 +28,10 @@ app = FastAPI()
|
||||
|
||||
add_cors_middleware(app)
|
||||
|
||||
|
||||
|
||||
app.include_router(chat_router)
|
||||
app.include_router(misc_router)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@app.exception_handler(HTTPException)
|
||||
async def http_exception_handler(_, exc):
|
||||
return JSONResponse(
|
||||
@ -47,7 +44,7 @@ async def http_exception_handler(_, exc):
|
||||
def handle_request_validation_error(app: FastAPI):
|
||||
@app.exception_handler(RequestValidationError)
|
||||
async def validation_exception_handler(
|
||||
request: Request, exc: RequestValidationError
|
||||
request: Request, exc: RequestValidationError
|
||||
):
|
||||
exc_str = f"{exc}".replace("\n", " ").replace(" ", " ")
|
||||
logger.error(request, exc_str)
|
||||
@ -66,5 +63,5 @@ handle_request_validation_error(app)
|
||||
if __name__ == "__main__":
|
||||
# run main.py to debug backend
|
||||
import uvicorn
|
||||
uvicorn.run(app, host="0.0.0.0", port=5050)
|
||||
|
||||
uvicorn.run(app, host="0.0.0.0", port=5050)
|
||||
|
@ -3,8 +3,10 @@ from typing import AsyncIterable, List
|
||||
|
||||
from langchain.callbacks.streaming_aiter import AsyncIteratorCallbackHandler
|
||||
from logger import get_logger
|
||||
from models.settings import BrainSettings # Importing settings related to the 'brain'
|
||||
from models import BrainSettings # Importing settings related to the 'brain'
|
||||
|
||||
from pydantic import BaseModel # For data validation and settings management
|
||||
from models import BrainSettings # Importing settings related to the 'brain'
|
||||
|
||||
logger = get_logger(__name__)
|
||||
|
||||
|
@ -2,7 +2,9 @@ import asyncio
|
||||
import json
|
||||
from typing import AsyncIterable, Awaitable
|
||||
from uuid import UUID
|
||||
from logger import get_logger
|
||||
|
||||
from supabase.client import Client, create_client
|
||||
from langchain.callbacks.streaming_aiter import AsyncIteratorCallbackHandler
|
||||
from langchain.chains import ConversationalRetrievalChain, LLMChain
|
||||
from langchain.chains.question_answering import load_qa_chain
|
||||
@ -13,16 +15,19 @@ from langchain.prompts.chat import (
|
||||
HumanMessagePromptTemplate,
|
||||
SystemMessagePromptTemplate,
|
||||
)
|
||||
|
||||
from logger import get_logger
|
||||
from models.chats import ChatQuestion
|
||||
from models import ChatQuestion
|
||||
from models.databases.supabase.chats import CreateChatHistory
|
||||
from repository.brain.get_brain_by_id import get_brain_by_id
|
||||
from repository.brain.get_brain_prompt_id import get_brain_prompt_id
|
||||
from repository.chat.format_chat_history import format_chat_history
|
||||
from repository.chat.get_chat_history import GetChatHistoryOutput, get_chat_history
|
||||
from repository.chat.update_chat_history import update_chat_history
|
||||
from repository.chat.update_message_by_id import update_message_by_id
|
||||
from repository.prompt.get_prompt_by_id import get_prompt_by_id
|
||||
from repository.brain import get_brain_by_id, get_brain_prompt_id
|
||||
from repository.chat import (
|
||||
get_chat_history,
|
||||
update_chat_history,
|
||||
format_chat_history,
|
||||
GetChatHistoryOutput,
|
||||
update_message_by_id,
|
||||
)
|
||||
from repository.prompt import get_prompt_by_id
|
||||
from supabase.client import Client, create_client
|
||||
from vectorstore.supabase import CustomSupabaseVectorStore
|
||||
|
||||
|
@ -10,15 +10,17 @@ from langchain.prompts.chat import (
|
||||
ChatPromptTemplate,
|
||||
HumanMessagePromptTemplate,
|
||||
)
|
||||
from repository.chat.update_message_by_id import update_message_by_id
|
||||
from models.databases.supabase.chats import CreateChatHistory
|
||||
from repository.chat.format_chat_history import format_chat_history
|
||||
from repository.chat.get_chat_history import get_chat_history
|
||||
from repository.chat.update_chat_history import update_chat_history
|
||||
from repository.chat.format_chat_history import format_history_to_openai_mesages
|
||||
from repository.chat import (
|
||||
update_message_by_id,
|
||||
format_chat_history,
|
||||
get_chat_history,
|
||||
update_chat_history,
|
||||
format_history_to_openai_mesages,
|
||||
GetChatHistoryOutput,
|
||||
)
|
||||
from logger import get_logger
|
||||
from models.chats import ChatQuestion
|
||||
from repository.chat.get_chat_history import GetChatHistoryOutput
|
||||
from models import ChatQuestion
|
||||
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
@ -0,0 +1,28 @@
|
||||
from .files import File
|
||||
from .users import User
|
||||
from .brains import Brain
|
||||
from .chat import Chat, ChatHistory
|
||||
from .user_identity import UserIdentity
|
||||
from .prompt import Prompt, PromptStatusEnum
|
||||
from .chats import ChatQuestion, ChatMessage
|
||||
from .brain_entity import BrainEntity, MinimalBrainEntity
|
||||
from .brains_subscription_invitations import BrainSubscription
|
||||
from .settings import (
|
||||
BrainRateLimiting,
|
||||
BrainSettings,
|
||||
LLMSettings,
|
||||
get_supabase_db,
|
||||
get_supabase_client,
|
||||
get_embeddings,
|
||||
get_documents_vector_store
|
||||
)
|
||||
|
||||
# TODO uncomment the below import when start using SQLalchemy
|
||||
# from .sqlalchemy_repository import (
|
||||
# User,
|
||||
# Brain,
|
||||
# BrainUser,
|
||||
# BrainVector,
|
||||
# BrainSubscriptionInvitation,
|
||||
# ApiKey
|
||||
# )
|
@ -5,8 +5,8 @@ import time
|
||||
import openai
|
||||
from langchain.schema import Document
|
||||
from langchain.text_splitter import RecursiveCharacterTextSplitter
|
||||
from models.files import File
|
||||
from models.settings import get_documents_vector_store
|
||||
|
||||
from models import File, get_documents_vector_store
|
||||
from utils.file import compute_sha1_from_content
|
||||
|
||||
|
||||
|
@ -1,8 +1,7 @@
|
||||
import time
|
||||
|
||||
from langchain.schema import Document
|
||||
from models.brains import Brain
|
||||
from models.files import File
|
||||
from models import Brain, File
|
||||
from utils.vectors import Neurons
|
||||
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
from langchain.document_loaders import CSVLoader
|
||||
from models.files import File
|
||||
from models import File
|
||||
|
||||
from .common import process_file
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
from langchain.document_loaders import Docx2txtLoader
|
||||
from models.files import File
|
||||
from models import File
|
||||
|
||||
from .common import process_file
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
from langchain.document_loaders.epub import UnstructuredEPubLoader
|
||||
from models.files import File
|
||||
from models import File
|
||||
|
||||
from .common import process_file
|
||||
|
||||
|
@ -4,8 +4,7 @@ import time
|
||||
from langchain.document_loaders import GitLoader
|
||||
from langchain.schema import Document
|
||||
from langchain.text_splitter import RecursiveCharacterTextSplitter
|
||||
from models.brains import Brain
|
||||
from models.files import File
|
||||
from models import Brain, File
|
||||
from utils.file import compute_sha1_from_content
|
||||
from utils.vectors import Neurons
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
from langchain.document_loaders import UnstructuredHTMLLoader
|
||||
from models.files import File
|
||||
from models import File
|
||||
|
||||
from .common import process_file
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
from langchain.document_loaders import UnstructuredMarkdownLoader
|
||||
from models.files import File
|
||||
from models import File
|
||||
|
||||
from .common import process_file
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
from langchain.document_loaders import NotebookLoader
|
||||
from models.files import File
|
||||
from models import File
|
||||
|
||||
from .common import process_file
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
from langchain.document_loaders import PyMuPDFLoader
|
||||
from models.files import File
|
||||
from models import File
|
||||
|
||||
from .common import process_file
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
from langchain.document_loaders import PyMuPDFLoader
|
||||
from models.files import File
|
||||
from models import File
|
||||
|
||||
from .common import process_file
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
from langchain.document_loaders import UnstructuredPowerPointLoader
|
||||
from models.files import File
|
||||
from models import File
|
||||
|
||||
from .common import process_file
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
from langchain.document_loaders import TextLoader
|
||||
from models.files import File
|
||||
from models import File
|
||||
|
||||
from .common import process_file
|
||||
|
||||
|
12
backend/repository/brain/__init__.py
Normal file
12
backend/repository/brain/__init__.py
Normal file
@ -0,0 +1,12 @@
|
||||
from .create_brain import create_brain
|
||||
from .get_brain_by_id import get_brain_by_id
|
||||
from .update_brain import update_brain_by_id
|
||||
from .get_user_brains import get_user_brains
|
||||
from .get_brain_details import get_brain_details
|
||||
from .create_brain_user import create_brain_user
|
||||
from .get_brain_for_user import get_brain_for_user
|
||||
from .get_brain_prompt_id import get_brain_prompt_id
|
||||
from .update_user_rights import update_brain_user_rights
|
||||
from .get_default_user_brain import get_user_default_brain
|
||||
from .set_as_default_brain_for_user import set_as_default_brain_for_user
|
||||
from .get_default_user_brain_or_create_new import get_default_user_brain_or_create_new
|
@ -1,6 +1,5 @@
|
||||
from models.brain_entity import BrainEntity
|
||||
from models.databases.supabase.brains import CreateBrainProperties
|
||||
from models.settings import get_supabase_db
|
||||
from models import BrainEntity, get_supabase_db
|
||||
|
||||
|
||||
def create_brain(brain: CreateBrainProperties) -> BrainEntity:
|
||||
|
@ -1,6 +1,6 @@
|
||||
from uuid import UUID
|
||||
|
||||
from models.settings import get_supabase_db
|
||||
from models import get_supabase_db
|
||||
from routes.authorizations.types import RoleEnum
|
||||
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
from uuid import UUID
|
||||
|
||||
from models.brain_entity import BrainEntity
|
||||
from models.settings import get_supabase_db
|
||||
from models import BrainEntity, get_supabase_db
|
||||
|
||||
|
||||
def get_brain_by_id(brain_id: UUID) -> BrainEntity | None:
|
||||
|
@ -1,7 +1,6 @@
|
||||
from uuid import UUID
|
||||
|
||||
from models.brain_entity import BrainEntity
|
||||
from models.settings import get_supabase_client
|
||||
from models import BrainEntity, get_supabase_client
|
||||
|
||||
|
||||
def get_brain_details(brain_id: UUID) -> BrainEntity | None:
|
||||
|
@ -1,7 +1,6 @@
|
||||
from uuid import UUID
|
||||
|
||||
from models.brain_entity import MinimalBrainEntity
|
||||
from models.settings import get_supabase_db
|
||||
from models import MinimalBrainEntity, get_supabase_db
|
||||
|
||||
|
||||
def get_brain_for_user(user_id: UUID, brain_id: UUID) -> MinimalBrainEntity:
|
||||
|
@ -1,6 +1,6 @@
|
||||
from uuid import UUID
|
||||
|
||||
from repository.brain.get_brain_by_id import get_brain_by_id
|
||||
from repository.brain import get_brain_by_id
|
||||
|
||||
|
||||
def get_brain_prompt_id(brain_id: UUID) -> UUID | None:
|
||||
|
@ -1,9 +1,8 @@
|
||||
from uuid import UUID
|
||||
|
||||
from logger import get_logger
|
||||
from models.brain_entity import BrainEntity
|
||||
from models.settings import get_supabase_db
|
||||
from repository.brain.get_brain_by_id import get_brain_by_id
|
||||
from models import BrainEntity, get_supabase_db
|
||||
from repository.brain import get_brain_by_id
|
||||
|
||||
logger = get_logger(__name__)
|
||||
|
||||
|
@ -1,11 +1,13 @@
|
||||
from models.brain_entity import BrainEntity
|
||||
from models.databases.supabase.brains import CreateBrainProperties
|
||||
from models.users import User
|
||||
from repository.brain.create_brain import create_brain
|
||||
from repository.brain.create_brain_user import create_brain_user
|
||||
from repository.brain.get_default_user_brain import get_user_default_brain
|
||||
from models import BrainEntity, User
|
||||
from routes.authorizations.types import RoleEnum
|
||||
|
||||
from repository.brain import (
|
||||
create_brain,
|
||||
create_brain_user,
|
||||
get_user_default_brain
|
||||
)
|
||||
|
||||
|
||||
def get_default_user_brain_or_create_new(user: User) -> BrainEntity:
|
||||
default_brain = get_user_default_brain(user.id)
|
||||
|
@ -1,7 +1,6 @@
|
||||
from uuid import UUID
|
||||
|
||||
from models.brain_entity import BrainEntity
|
||||
from models.settings import get_supabase_db
|
||||
from models import BrainEntity, get_supabase_db
|
||||
|
||||
|
||||
def get_user_brains(user_id: UUID) -> list[BrainEntity]:
|
||||
|
@ -1,7 +1,7 @@
|
||||
from uuid import UUID
|
||||
|
||||
from models.settings import get_supabase_client
|
||||
from repository.brain.get_default_user_brain import get_user_default_brain
|
||||
from models import get_supabase_client
|
||||
from repository.brain import get_user_default_brain
|
||||
|
||||
|
||||
def set_as_default_brain_for_user(user_id: UUID, brain_id: UUID):
|
||||
|
@ -1,8 +1,7 @@
|
||||
from uuid import UUID
|
||||
|
||||
from models.brain_entity import BrainEntity
|
||||
from models.databases.supabase.brains import BrainUpdatableProperties
|
||||
from models.settings import get_supabase_db
|
||||
from models import BrainEntity, get_supabase_db
|
||||
|
||||
|
||||
def update_brain_by_id(brain_id: UUID, brain: BrainUpdatableProperties) -> BrainEntity:
|
||||
|
@ -1,6 +1,6 @@
|
||||
from uuid import UUID
|
||||
|
||||
from models.settings import get_supabase_client
|
||||
from models import get_supabase_client
|
||||
|
||||
|
||||
def update_brain_user_rights(brain_id: UUID, user_id: UUID, rights: str) -> None:
|
||||
|
@ -0,0 +1,3 @@
|
||||
from .get_brain_url import get_brain_url
|
||||
from .resend_invitation_email import resend_invitation_email
|
||||
from .subscription_invitation_service import SubscriptionInvitationService
|
@ -1,10 +1,9 @@
|
||||
import resend
|
||||
from logger import get_logger
|
||||
from models.brains_subscription_invitations import BrainSubscription
|
||||
from models.settings import BrainSettings
|
||||
from models import BrainSubscription, BrainSettings
|
||||
|
||||
from repository.brain.get_brain_details import get_brain_details
|
||||
from repository.brain_subscription.get_brain_url import get_brain_url
|
||||
from repository.brain import get_brain_details
|
||||
from repository.brain_subscription import get_brain_url
|
||||
|
||||
logger = get_logger(__name__)
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
from logger import get_logger
|
||||
from models.brains_subscription_invitations import BrainSubscription
|
||||
from models.settings import get_supabase_client
|
||||
from models import BrainSubscription, get_supabase_client
|
||||
|
||||
logger = get_logger(__name__)
|
||||
|
||||
|
@ -0,0 +1,9 @@
|
||||
from .create_chat import create_chat, CreateChatProperties
|
||||
from .update_chat import update_chat, ChatUpdatableProperties
|
||||
from .get_user_chats import get_user_chats
|
||||
from .get_chat_by_id import get_chat_by_id
|
||||
from .get_chat_history import GetChatHistoryOutput, get_chat_history
|
||||
from .update_chat_history import update_chat_history
|
||||
from .update_message_by_id import update_message_by_id
|
||||
from .format_chat_history import format_history_to_openai_mesages
|
||||
from .format_chat_history import format_chat_history, format_history_to_openai_mesages
|
@ -2,8 +2,7 @@ from dataclasses import dataclass
|
||||
from uuid import UUID
|
||||
|
||||
from logger import get_logger
|
||||
from models.chat import Chat
|
||||
from models.settings import get_supabase_db
|
||||
from models import Chat, get_supabase_db
|
||||
|
||||
logger = get_logger(__name__)
|
||||
|
||||
|
@ -1,5 +1,4 @@
|
||||
from models.chat import Chat
|
||||
from models.settings import get_supabase_db
|
||||
from models import Chat, get_supabase_db
|
||||
|
||||
|
||||
def get_chat_by_id(chat_id: str) -> Chat:
|
||||
|
@ -1,12 +1,11 @@
|
||||
from typing import List, Optional
|
||||
from uuid import UUID
|
||||
|
||||
from models.chat import ChatHistory
|
||||
from models.settings import get_supabase_db # For type hinting
|
||||
from models import ChatHistory, get_supabase_db
|
||||
from pydantic import BaseModel
|
||||
|
||||
from repository.brain.get_brain_by_id import get_brain_by_id
|
||||
from repository.prompt.get_prompt_by_id import get_prompt_by_id
|
||||
from repository.brain import get_brain_by_id
|
||||
from repository.prompt import get_prompt_by_id
|
||||
|
||||
|
||||
class GetChatHistoryOutput(BaseModel):
|
||||
|
@ -1,7 +1,6 @@
|
||||
from typing import List
|
||||
|
||||
from models.chat import Chat
|
||||
from models.settings import get_supabase_db
|
||||
from models import Chat, get_supabase_db
|
||||
|
||||
|
||||
def get_user_chats(user_id: str) -> List[Chat]:
|
||||
|
@ -2,8 +2,7 @@ from dataclasses import dataclass
|
||||
from typing import Optional
|
||||
|
||||
from logger import get_logger
|
||||
from models.chat import Chat
|
||||
from models.settings import get_supabase_db
|
||||
from models import Chat, get_supabase_db
|
||||
|
||||
logger = get_logger(__name__)
|
||||
|
||||
|
@ -1,9 +1,8 @@
|
||||
from typing import List
|
||||
|
||||
from fastapi import HTTPException
|
||||
from models.chat import ChatHistory
|
||||
from models.databases.supabase.chats import CreateChatHistory
|
||||
from models.settings import get_supabase_db
|
||||
from models import ChatHistory, get_supabase_db
|
||||
|
||||
|
||||
def update_chat_history(chat_history: CreateChatHistory) -> ChatHistory:
|
||||
|
@ -1,6 +1,5 @@
|
||||
from logger import get_logger
|
||||
from models.chat import ChatHistory
|
||||
from models.settings import get_supabase_db
|
||||
from models import ChatHistory, get_supabase_db
|
||||
|
||||
logger = get_logger(__name__)
|
||||
|
||||
|
5
backend/repository/prompt/__init__.py
Normal file
5
backend/repository/prompt/__init__.py
Normal file
@ -0,0 +1,5 @@
|
||||
from .create_prompt import create_prompt
|
||||
from .get_prompt_by_id import get_prompt_by_id
|
||||
from .get_public_prompts import get_public_prompts
|
||||
from .update_prompt_by_id import update_prompt_by_id
|
||||
from .delete_prompt_py_id import delete_prompt_by_id
|
@ -1,6 +1,5 @@
|
||||
from models.databases.supabase.prompts import CreatePromptProperties
|
||||
from models.prompt import Prompt
|
||||
from models.settings import get_supabase_db
|
||||
from models import Prompt, get_supabase_db
|
||||
|
||||
|
||||
def create_prompt(prompt: CreatePromptProperties) -> Prompt:
|
||||
|
@ -1,7 +1,7 @@
|
||||
from uuid import UUID
|
||||
|
||||
from models.databases.supabase.prompts import DeletePromptResponse
|
||||
from models.settings import get_supabase_db
|
||||
from models import get_supabase_db
|
||||
|
||||
|
||||
def delete_prompt_by_id(prompt_id: UUID) -> DeletePromptResponse:
|
||||
|
@ -1,7 +1,6 @@
|
||||
from uuid import UUID
|
||||
|
||||
from models.prompt import Prompt
|
||||
from models.settings import get_supabase_db
|
||||
from models import Prompt, get_supabase_db
|
||||
|
||||
|
||||
def get_prompt_by_id(prompt_id: UUID) -> Prompt | None:
|
||||
|
@ -1,5 +1,4 @@
|
||||
from models.prompt import Prompt
|
||||
from models.settings import get_supabase_db
|
||||
from models import Prompt, get_supabase_db
|
||||
|
||||
|
||||
def get_public_prompts() -> list[Prompt]:
|
||||
|
@ -1,8 +1,7 @@
|
||||
from uuid import UUID
|
||||
|
||||
from models.databases.supabase.prompts import PromptUpdatableProperties
|
||||
from models.prompt import Prompt
|
||||
from models.settings import get_supabase_db
|
||||
from models import Prompt, get_supabase_db
|
||||
|
||||
|
||||
def update_prompt_by_id(prompt_id: UUID, prompt: PromptUpdatableProperties) -> Prompt:
|
||||
|
2
backend/repository/user/__init__.py
Normal file
2
backend/repository/user/__init__.py
Normal file
@ -0,0 +1,2 @@
|
||||
from .get_user_email_by_user_id import get_user_email_by_user_id
|
||||
from .get_user_id_by_user_email import get_user_id_by_user_email
|
@ -1,6 +1,6 @@
|
||||
from uuid import UUID
|
||||
|
||||
from models.settings import get_supabase_client
|
||||
from models import get_supabase_client
|
||||
|
||||
|
||||
def get_user_email_by_user_id(user_id: UUID) -> str:
|
||||
|
@ -1,6 +1,6 @@
|
||||
from uuid import UUID
|
||||
|
||||
from models.settings import get_supabase_client
|
||||
from models import get_supabase_client
|
||||
|
||||
|
||||
def get_user_id_by_user_email(email: str) -> UUID:
|
||||
|
3
backend/repository/user_identity/__init__.py
Normal file
3
backend/repository/user_identity/__init__.py
Normal file
@ -0,0 +1,3 @@
|
||||
from .get_user_identity import get_user_identity
|
||||
from .create_user_identity import create_user_identity
|
||||
from .update_user_identity import update_user_identity, UserIdentityUpdatableProperties
|
@ -1,5 +1,4 @@
|
||||
from models.settings import get_supabase_client
|
||||
from models.user_identity import UserIdentity
|
||||
from models import get_supabase_client, UserIdentity
|
||||
|
||||
|
||||
def create_user_identity(user_identity: UserIdentity) -> UserIdentity:
|
||||
|
@ -1,7 +1,6 @@
|
||||
from uuid import UUID
|
||||
|
||||
from models.settings import get_supabase_client
|
||||
from models.user_identity import UserIdentity
|
||||
from models import get_supabase_client, UserIdentity
|
||||
from repository.user_identity.create_user_identity import create_user_identity
|
||||
|
||||
|
||||
|
@ -1,10 +1,9 @@
|
||||
from typing import Optional
|
||||
from uuid import UUID
|
||||
|
||||
from models.settings import get_supabase_client
|
||||
from models.user_identity import UserIdentity
|
||||
from models import get_supabase_client, UserIdentity
|
||||
from pydantic import BaseModel
|
||||
from repository.user_identity.create_user_identity import create_user_identity
|
||||
from repository.user_identity import create_user_identity
|
||||
|
||||
|
||||
class UserIdentityUpdatableProperties(BaseModel):
|
||||
|
@ -6,10 +6,13 @@ from asyncpg.exceptions import UniqueViolationError
|
||||
from auth import AuthBearer, get_current_user
|
||||
from fastapi import APIRouter, Depends
|
||||
from logger import get_logger
|
||||
from models.settings import get_supabase_db
|
||||
from models.users import User
|
||||
|
||||
from models import get_supabase_db, User
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
from models import get_supabase_db, User
|
||||
|
||||
logger = get_logger(__name__)
|
||||
|
||||
|
||||
|
@ -3,8 +3,8 @@ from uuid import UUID
|
||||
|
||||
from auth.auth_bearer import get_current_user
|
||||
from fastapi import Depends, HTTPException, status
|
||||
from models.users import User
|
||||
from repository.brain.get_brain_for_user import get_brain_for_user
|
||||
from models import User
|
||||
from repository.brain import get_brain_for_user
|
||||
|
||||
from routes.authorizations.types import RoleEnum
|
||||
|
||||
|
@ -7,22 +7,20 @@ from models.databases.supabase.brains import (
|
||||
BrainUpdatableProperties,
|
||||
CreateBrainProperties,
|
||||
)
|
||||
from models.settings import BrainRateLimiting
|
||||
from models.users import User
|
||||
from repository.brain.create_brain import create_brain
|
||||
from repository.brain.create_brain_user import create_brain_user
|
||||
from repository.brain.get_brain_details import get_brain_details
|
||||
from repository.brain.get_default_user_brain import get_user_default_brain
|
||||
from repository.brain.get_default_user_brain_or_create_new import (
|
||||
from models import BrainRateLimiting, User
|
||||
|
||||
from repository.brain import (
|
||||
create_brain,
|
||||
get_user_brains,
|
||||
get_brain_details,
|
||||
create_brain_user,
|
||||
update_brain_by_id,
|
||||
get_user_default_brain,
|
||||
set_as_default_brain_for_user,
|
||||
get_default_user_brain_or_create_new,
|
||||
)
|
||||
from repository.brain.get_user_brains import get_user_brains
|
||||
from repository.brain.set_as_default_brain_for_user import (
|
||||
set_as_default_brain_for_user,
|
||||
)
|
||||
from repository.brain.update_brain import update_brain_by_id
|
||||
from repository.prompt.delete_prompt_py_id import delete_prompt_by_id
|
||||
from repository.prompt.get_prompt_by_id import get_prompt_by_id
|
||||
|
||||
from repository.prompt import get_prompt_by_id, delete_prompt_by_id
|
||||
|
||||
from routes.authorizations.brain_authorization import (
|
||||
has_brain_authorization,
|
||||
|
@ -7,6 +7,7 @@ from venv import logger
|
||||
from auth import AuthBearer, get_current_user
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query, Request
|
||||
from fastapi.responses import StreamingResponse
|
||||
from llm.qa_headless import HeadlessQA
|
||||
from llm.openai import OpenAIBrainPicking
|
||||
from llm.qa_headless import HeadlessQA
|
||||
from models.brain_entity import BrainEntity
|
||||
@ -14,15 +15,27 @@ from models.brains import Brain
|
||||
from models.chat import Chat
|
||||
from models.chats import ChatQuestion
|
||||
from models.databases.supabase.supabase import SupabaseDB
|
||||
from models.settings import LLMSettings, get_supabase_db
|
||||
from models.users import User
|
||||
from repository.brain.get_brain_details import get_brain_details
|
||||
from repository.chat.create_chat import CreateChatProperties, create_chat
|
||||
from repository.chat.get_chat_by_id import get_chat_by_id
|
||||
from repository.chat.get_chat_history import GetChatHistoryOutput, get_chat_history
|
||||
from repository.chat.get_user_chats import get_user_chats
|
||||
from repository.chat.update_chat import ChatUpdatableProperties, update_chat
|
||||
from repository.user_identity.get_user_identity import get_user_identity
|
||||
from models import (
|
||||
User,
|
||||
Chat,
|
||||
Brain,
|
||||
LLMSettings,
|
||||
BrainEntity,
|
||||
ChatQuestion,
|
||||
get_supabase_db,
|
||||
)
|
||||
from repository.brain import get_brain_details
|
||||
from repository.chat import (
|
||||
create_chat,
|
||||
update_chat,
|
||||
get_chat_by_id,
|
||||
get_user_chats,
|
||||
get_chat_history,
|
||||
GetChatHistoryOutput,
|
||||
CreateChatProperties,
|
||||
ChatUpdatableProperties,
|
||||
)
|
||||
from repository.user_identity import get_user_identity
|
||||
|
||||
chat_router = APIRouter()
|
||||
|
||||
@ -273,6 +286,11 @@ async def create_stream_question_handler(
|
||||
if brain_id:
|
||||
gpt_answer_generator = OpenAIBrainPicking(
|
||||
chat_id=str(chat_id),
|
||||
<<<<<<< HEAD
|
||||
model=(brain_details or chat_question).model if current_user.user_openai_api_key else "gpt-3.5-turbo",
|
||||
max_tokens=(brain_details or chat_question).max_tokens if current_user.user_openai_api_key else 0,
|
||||
temperature=(brain_details or chat_question).temperature if current_user.user_openai_api_key else 256,
|
||||
=======
|
||||
model=(brain_details or chat_question).model
|
||||
if current_user.user_openai_api_key
|
||||
else "gpt-3.5-turbo",
|
||||
@ -282,12 +300,18 @@ async def create_stream_question_handler(
|
||||
temperature=(brain_details or chat_question).temperature
|
||||
if current_user.user_openai_api_key
|
||||
else 256,
|
||||
>>>>>>> main
|
||||
brain_id=str(brain_id),
|
||||
user_openai_api_key=current_user.user_openai_api_key, # pyright: ignore reportPrivateUsage=none
|
||||
streaming=True,
|
||||
)
|
||||
else:
|
||||
gpt_answer_generator = HeadlessQA(
|
||||
<<<<<<< HEAD
|
||||
model=chat_question.model if current_user.user_openai_api_key else "gpt-3.5-turbo",
|
||||
temperature=chat_question.temperature if current_user.user_openai_api_key else 256,
|
||||
max_tokens=chat_question.max_tokens if current_user.user_openai_api_key else 0,
|
||||
=======
|
||||
model=chat_question.model
|
||||
if current_user.user_openai_api_key
|
||||
else "gpt-3.5-turbo",
|
||||
@ -297,6 +321,7 @@ async def create_stream_question_handler(
|
||||
max_tokens=chat_question.max_tokens
|
||||
if current_user.user_openai_api_key
|
||||
else 0,
|
||||
>>>>>>> main
|
||||
user_openai_api_key=current_user.user_openai_api_key, # pyright: ignore reportPrivateUsage=none
|
||||
chat_id=str(chat_id),
|
||||
streaming=True,
|
||||
|
@ -6,9 +6,7 @@ from uuid import UUID
|
||||
from auth import AuthBearer, get_current_user
|
||||
from crawl.crawler import CrawlWebsite
|
||||
from fastapi import APIRouter, Depends, Query, Request, UploadFile
|
||||
from models.brains import Brain
|
||||
from models.files import File
|
||||
from models.users import User
|
||||
from models import User, Brain, File
|
||||
from parsers.github import process_github
|
||||
from utils.file import convert_bytes
|
||||
from utils.processors import filter_file
|
||||
|
@ -2,9 +2,7 @@ from uuid import UUID
|
||||
|
||||
from auth import AuthBearer, get_current_user
|
||||
from fastapi import APIRouter, Depends, Query
|
||||
from models.brains import Brain
|
||||
from models.settings import get_supabase_db
|
||||
from models.users import User
|
||||
from models import User, get_supabase_db, Brain
|
||||
from routes.authorizations.brain_authorization import (
|
||||
RoleEnum,
|
||||
has_brain_authorization,
|
||||
|
@ -6,11 +6,13 @@ from models.databases.supabase.prompts import (
|
||||
CreatePromptProperties,
|
||||
PromptUpdatableProperties,
|
||||
)
|
||||
from models.prompt import Prompt
|
||||
from repository.prompt.create_prompt import create_prompt
|
||||
from repository.prompt.get_prompt_by_id import get_prompt_by_id
|
||||
from repository.prompt.get_public_prompts import get_public_prompts
|
||||
from repository.prompt.update_prompt_by_id import update_prompt_by_id
|
||||
from models import Prompt
|
||||
from repository.prompt import (
|
||||
create_prompt,
|
||||
get_prompt_by_id,
|
||||
get_public_prompts,
|
||||
update_prompt_by_id,
|
||||
)
|
||||
|
||||
prompt_router = APIRouter()
|
||||
|
||||
|
@ -3,26 +3,21 @@ from uuid import UUID
|
||||
|
||||
from auth.auth_bearer import AuthBearer, get_current_user
|
||||
from fastapi import APIRouter, Depends, HTTPException
|
||||
from models.brains import Brain
|
||||
from models.brains_subscription_invitations import BrainSubscription
|
||||
from models.prompt import PromptStatusEnum
|
||||
from models.users import User
|
||||
from models import User, BrainSubscription, Brain, PromptStatusEnum
|
||||
from pydantic import BaseModel
|
||||
from repository.brain.create_brain_user import create_brain_user
|
||||
from repository.brain.get_brain_by_id import get_brain_by_id
|
||||
from repository.brain.get_brain_details import get_brain_details
|
||||
from repository.brain.get_brain_for_user import get_brain_for_user
|
||||
from repository.brain.update_user_rights import update_brain_user_rights
|
||||
from repository.brain_subscription.resend_invitation_email import (
|
||||
from repository.brain import (
|
||||
get_brain_by_id,
|
||||
create_brain_user,
|
||||
get_brain_details,
|
||||
get_brain_for_user,
|
||||
update_brain_user_rights,
|
||||
)
|
||||
from repository.brain_subscription import (
|
||||
SubscriptionInvitationService,
|
||||
resend_invitation_email,
|
||||
)
|
||||
from repository.brain_subscription.subscription_invitation_service import (
|
||||
SubscriptionInvitationService,
|
||||
)
|
||||
from repository.prompt.delete_prompt_py_id import delete_prompt_by_id
|
||||
from repository.prompt.get_prompt_by_id import get_prompt_by_id
|
||||
from repository.user.get_user_email_by_user_id import get_user_email_by_user_id
|
||||
from repository.user.get_user_id_by_user_email import get_user_id_by_user_email
|
||||
from repository.prompt import delete_prompt_by_id, get_prompt_by_id
|
||||
from repository.user import get_user_id_by_user_email, get_user_email_by_user_id
|
||||
from routes.authorizations.brain_authorization import (
|
||||
RoleEnum,
|
||||
has_brain_authorization,
|
||||
|
@ -3,11 +3,9 @@ from uuid import UUID
|
||||
|
||||
from auth import AuthBearer, get_current_user
|
||||
from fastapi import APIRouter, Depends, Query, Request, UploadFile
|
||||
from models.brains import Brain
|
||||
from models.files import File
|
||||
from models.users import User
|
||||
from repository.brain.get_brain_details import get_brain_details
|
||||
from repository.user_identity.get_user_identity import get_user_identity
|
||||
from models import User, File, Brain
|
||||
from repository.brain import get_brain_details
|
||||
from repository.user_identity import get_user_identity
|
||||
from routes.authorizations.brain_authorization import (
|
||||
RoleEnum,
|
||||
validate_brain_authorization,
|
||||
|
@ -3,15 +3,12 @@ import time
|
||||
|
||||
from auth import AuthBearer, get_current_user
|
||||
from fastapi import APIRouter, Depends, Request
|
||||
from models.brains import Brain
|
||||
from models.settings import BrainRateLimiting
|
||||
from models.user_identity import UserIdentity
|
||||
from models.users import User
|
||||
from repository.brain.get_default_user_brain import get_user_default_brain
|
||||
from repository.user_identity.get_user_identity import get_user_identity
|
||||
from repository.user_identity.update_user_identity import (
|
||||
from models import User, Brain, BrainRateLimiting, UserIdentity
|
||||
from repository.brain import get_user_default_brain
|
||||
from repository.user_identity import (
|
||||
UserIdentityUpdatableProperties,
|
||||
update_user_identity,
|
||||
get_user_identity,
|
||||
)
|
||||
|
||||
user_router = APIRouter()
|
||||
|
@ -2,9 +2,9 @@ from concurrent.futures import ThreadPoolExecutor
|
||||
from typing import List
|
||||
|
||||
from langchain.embeddings.openai import OpenAIEmbeddings
|
||||
from pydantic import BaseModel
|
||||
from logger import get_logger
|
||||
from models.settings import get_documents_vector_store, get_embeddings, get_supabase_db
|
||||
from pydantic import BaseModel
|
||||
|
||||
logger = get_logger(__name__)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user