Skip to content

Commit

Permalink
Add mssql support (#3985)
Browse files Browse the repository at this point in the history
some thing
-  execsql  add connection mssql
- fix bug duckduckgo-search rate limit
- update typo vi res

---------

Co-authored-by: Kevin Hu <[email protected]>
  • Loading branch information
isthaison and KevinHuSh authored Dec 12, 2024
1 parent e8d7410 commit d6c74ff
Show file tree
Hide file tree
Showing 10 changed files with 440 additions and 319 deletions.
12 changes: 10 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,16 @@ RUN --mount=type=cache,id=ragflow_apt,target=/var/cache/apt,sharing=locked \
apt purge -y nodejs npm && \
apt autoremove && \
apt update && \
apt install -y nodejs cargo
apt install -y nodejs cargo

# Add msssql17
RUN --mount=type=cache,id=ragflow_apt,target=/var/cache/apt,sharing=locked \
curl https://packages.microsoft.com/keys/microsoft.asc | tee /etc/apt/trusted.gpg.d/microsoft.asc && \
curl https://packages.microsoft.com/config/ubuntu/22.04/prod.list | tee /etc/apt/sources.list.d/mssql-release.list && \
apt update && \
ACCEPT_EULA=Y apt install -y unixodbc-dev msodbcsql17



# Add dependencies of selenium
RUN --mount=type=bind,from=infiniflow/ragflow_deps:latest,source=/chrome-linux64-121-0-6167-85,target=/chrome-linux64.zip \
Expand Down Expand Up @@ -170,5 +179,4 @@ RUN chmod +x ./entrypoint.sh
COPY --from=builder /ragflow/web/dist /ragflow/web/dist

COPY --from=builder /ragflow/VERSION /ragflow/VERSION

ENTRYPOINT ["./entrypoint.sh"]
13 changes: 11 additions & 2 deletions agent/component/exesql.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import pymysql
import psycopg2
from agent.component.base import ComponentBase, ComponentParamBase
import pyodbc


class ExeSQLParam(ComponentParamBase):
Expand All @@ -38,7 +39,7 @@ def __init__(self):
self.top_n = 30

def check(self):
self.check_valid_value(self.db_type, "Choose DB type", ['mysql', 'postgresql', 'mariadb'])
self.check_valid_value(self.db_type, "Choose DB type", ['mysql', 'postgresql', 'mariadb', 'mssql'])
self.check_empty(self.database, "Database name")
self.check_empty(self.username, "database username")
self.check_empty(self.host, "IP Address")
Expand Down Expand Up @@ -77,7 +78,15 @@ def _run(self, history, **kwargs):
elif self._param.db_type == 'postgresql':
db = psycopg2.connect(dbname=self._param.database, user=self._param.username, host=self._param.host,
port=self._param.port, password=self._param.password)

elif self._param.db_type == 'mssql':
conn_str = (
r'DRIVER={ODBC Driver 17 for SQL Server};'
r'SERVER=' + self._param.host + ',' + str(self._param.port) + ';'
r'DATABASE=' + self._param.database + ';'
r'UID=' + self._param.username + ';'
r'PWD=' + self._param.password
)
db = pyodbc.connect(conn_str)
try:
cursor = db.cursor()
except Exception as e:
Expand Down
20 changes: 19 additions & 1 deletion api/apps/canvas_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,26 @@ def test_db_connect():
elif req["db_type"] == 'postgresql':
db = PostgresqlDatabase(req["database"], user=req["username"], host=req["host"], port=req["port"],
password=req["password"])
db.connect()
elif req["db_type"] == 'mssql':
import pyodbc
connection_string = (
f"DRIVER={{ODBC Driver 17 for SQL Server}};"
f"SERVER={req['host']},{req['port']};"
f"DATABASE={req['database']};"
f"UID={req['username']};"
f"PWD={req['password']};"
)
db = pyodbc.connect(connection_string)
cursor = db.cursor()
cursor.execute("SELECT 1")
cursor.close()
else:
return server_error_response("Unsupported database type.")
if req["db_type"] != 'mssql':
db.connect()
db.close()

return get_json_result(data="Database Connection Successful!")
except Exception as e:
return server_error_response(e)

667 changes: 365 additions & 302 deletions poetry.lock

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ dashscope = "1.20.11"
deepl = "1.18.0"
demjson3 = "3.0.6"
discord-py = "2.3.2"
duckduckgo-search = "6.1.9"
duckduckgo-search = "6.4.1"
editdistance = "0.8.1"
elastic-transport = "8.12.0"
elasticsearch = "8.12.1"
Expand Down Expand Up @@ -117,6 +117,7 @@ pypdf2 = "^3.0.1"
graspologic = "^3.4.1"
pymysql = "^1.1.1"
mini-racer = "^0.12.4"
pyodbc = "^5.2.0"
pyicu = "^2.13.1"
flasgger = "^0.9.7.1"
polars = { version = "^1.9.0", markers = "platform_machine == 'x86_64'" }
Expand Down
12 changes: 10 additions & 2 deletions web/src/locales/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,18 @@ const enFlattened = flattenObject(translation_en);
const viFlattened = flattenObject(translation_vi);
const esFlattened = flattenObject(translation_es);
const zhFlattened = flattenObject(translation_zh);
const jaFlattened = flattenObject(translation_ja);
const zh_traditionalFlattened = flattenObject(translation_zh_traditional);
export const translationTable = createTranslationTable(
[enFlattened, viFlattened, esFlattened, zhFlattened, zh_traditionalFlattened],
['English', 'Vietnamese', 'Spanish', 'zh', 'zh-TRADITIONAL'],
[
enFlattened,
viFlattened,
esFlattened,
zhFlattened,
zh_traditionalFlattened,
jaFlattened,
],
['English', 'Vietnamese', 'Spanish', 'zh', 'zh-TRADITIONAL', 'ja'],
);
i18n
.use(initReactI18next)
Expand Down
6 changes: 3 additions & 3 deletions web/src/locales/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,8 @@ The above is the content you need to summarize.`,
setAnOpenerTip: 'Set an opening greeting for users.',
knowledgeBases: 'Knowledge bases',
knowledgeBasesMessage: 'Please select',
knowledgeBasesTip: 'Select the knowledge bases to associate with this chat assistant.',
knowledgeBasesTip:
'Select the knowledge bases to associate with this chat assistant.',
system: 'System',
systemInitialValue: `You are an intelligent assistant. Please summarize the content of the knowledge base to answer the question. Please list the data in the knowledge base and answer in detail. When all knowledge base content is irrelevant to the question, your answer must include the sentence "The answer you are looking for is not found in the knowledge base!" Answers need to consider chat history.
Here is the knowledge base:
Expand Down Expand Up @@ -455,8 +456,7 @@ The above is the content you need to summarize.`,
profileDescription: 'Update your photo and personal details here.',
maxTokens: 'Max Tokens',
maxTokensMessage: 'Max Tokens is required',
maxTokensTip:
`This sets the maximum length of the model's output, measured in the number of tokens (words or pieces of words).`,
maxTokensTip: `This sets the maximum length of the model's output, measured in the number of tokens (words or pieces of words).`,
maxTokensInvalidMessage: 'Please enter a valid number for Max Tokens.',
maxTokensMinMessage: 'Max Tokens cannot be less than 0.',
password: 'Password',
Expand Down
7 changes: 6 additions & 1 deletion web/src/locales/vi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export default {
submit: 'Gửi',
vietnamese: 'Tiếng việt',
spanish: 'Tiếng Tây Ban Nha',
japanese: 'Tiếng Nhật',
},
login: {
login: 'Đăng nhập',
Expand Down Expand Up @@ -447,6 +448,7 @@ export default {
'Trong các cuộc trò chuyện nhiều vòng, truy vấn vào cơ sở kiến thức được tối ưu hóa. Mô hình lớn sẽ được gọi để sử dụng thêm các token.',
howUseId: 'Làm thế nào để sử dụng ID cuộc trò chuyện?',
description: 'Mô tả về trợ lý',
betaError: `"Beta API Token" không được để trống!`,
},
setting: {
profile: 'Hồ sơ',
Expand Down Expand Up @@ -841,7 +843,7 @@ export default {
timePeriod: 'Kỳ hạn',
qWeatherLangOptions: {
zh: 'Giản thể Trung Quốc',
'zh-hant': '繁體中文',
'zh-hant': 'Phồn thể Trung Quốc',
en: 'Tiếng Anh',
de: 'Tiếng Đức',
es: 'Tiếng Tây Ban Nha',
Expand Down Expand Up @@ -1079,6 +1081,9 @@ export default {
jsonUploadTypeErrorMessage: 'Vui lòng tải lên tệp json',
dynamicParameters: 'Tham số động',
emailSubject: 'Tiêu đề email',
ccEmail: 'Email CC',
toEmailTip: 'to_email: Email người nhận (Bắt buộc)',
ccEmailTip: 'cc_email: Email CC (Tùy chọn)',
},
footer: {
profile: 'All rights reserved @ React',
Expand Down
10 changes: 6 additions & 4 deletions web/src/pages/flow/constant.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2855,10 +2855,12 @@ export const QWeatherTimePeriodOptions = [
'30d',
];

export const ExeSQLOptions = ['mysql', 'postgresql', 'mariadb'].map((x) => ({
label: upperFirst(x),
value: x,
}));
export const ExeSQLOptions = ['mysql', 'postgresql', 'mariadb', 'mssql'].map(
(x) => ({
label: upperFirst(x),
value: x,
}),
);

export const SwitchElseTo = 'end_cpn_id';

Expand Down
9 changes: 8 additions & 1 deletion web/src/pages/user-setting/setting-locale/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,14 @@ function UserSettingLocale() {
return (
<TranslationTable
data={translationTable}
languages={['English', 'Vietnamese', 'Spanish', 'zh', 'zh-TRADITIONAL']}
languages={[
'English',
'Vietnamese',
'Spanish',
'zh',
'zh-TRADITIONAL',
'ja',
]}
/>
);
}
Expand Down

0 comments on commit d6c74ff

Please sign in to comment.