Skip to content

Commit

Permalink
feat/Enable file upload in chat window (#187)
Browse files Browse the repository at this point in the history
* feat: Add file uploader in chat interface.
* chore: Add manage documents for chat uploads.
* feat: Create thread space for thread uploads.
* fix: 'Empty Response' for consercutive shared asks.
* chore: Setup spaces table DB migration script.
* chore: Create a new layout for document lists.
* refactor(UI): move "New chat" button to the bottom of the screen.
* refactor(UI): Add a spinner when indexing thread space.

* bump version v0.7.4 -> v0.7.5

---------
Co-authored-by: Janaka Abeywardhana <[email protected]>
  • Loading branch information
osala-eng authored Jan 20, 2024
1 parent 677c71d commit cc903d9
Show file tree
Hide file tree
Showing 21 changed files with 607 additions and 150 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "docq"
version = "0.7.4"
version = "0.7.5"
description = "Docq.AI - private and secure knowledge insight on your data."
authors = ["Docq.AI Team <[email protected]>"]
maintainers = ["Docq.AI Team <[email protected]>"]
Expand Down
1 change: 1 addition & 0 deletions source/docq/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class SpaceType(Enum):
PERSONAL = "personal"
SHARED = "shared"
PUBLIC = "public"
THREAD = "thread"


class SystemFeatureType(Enum):
Expand Down
1 change: 0 additions & 1 deletion source/docq/data_source/knowledge_base_scraper.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Data source for scrapping articles from a knowledge base."""

import logging as log
from typing import List

from ..domain import ConfigKey, SpaceKey
Expand Down
2 changes: 1 addition & 1 deletion source/docq/data_source/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from abc import ABC, abstractmethod
from dataclasses import asdict
from enum import Enum
from typing import Any, Callable, List, Literal, Self
from typing import List, Self

from llama_index import Document
from opentelemetry import trace
Expand Down
2 changes: 0 additions & 2 deletions source/docq/data_source/manual_upload.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
"""Data source for documents uploaded manually."""

import logging
import os
from datetime import datetime
from typing import List

from llama_index import Document, SimpleDirectoryReader
from opentelemetry import trace

from ..domain import ConfigKey, DocumentListItem, SpaceKey
from ..support.store import get_upload_dir
Expand Down
79 changes: 79 additions & 0 deletions source/docq/db_migrations.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
"""Database migration scripts for schema changes etc."""

import logging
import sqlite3
from contextlib import closing

from opentelemetry import trace

import docq
from docq.support.store import SpaceType, get_sqlite_system_file

tracer = trace.get_tracer(__name__, docq.__version_str__)


@tracer.start_as_current_span("db_migrations.run")
def run() -> None:
"""Run database migrations.
Call this after all tables are created.
"""
migration_sample1()
add_space_type_to_spaces_table()


def migration_sample1() -> None:
"""Sample migration script."""
with tracer.start_as_current_span("migration_sample") as span:
try:
logging.info("Running migration sample")
span.add_event("Running migration sample")
# do some migration work
logging.info("Migration sample complete successfully")
span.set_attribute("migration_successful", "true")
except Exception as e:
logging.error("Migration XYZ sample failed")
span.set_status(trace.Status(trace.StatusCode.ERROR, "Migration sample failed"))
span.record_exception(e)
raise Exception("Migration XYZ failed") from e


def add_space_type_to_spaces_table() -> None:
"""Add space_type column to spaces table.
Check if space_type column exists in spaces table. if exists log and return.
Create space_type column in spaces table with parameter space_type TEXT NOT NULL.
UPDATE spaces SET space_type = SpaceType.SHARED.name for all existing rows.
"""
with tracer.start_as_current_span("add_space_type_to_spaces_table") as span:
try:
span.add_event("Running migration add_space_type_to_spaces_table")
logging.info("Running migration add_space_type_to_spaces_table")

with closing(sqlite3.connect(get_sqlite_system_file())) as connection, closing(connection.cursor()) as cursor:
cursor.execute("SELECT name FROM pragma_table_info('spaces') WHERE name = 'space_type'")

if cursor.fetchone() is None:
logging.info("db_migrations.add_space_type_to_spaces_table, space_type column does not exist, adding it")
span.add_event("space_type column does not exist, adding it")
try:
cursor.execute("BEGIN TRANSACTION")
cursor.execute("ALTER TABLE spaces ADD COLUMN space_type TEXT NOT NULL DEFAULT '" + SpaceType.SHARED.name + "'",)
connection.commit()
logging.info("db_migrations.add_space_type_to_spaces_table, space_type column added successfully")
span.add_event("space_type column added successfully")
span.set_attribute("migration_successful", "true")

except sqlite3.Error as e:
logging.error("db_migrations.add_space_type_to_spaces_table, failed to add space_type column to spaces table %s", e)
span.set_status(trace.Status(trace.StatusCode.ERROR, "Migration add_space_type_to_spaces_table failed"))
span.set_attribute("migration_successful", "false")
span.record_exception(e)
connection.rollback()

except Exception as e:
logging.error("Migration add_space_type_to_spaces_table failed")
span.set_status(trace.Status(trace.StatusCode.ERROR, "Migration add_space_type_to_spaces_table failed"))
span.record_exception(e)
raise Exception("Migration add_space_type_to_spaces_table failed") from e
3 changes: 1 addition & 2 deletions source/docq/manage_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import logging as log
import sqlite3
from contextlib import closing
from typing import Any, Optional
from typing import Optional

from opentelemetry import trace

Expand All @@ -23,7 +23,6 @@
SystemSettingsKey,
UserSettingsKey,
)
from .constants import DEFAULT_ORG_ID
from .support.store import get_sqlite_system_file, get_sqlite_usage_file

tracer = trace.get_tracer(__name__, docq.__version_str__)
Expand Down
Loading

0 comments on commit cc903d9

Please sign in to comment.