-
Notifications
You must be signed in to change notification settings - Fork 238
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add embedding based table search support
- Loading branch information
Showing
43 changed files
with
1,334 additions
and
559 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
ALL_PLUGIN_VECTOR_STORES = {} | ||
ALL_PLUGIN_EMBEDDINGS = {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,32 @@ | ||
from const.ai_assistant import ( | ||
AI_ASSISTANT_NAMESPACE, | ||
AI_ASSISTANT_REQUEST_EVENT, | ||
) | ||
from const.ai_assistant import AI_ASSISTANT_NAMESPACE, AICommandType | ||
from lib.ai_assistant import ai_assistant | ||
|
||
from .helper import register_socket | ||
|
||
|
||
@register_socket(AI_ASSISTANT_REQUEST_EVENT, namespace=AI_ASSISTANT_NAMESPACE) | ||
def ai_assistant_request(command_type: str, payload={}): | ||
from lib.ai_assistant import ai_assistant | ||
@register_socket(AICommandType.TEXT_TO_SQL.value, namespace=AI_ASSISTANT_NAMESPACE) | ||
def text_to_sql(payload={}): | ||
original_query = payload["original_query"] | ||
query_engine_id = payload["query_engine_id"] | ||
tables = payload.get("tables") | ||
question = payload["question"] | ||
ai_assistant.generate_sql_query( | ||
query_engine_id=query_engine_id, | ||
tables=tables, | ||
question=question, | ||
original_query=original_query, | ||
) | ||
|
||
ai_assistant.handle_ai_command(command_type, payload) | ||
|
||
@register_socket(AICommandType.SQL_TITLE.value, namespace=AI_ASSISTANT_NAMESPACE) | ||
def sql_title(payload={}): | ||
query = payload["query"] | ||
ai_assistant.generate_title_from_query(query=query) | ||
|
||
|
||
@register_socket(AICommandType.SQL_FIX.value, namespace=AI_ASSISTANT_NAMESPACE) | ||
def sql_fix(payload={}): | ||
query_execution_id = payload["query_execution_id"] | ||
ai_assistant.query_auto_fix( | ||
query_execution_id=query_execution_id, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import functools | ||
|
||
from flask import request | ||
|
||
from app.flask_app import socketio | ||
from const.ai_assistant import AI_ASSISTANT_NAMESPACE, AICommandType | ||
|
||
|
||
class AIWebSocket: | ||
def __init__(self, socketio, command_type: AICommandType): | ||
self.socketio = socketio | ||
self.command_type = command_type | ||
self.room = request.sid | ||
|
||
def _send(self, event_type, payload: dict = None): | ||
self.socketio.emit( | ||
self.command_type.value, | ||
( | ||
event_type, | ||
payload, | ||
), | ||
namespace=AI_ASSISTANT_NAMESPACE, | ||
room=self.room, | ||
) | ||
|
||
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(self, data: list[str]): | ||
self._send("tables", data) | ||
|
||
def send_error(self, error: str): | ||
self._send("error", error) | ||
self.close() | ||
|
||
def close(self): | ||
self._send("close") | ||
|
||
|
||
def with_ai_socket(command_type: AICommandType): | ||
def decorator_fn(fn): | ||
@functools.wraps(fn) | ||
def func(*args, **kwargs): | ||
if not kwargs.get("socket"): | ||
kwargs["socket"] = AIWebSocket(socketio, command_type) | ||
|
||
result = fn(*args, **kwargs) | ||
|
||
return result | ||
|
||
return func | ||
|
||
return decorator_fn |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.