Skip to content

Commit

Permalink
Merge branch 'pinterest:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
aidenprice authored Mar 6, 2024
2 parents 64900e3 + e313560 commit e9e8cd9
Show file tree
Hide file tree
Showing 47 changed files with 555 additions and 581 deletions.
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ RUN pip install -r requirements/base.txt \
pip install -r requirements/${PACKAGE}; \
done \
fi \
&& pip install -r requirements/local.txt || true
&& if [ -f requirements/local.txt ]; then \
pip install -r requirements/local.txt; \
fi

COPY package.json yarn.lock ./
RUN yarn install --pure-lockfile
Expand Down
7 changes: 7 additions & 0 deletions docs_website/docs/changelog/breaking_change.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ slug: /changelog

Here are the list of breaking changes that you should be aware of when updating Querybook:

## v3.31.0

Upgraded langchain to [0.1.6](https://blog.langchain.dev/langchain-v0-1-0/).

- Some langchain packages are imported from different paths, e.g. `PromptTemplate` is now from `langchain.prompts`
- Removed `StreamingWebsocketCallbackHandler` to adopt the new streaming approach.

## v3.29.0

Made below changes for `S3BaseExporter` (csv table uploader feature):
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "querybook",
"version": "3.29.0",
"version": "3.31.2",
"description": "A Big Data Webapp",
"private": true,
"scripts": {
Expand Down Expand Up @@ -50,6 +50,7 @@
"core-js": "^3.19.1",
"cron-parser": "^4.7.0",
"dagre": "^0.8.5",
"dompurify": "^3.0.9",
"draft-js": "0.11.7",
"draft-js-export-html": "^1.4.1",
"draft-js-import-html": "^1.4.1",
Expand Down
4 changes: 3 additions & 1 deletion querybook/config/querybook_default_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ FLASK_SECRET_KEY: ~
# Url of the querybook site, used for auth callback and notifications
PUBLIC_URL: ''
# Use this config to set cache policy of flask, see https://pythonhosted.org/Flask-Cache/ for details
FLASK_CACHE_CONFIG: '{"CACHE_TYPE": "simple"}'
FLASK_CACHE_CONFIG:
CACHE_TYPE: 'simple'

# --------------- Celery ---------------
REDIS_URL: ~
Expand Down Expand Up @@ -92,6 +93,7 @@ AI_ASSISTANT_CONFIG:
model_args:
model_name: ~
temperature: ~
streaming: ~
reserved_tokens: ~

EMBEDDINGS_PROVIDER: ~
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
"""allow unique_table_ownership per type
Revision ID: 299e24dcfd29
Revises: c00f08f16065
Create Date: 2024-01-31 14:39:13.601013
"""

from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import mysql

# revision identifiers, used by Alembic.
revision = "299e24dcfd29"
down_revision = "c00f08f16065"
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
ownership_table = sa.Table(
"data_table_ownership", sa.MetaData(op.get_bind()), autoload=True
)

for constraint in ownership_table.foreign_key_constraints:
op.drop_constraint(constraint.name, "data_table_ownership", type_="foreignkey")

op.drop_constraint("unique_table_ownership", "data_table_ownership", type_="unique")

op.create_foreign_key(
"data_table_ownership_data_table_id_fk",
"data_table_ownership",
"data_table",
["data_table_id"],
["id"],
ondelete="CASCADE",
)
op.create_foreign_key(
"data_table_ownership_uid_fk",
"data_table_ownership",
"user",
["uid"],
["id"],
ondelete="CASCADE",
)
op.create_unique_constraint(
"unique_table_ownership",
"data_table_ownership",
["data_table_id", "uid", "type"],
)
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
ownership_table = sa.Table(
"data_table_ownership", sa.MetaData(op.get_bind()), autoload=True
)

for constraint in ownership_table.foreign_key_constraints:
op.drop_constraint(constraint.name, "data_table_ownership", type_="foreignkey")

op.drop_constraint("unique_table_ownership", "data_table_ownership", type_="unique")

op.create_foreign_key(
"data_table_ownership_data_table_id_fk",
"data_table_ownership",
"data_table",
["data_table_id"],
["id"],
ondelete="CASCADE",
)
op.create_foreign_key(
"data_table_ownership_uid_fk",
"data_table_ownership",
"user",
["uid"],
["id"],
ondelete="CASCADE",
)
op.create_unique_constraint(
"unique_table_ownership",
"data_table_ownership",
["data_table_id", "uid"],
)
# ### end Alembic commands ###
19 changes: 17 additions & 2 deletions querybook/server/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@ class MissingConfigException(Exception):
pass


def is_json(value):
"""
Check if a given value is a valid JSON serialized dict or list
"""
try:
parsed = json.loads(value)
return isinstance(parsed, (dict, list))
except ValueError:
return False


def get_env_config(name, optional=True):
found = True
val = None
Expand All @@ -32,6 +43,9 @@ def get_env_config(name, optional=True):
raise MissingConfigException(
"{} is required to start the process.".format(name)
)
# Check for string-serialized JSON dicts/lists
if isinstance(val, str) and is_json(val):
val = json.loads(val)
return val


Expand All @@ -40,7 +54,8 @@ class QuerybookSettings(object):
PRODUCTION = os.environ.get("production", "false") == "true"
PUBLIC_URL = get_env_config("PUBLIC_URL")
FLASK_SECRET_KEY = get_env_config("FLASK_SECRET_KEY", optional=False)
FLASK_CACHE_CONFIG = json.loads(get_env_config("FLASK_CACHE_CONFIG"))
FLASK_CACHE_CONFIG = get_env_config("FLASK_CACHE_CONFIG")

# Celery
REDIS_URL = get_env_config("REDIS_URL", optional=False)

Expand Down Expand Up @@ -117,7 +132,7 @@ class QuerybookSettings(object):

DB_MAX_UPLOAD_SIZE = int(get_env_config("DB_MAX_UPLOAD_SIZE"))

GOOGLE_CREDS = json.loads(get_env_config("GOOGLE_CREDS") or "null")
GOOGLE_CREDS = get_env_config("GOOGLE_CREDS")

# Logging
LOG_LOCATION = get_env_config("LOG_LOCATION")
Expand Down
6 changes: 0 additions & 6 deletions querybook/server/lib/ai_assistant/ai_socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,6 @@ def _send(self, event_type, payload: dict = None):
def send_data(self, data: dict):
self._send("data", data)

def send_delta_data(self, data: str):
self._send("delta_data", data)

def send_delta_end(self):
self._send("delta_end")

def send_tables_for_sql_gen(self, data: list[str]):
self._send("tables", data)

Expand Down
16 changes: 4 additions & 12 deletions querybook/server/lib/ai_assistant/assistants/openai_assistant.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import openai
import tiktoken
from langchain.callbacks.manager import CallbackManager
from langchain.chat_models import ChatOpenAI
from langchain_openai import ChatOpenAI

from lib.ai_assistant.base_ai_assistant import BaseAIAssistant
from lib.logger import get_logger
Expand Down Expand Up @@ -46,19 +45,12 @@ def _get_token_count(self, ai_command: str, prompt: str) -> int:
return len(encoding.encode(prompt))

def _get_error_msg(self, error) -> str:
if isinstance(error, openai.error.AuthenticationError):
if isinstance(error, openai.AuthenticationError):
return "Invalid OpenAI API key"

return super()._get_error_msg(error)

def _get_llm(self, ai_command: str, prompt_length: int, callback_handler=None):
def _get_llm(self, ai_command: str, prompt_length: int):
config = self._get_llm_config(ai_command)
if not callback_handler:
# non-streaming
return ChatOpenAI(**config)

return ChatOpenAI(
**config,
streaming=True,
callback_manager=CallbackManager([callback_handler])
)
return ChatOpenAI(**config)
Loading

0 comments on commit e9e8cd9

Please sign in to comment.