feat(model): Add new LLMClient and new build tools (#967)

This commit is contained in:
Fangyin Cheng
2023-12-23 16:33:01 +08:00
committed by GitHub
parent 12234ae258
commit 0c46c339ca
30 changed files with 1072 additions and 133 deletions

View File

@@ -1,7 +1,6 @@
from __future__ import annotations
import sqlparse
import regex as re
import pandas as pd
from urllib.parse import quote
from urllib.parse import quote_plus as urlquote
from typing import Any, Iterable, List, Optional, Dict
@@ -383,6 +382,10 @@ class RDBMSDatabase(BaseConnect):
return self.get_simple_fields(table_name)
def run_to_df(self, command: str, fetch: str = "all"):
import pandas as pd
# Pandas has too much dependence and the import time is too long
# TODO: Remove the dependency on pandas
result_lst = self.run(command, fetch)
colunms = result_lst[0]
values = result_lst[1:]

View File

@@ -1,13 +1,8 @@
import re
import sqlparse
import clickhouse_connect
from typing import List, Optional, Any, Iterable, Dict
from sqlalchemy import text
from urllib.parse import quote
from sqlalchemy.schema import CreateTable
from urllib.parse import quote_plus as urlquote
from dbgpt.datasource.rdbms.base import RDBMSDatabase
from clickhouse_connect.driver import httputil
from dbgpt.storage.schema import DBType
from sqlalchemy import (
MetaData,
@@ -56,6 +51,11 @@ class ClickhouseConnect(RDBMSDatabase):
engine_args: Optional[dict] = None,
**kwargs: Any,
) -> RDBMSDatabase:
import clickhouse_connect
from clickhouse_connect.driver import httputil
# Lazy import
big_pool_mgr = httputil.get_pool_manager(maxsize=16, num_pools=12)
client = clickhouse_connect.get_client(
host=host,

View File

@@ -37,7 +37,14 @@ class SQLiteConnect(RDBMSDatabase):
"""Get table indexes about specified table."""
cursor = self.session.execute(text(f"PRAGMA index_list({table_name})"))
indexes = cursor.fetchall()
return [(index[1], index[3]) for index in indexes]
result = []
for idx in indexes:
index_name = idx[1]
cursor = self.session.execute(text(f"PRAGMA index_info({index_name})"))
index_infos = cursor.fetchall()
column_names = [index_info[2] for index_info in index_infos]
result.append({"name": index_name, "column_names": column_names})
return result
def get_show_create_table(self, table_name):
"""Get table show create table about specified table."""

View File

@@ -47,7 +47,8 @@ def test_run_no_throw(db):
def test_get_indexes(db):
db.run("CREATE TABLE test (name TEXT);")
db.run("CREATE INDEX idx_name ON test(name);")
assert db.get_indexes("test") == [("idx_name", "c")]
indexes = db.get_indexes("test")
assert indexes == [{"name": "idx_name", "column_names": ["name"]}]
def test_get_indexes_empty(db):