Commit 484b7b14 authored by jaden's avatar jaden

fix: functions upodate

parent ebd75809
...@@ -37,8 +37,9 @@ export default class OpenAI { ...@@ -37,8 +37,9 @@ export default class OpenAI {
onFinish: (responseText: string) => any, onFinish: (responseText: string) => any,
onUpdate: (responseText: string, delta: string) => any, onUpdate: (responseText: string, delta: string) => any,
onError: (e: Error) => any, onError: (e: Error) => any,
functions: any[] = [], functions: any[],
closeFn?: MutableRefObject<any>, closeFn?: MutableRefObject<any>,
function_call?: any,
stream: boolean = true stream: boolean = true
) { ) {
const requestPayload = { const requestPayload = {
...@@ -48,7 +49,8 @@ export default class OpenAI { ...@@ -48,7 +49,8 @@ export default class OpenAI {
frequency_penalty: model.frequency_penalty, frequency_penalty: model.frequency_penalty,
presence_penalty: model.presence_penalty, presence_penalty: model.presence_penalty,
stream, stream,
functions: functions, functions,
function_call,
}; };
const controller = new AbortController(); const controller = new AbortController();
const chatPayload = { const chatPayload = {
......
...@@ -52,6 +52,7 @@ type AIProps = { ...@@ -52,6 +52,7 @@ type AIProps = {
noHistory?: boolean; noHistory?: boolean;
functions: any[]; functions: any[];
stream?: boolean; stream?: boolean;
function_call: any;
}; };
export function AIWrapper({ export function AIWrapper({
...@@ -71,6 +72,7 @@ export function AIWrapper({ ...@@ -71,6 +72,7 @@ export function AIWrapper({
SendButton, SendButton,
noHistory, noHistory,
functions, functions,
function_call,
stream, stream,
}: AIProps) { }: AIProps) {
const input = useRef<any>(); const input = useRef<any>();
...@@ -170,6 +172,7 @@ export function AIWrapper({ ...@@ -170,6 +172,7 @@ export function AIWrapper({
}, },
functions, functions,
closeRef, closeRef,
function_call,
stream || !functions stream || !functions
); );
}, },
......
export const QUERY_FUNCTION = [ export const QUERY_FUNCTION = [
{ {
name: 'saveExecuteSqlInfo', name: 'saveExecuteSqlInfo',
description: '存储执行该需求所需要的关键信息', description:
'Unique and mandatory execution (no other functions can be executed), storing the key information required to execute this requirement',
parameters: { parameters: {
type: 'object', type: 'object',
properties: { properties: {
sql: { sql: {
type: 'string', type: 'string',
description: 'The SQL statement to execute', description:
'The SQL statement to execute must be standard and cannot contain any other code.',
}, },
variablesArr: { variablesArr: {
type: 'array', type: 'array',
......
...@@ -635,38 +635,14 @@ export default function Actions() { ...@@ -635,38 +635,14 @@ export default function Actions() {
role: 'assistant', role: 'assistant',
content: `好的,请问这个示例对吗? content: `好的,请问这个示例对吗?
根据您提供的数据库模型,生成的查询如下: 根据您提供的数据库模型,生成的查询如下:
{"name":"python","arguments":"import pandas as pd\n\n# 模拟查询数据库中的表\ntables = ['departments', 'doctors', 'patients', 'appointments']\n\n# 将查询结果转换为DataFrame格式\ndf = pd.DataFrame(tables, columns=['Table Name'])\n\n# 将DataFrame转换为HTML格式\nhtml_result = df.to_html(index=False)\n\nhtml_result"}
\`\`\`sql
SELECT $field$ FROM users where id=$id$;
INSERT INTO users (email, name) VALUES ($email$, $name$);
\`\`\`
执行所需变量:
<var> $field$ </var>: <varDescription> users 表中的某个字段。</varDescription>
查询命名和描述:
查询名称:查询所有表中的数据
查询描述:该查询用于检索所有表中的数据。
`, `,
}, },
{ {
role: 'user', role: 'user',
content: `不对!你不应该使用markdown语法,(输出结果标签(<sql>、<var>等)必须保留。变量的命名必须请放在$和$之间,例如:$tab$、$name$...),下面是一个示例: content: `不对!必须且仅能调用functions中saveExecuteSqlInfo,(输出结果标签(<sql>、<var>等)必须保留。变量的命名必须请放在$和$之间,例如:$tab$、$name$...),下面是一个示例:
根据您提供的数据库模型,已为您生成查询: 根据您提供的数据库模型,已为您生成查询:
<sql> {"name":"saveExecuteSqlInfo","arguments":"{\n \"sql\": \"SELECT * FROM departments; SELECT * FROM doctors; SELECT * FROM patients; SELECT * FROM appointments;\",\n \"variablesArr\": [],\n \"queryName\": \"查询所有表中的数据\",\n \"queryDescription\": \"该查询用于检索所有表中的数据。\"\n}"}
SELECT $field$ FROM users where id=$id$;
INSERT INTO users (email, name) VALUES ($email$, $name$);
</sql>
执行所需变量:
<var> $field$ </var>: <varDescription> users 表中的某个字段。</varDescription>
查询命名和描述:
<queryName> 查用户和插入用户 </queryName>
<queryDescription> 先根据用户id查出用户,然后插入一个用户。 </queryDescription>
`, `,
}, },
{ {
...@@ -803,8 +779,10 @@ INSERT INTO users (email, name) VALUES ($email$, $name$); ...@@ -803,8 +779,10 @@ INSERT INTO users (email, name) VALUES ($email$, $name$);
<Content> <Content>
<AI <AI
functions={QUERY_FUNCTION} functions={QUERY_FUNCTION}
function_call={{
name: 'saveExecuteSqlInfo',
}}
stream={false} stream={false}
noHistory
quickTip={queryTip} quickTip={queryTip}
welcome={ welcome={
<> <>
......
...@@ -47,10 +47,12 @@ const exportSQL = (tableDict, linkDict, databaseType = 'postgres') => { ...@@ -47,10 +47,12 @@ const exportSQL = (tableDict, linkDict, databaseType = 'postgres') => {
}), }),
}; };
try {
const database = Parser.parse(combined, 'json'); const database = Parser.parse(combined, 'json');
const sql = ModelExporter.export(database, databaseType, false); return ModelExporter.export(database, databaseType, false);
} catch (e) {
return sql; console.log(e);
}
}; };
export default exportSQL; export default exportSQL;
...@@ -15,13 +15,21 @@ export class XML { ...@@ -15,13 +15,21 @@ export class XML {
} }
export class FunctionsJson { export class FunctionsJson {
private root: HTMLDivElement; private root: Record<string, any>;
constructor(code: string) { constructor(code: string) {
try {
this.root = JSON.parse(code); this.root = JSON.parse(code);
} catch {
this.root = {};
}
} }
get(code: string): string { get(code: string): string {
return JSON.parse(get(this.root, 'arguments', '{}'))[code]; try {
return JSON.parse(get(this.root, 'arguments', '{}'))[code] || '';
} catch (e) {
return '';
}
} }
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment