mirror of
https://github.com/sqlchat/sqlchat.git
synced 2025-07-28 17:53:21 +08:00
chore: update assistant prompt
This commit is contained in:
@ -54,6 +54,9 @@ const MessageView = (props: Props) => {
|
||||
</pre>
|
||||
);
|
||||
},
|
||||
code({ children }) {
|
||||
return <code className="px-0">`{children}`</code>;
|
||||
},
|
||||
}}
|
||||
>
|
||||
{message.content}
|
||||
|
@ -31,6 +31,7 @@ const getDatabases = async (connection: Connection): Promise<string[]> => {
|
||||
const client = newPostgresClient(connection);
|
||||
await client.connect();
|
||||
await client.end();
|
||||
// Because PostgreSQL needs to specify a database to connect to, we use the default database.
|
||||
return [connection.database!];
|
||||
};
|
||||
|
||||
@ -55,17 +56,19 @@ const getTableStructure = async (connection: Connection, _: string, tableName: s
|
||||
const client = newPostgresClient(connection);
|
||||
await client.connect();
|
||||
const { rows } = await client.query(
|
||||
`SELECT column_name, data_type, is_nullable, column_default FROM information_schema.columns WHERE table_schema='public' AND table_name=$1;`,
|
||||
`SELECT column_name, data_type, is_nullable FROM information_schema.columns WHERE table_schema='public' AND table_name=$1;`,
|
||||
[tableName]
|
||||
);
|
||||
await client.end();
|
||||
const columnList = [];
|
||||
// TODO(steven): transform it to standard schema string.
|
||||
for (const row of rows) {
|
||||
columnList.push(`\`${row["column_name"]}\` ${row["data_type"]} ${String(row["is_nullable"]).toUpperCase()} ${row["column_default"]},`);
|
||||
columnList.push(
|
||||
`${row["column_name"]} ${row["data_type"].toUpperCase()} ${String(row["is_nullable"]).toUpperCase() === "NO" ? "NOT NULL" : ""}`
|
||||
);
|
||||
}
|
||||
return `CREATE TABLE \`${tableName}\` (
|
||||
${columnList.join("\n")}
|
||||
${columnList.join(",\n")}
|
||||
);`;
|
||||
};
|
||||
|
||||
|
@ -20,7 +20,7 @@ export const getAssistantById = (id: Id) => {
|
||||
export const getPromptGeneratorOfAssistant = (assistant: User) => {
|
||||
if (assistant.id === "sql-assistant") {
|
||||
return (schema: string) =>
|
||||
`Remember that you are an expert in SQL. And you know everything about databases. You will answer some questions about databases with a database schema like "${schema}".`;
|
||||
`This is my database schema"${schema}". You will see the tables and columns in the database. And please answer the following questions about the database.`;
|
||||
}
|
||||
return () => "";
|
||||
};
|
||||
|
Reference in New Issue
Block a user