Skip to content

Commit

Permalink
Add prompt template (#75)
Browse files Browse the repository at this point in the history
* Implement UI for creating prompt template

* Refactor database structure

* Move llm and rag related code to core/

* Create template table

* Add template module in database manager

* Handle context error

* Implement template plugin

* Fix lint

* Update style

* Style dialog

* Fix popover positioning bug

* Use sentence case

* Fix styles

* Resolve review

* Update paths

* Update path

* Fix bug where autofocus is not working

---------

Co-authored-by: realsnoopso <[email protected]>
  • Loading branch information
kevin-on and realsnoopso authored Nov 1, 2024
1 parent da83d8f commit f81cede
Show file tree
Hide file tree
Showing 50 changed files with 1,827 additions and 535 deletions.
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ We use PGlite and Drizzle ORM for database management in this project. This sect

To update the database schema:

1. Modify the existing schema as needed in the `src/db/schema.ts` file.
1. Modify the existing schema as needed in the `src/database/schema.ts` file.
2. After making changes, run the following command to generate migration files:

```
Expand All @@ -58,7 +58,7 @@ To update the database schema:
npm run migrate:compile
```

This will create or update the `src/db/migrations.json` file. Note that migration files in the 'drizzle' directory won't affect the project until they are compiled into this JSON file, which is used in the actual migration process.
This will create or update the `src/database/migrations.json` file. Note that migration files in the 'drizzle' directory won't affect the project until they are compiled into this JSON file, which is used in the actual migration process.

### Handling Migration Files

Expand Down
2 changes: 1 addition & 1 deletion DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

PGlite typically uses the `node:fs` module to load bundle files. However, Obsidian plugins run in a browser-like environment where `node:fs` is not available. This presents a challenge in implementing PGlite in Obsidian's environment.

To address this, we developed a workaround in `src/utils/vector-db/repository.ts`:
To address this, we developed a workaround in `src/database/DatabaseManager.ts`:

1. Manually fetch required PGlite resources (Postgres data, WebAssembly module, and Vector extension).
2. Use PGlite's option to directly set bundle files or URLs when initializing the database.
Expand Down
5 changes: 4 additions & 1 deletion compile-migration.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ const fs = require('node:fs/promises')
async function compileMigrations() {
const migrations = readMigrationFiles({ migrationsFolder: './drizzle/' })

await fs.writeFile('./src/db/migrations.json', JSON.stringify(migrations))
await fs.writeFile(
'./src/database/migrations.json',
JSON.stringify(migrations),
)

console.log('Migrations compiled!')
}
Expand Down
2 changes: 1 addition & 1 deletion drizzle.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ import { defineConfig } from 'drizzle-kit'

export default defineConfig({
dialect: 'postgresql',
schema: './src/db/schema.ts',
schema: './src/database/schema.ts',
})
8 changes: 8 additions & 0 deletions drizzle/0005_create_template_table.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CREATE TABLE IF NOT EXISTS "template" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"name" text NOT NULL,
"content" jsonb NOT NULL,
"created_at" timestamp DEFAULT now() NOT NULL,
"updated_at" timestamp DEFAULT now() NOT NULL,
CONSTRAINT "template_name_unique" UNIQUE("name")
);
Loading

0 comments on commit f81cede

Please sign in to comment.