chore: update assistant prompt

This commit is contained in:
steven
2023-03-27 15:32:00 +08:00
parent c15f572d40
commit 408e61e171
3 changed files with 10 additions and 4 deletions

View File

@ -54,6 +54,9 @@ const MessageView = (props: Props) => {
</pre>
);
},
code({ children }) {
return <code className="px-0">`{children}`</code>;
},
}}
>
{message.content}

View File

@ -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")}
);`;
};

View File

@ -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 () => "";
};