Skip to content

Commit

Permalink
feat: allow db any path with flag
Browse files Browse the repository at this point in the history
  • Loading branch information
catpaladin committed Jul 17, 2024
1 parent 916aea7 commit 8cc650a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
3 changes: 2 additions & 1 deletion cmd/jenn-ai/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ var (
topP = flag.Float64("topP", 0.999, "topP setting")
topK = flag.Int("topK", 250, "topK setting")
maxTokens = flag.Int("max-tokens", 500, "max tokens to sample")
dbPath = flag.String("db-path", "./chat.db", "The path to the sqlite database")
)

func main() {
Expand All @@ -31,5 +32,5 @@ func main() {
TopK: *topK,
MaxTokens: *maxTokens,
}
api.Serve(ctx, mc)
api.Serve(ctx, mc, *dbPath)
}
4 changes: 2 additions & 2 deletions internal/api/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"jenn-ai/internal/state"
)

func Serve(ctx context.Context, c config.ModelConfig) {
func Serve(ctx context.Context, c config.ModelConfig, dbPath string) {
router := gin.Default()

// Use the embedded template set
Expand All @@ -22,7 +22,7 @@ func Serve(ctx context.Context, c config.ModelConfig) {

mc := handlers.NewParameters(c.Platform, c.ModelID, c.Region, c.Temperature, c.TopP, c.TopK, c.MaxTokens)

err := db.NewDB()
err := db.NewDB(dbPath)
if err != nil {
log.Fatal(err)
}
Expand Down
4 changes: 2 additions & 2 deletions internal/db/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ var DB *sql.DB

// NewDB creates a new database if it doesn't exist
// and returns an error if it fails
func NewDB() error {
func NewDB(dbPath string) error {
var err error

DB, err = sql.Open("sqlite3", "./chat.db")
DB, err = sql.Open("sqlite3", dbPath)
if err != nil {
return err
}
Expand Down

0 comments on commit 8cc650a

Please sign in to comment.