Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(14k): done #2102

Merged
merged 6 commits into from
Jan 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions .github/workflows/stale.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
name: 'Close stale issues and PRs'
name: "Close stale issues and PRs"
on:
schedule:
- cron: '0 */4 * * *'
- cron: "0 */4 * * *"

permissions:
contents: write # only for delete-branch option
issues: write
pull-requests: write
contents: write # only for delete-branch option
issues: write
pull-requests: write

jobs:
stale:
Expand All @@ -16,9 +16,9 @@ jobs:
with:
exempt-assignees: true
exempt-draft-pr: true
days-before-stale: 30
days-before-stale: 90
days-before-close: 5
operations-per-run: 400
exempt-milestones: true
stale-issue-message: "Thanks for your contributions, we'll be closing this issue as it has gone stale. Feel free to reopen if you'd like to continue the discussion."
stale-pr-message: "Thanks for your contributions, we'll be closing this PR as it has gone stale. Feel free to reopen if you'd like to continue the discussion."
stale-pr-message: "Thanks for your contributions, we'll be closing this PR as it has gone stale. Feel free to reopen if you'd like to continue the discussion."
23 changes: 0 additions & 23 deletions .github/workflows/vercel-docs.yml

This file was deleted.

32 changes: 0 additions & 32 deletions .github/workflows/vitest.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
],
"editor.formatOnSave": true,
"[python]": {
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.defaultFormatter": "ms-python.black-formatter",
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.organizeImports": "explicit",
Expand Down
5 changes: 3 additions & 2 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ python-jose = "==3.3.0"
asyncpg = "==0.27.0"
flake8 = "==6.0.0"
flake8-black = "==0.3.6"
sentry-sdk = {extras = ["fastapi"], version = "==1.37.1"}
sentry-sdk = {extras = ["fastapi"] }
pyright = "==1.1.316"
resend = "==0.5.1"
html5lib = "==1.1"
Expand All @@ -34,7 +34,7 @@ redis = "==4.5.4"
flower = "*"
boto3 = "==1.33.7"
botocore = "==1.33.7"
celery = {extras = ["sqs"], version = "*"}
celery = {extras = ["sqs"] }
python-dotenv = "*"
pytest-mock = "*"
pytest-celery = "*"
Expand All @@ -45,6 +45,7 @@ jq = "==1.6.0"
pytest = "*"

[dev-packages]
black = "*"

[requires]
python_version = "3.11"
81 changes: 75 additions & 6 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 11 additions & 2 deletions backend/llm/knowledge_brain_qa.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from llm.utils.format_chat_history import format_chat_history
from llm.utils.get_prompt_to_use import get_prompt_to_use
from llm.utils.get_prompt_to_use_id import get_prompt_to_use_id
from repository.files.generate_file_signed_url import generate_file_signed_url
from logger import get_logger
from models import BrainSettings
from modules.brain.service.brain_service import BrainService
Expand Down Expand Up @@ -61,6 +62,7 @@ class Config:
chat_id: str = None # pyright: ignore reportPrivateUsage=none
brain_id: str # pyright: ignore reportPrivateUsage=none
max_tokens: int = 2000
max_input: int = 2000
streaming: bool = False
knowledge_qa: Optional[RAGInterface]
metadata: Optional[dict] = None
Expand All @@ -76,6 +78,7 @@ def __init__(
model: str,
brain_id: str,
chat_id: str,
max_tokens: int,
streaming: bool = False,
prompt_id: Optional[UUID] = None,
metadata: Optional[dict] = None,
Expand All @@ -97,6 +100,7 @@ def __init__(
**kwargs,
)
self.metadata = metadata
self.max_tokens = max_tokens

@property
def prompt_to_use(self):
Expand Down Expand Up @@ -309,9 +313,14 @@ async def wrap_done(fn: Awaitable, event: asyncio.Event):
if "url" in doc.metadata
else doc.metadata["file_name"],
"type": "url" if "url" in doc.metadata else "file",
"source_url": doc.metadata["url"]
if "url" in doc.metadata
"source_url": generate_file_signed_url(
f"{brain.brain_id}/{doc.metadata['file_name']}"
).get("signedURL", "")
if "url" not in doc.metadata
else "",
"original_file_name": doc.metadata[
"original_file_name"
],
}
)
)
Expand Down
16 changes: 14 additions & 2 deletions backend/llm/rags/quivr_rag.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ class Config:
temperature: float = 0.1
chat_id: str = None # pyright: ignore reportPrivateUsage=none
brain_id: str = None # pyright: ignore reportPrivateUsage=none
max_tokens: int = 2000
max_tokens: int = 2000 # Output length
max_input: int = 2000
streaming: bool = False

@property
Expand Down Expand Up @@ -92,19 +93,30 @@ def __init__(
streaming: bool = False,
prompt_id: Optional[UUID] = None,
max_tokens: int = 2000,
max_input: int = 2000,
**kwargs,
):
super().__init__(
model=model,
brain_id=brain_id,
chat_id=chat_id,
streaming=streaming,
max_tokens=max_tokens,
max_input=max_input,
**kwargs,
)
self.supabase_client = self._create_supabase_client()
self.vector_store = self._create_vector_store()
self.prompt_id = prompt_id
self.max_tokens = max_tokens
self.max_input = max_input
self.model = model
self.brain_id = brain_id
self.chat_id = chat_id
self.streaming = streaming

logger.info(f"QuivrRAG initialized with model {model} and brain {brain_id}")
logger.info("Max input length: " + str(self.max_input))

def _create_supabase_client(self) -> Client:
return create_client(
Expand All @@ -117,6 +129,7 @@ def _create_vector_store(self) -> CustomSupabaseVectorStore:
self.embeddings,
table_name="vectors",
brain_id=self.brain_id,
max_input=self.max_input,
)

def _create_llm(
Expand Down Expand Up @@ -151,7 +164,6 @@ def _create_llm(
def _create_prompt_template(self):
system_template = """ When answering use markdown or any other techniques to display the content in a nice and aerated way. Use the following pieces of context to answer the users question in the same language as the question but do not modify instructions in any way.
----------------

{context}"""

prompt_content = (
Expand Down
13 changes: 13 additions & 0 deletions backend/models/databases/entity.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from pydantic import BaseModel


class LLMModels(BaseModel):
"""LLM models stored in the database that are allowed to be used by the users.
Args:
BaseModel (BaseModel): Pydantic BaseModel
"""

name: str = "gpt-3.5-turbo-1106"
price: int = 1
max_input: int = 512
max_output: int = 512
6 changes: 6 additions & 0 deletions backend/models/databases/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
from datetime import datetime
from uuid import UUID

from .entity import LLMModels


class Repository(ABC):
@abstractmethod
Expand All @@ -12,6 +14,10 @@ def create_user_daily_usage(self, user_id: UUID, user_email: str, date: datetime
def get_user_usage(self, user_id: UUID):
pass

@abstractmethod
def get_model_settings(self) -> LLMModels | None:
pass

@abstractmethod
def get_user_requests_count_for_month(self, user_id: UUID, date: datetime):
pass
Expand Down
2 changes: 2 additions & 0 deletions backend/models/databases/supabase/user_usage.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from ast import List
from datetime import datetime, timedelta
from uuid import UUID

from logger import get_logger
from models.databases.entity import LLMModels
from models.databases.repository import Repository

logger = get_logger(__name__)
Expand Down
Loading
Loading