Skip to content

Commit

Permalink
feat(cli): pr feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
juftin committed Jul 28, 2023
1 parent 7e2bd4c commit 3bebb5e
Showing 1 changed file with 25 additions and 8 deletions.
33 changes: 25 additions & 8 deletions elia_chat/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
Elia CLI
"""

import pathlib

import click

from elia_chat.app import app
from elia_chat.database.create_database import create_database
from elia_chat.database.import_chatgpt import import_chatgpt_data
from elia_chat.database.models import sqlite_file_name


Expand All @@ -23,22 +26,36 @@ def cli(context: click.Context) -> None:
app.run()


@cli.group()
def db() -> None:
"""
Elia database interactions
"""


@db.command()
@cli.command()
def reset() -> None:
"""
Reset the database
This command will delete the database file and recreate it.
Previously saved conversations and data will be lost.
"""
sqlite_file_name.unlink(missing_ok=True)
create_database()
click.echo(f"♻️ Database reset @ {sqlite_file_name}")


@cli.command("import")
@click.argument(
"file",
type=click.Path(
exists=True, dir_okay=False, path_type=pathlib.Path, resolve_path=True
),
)
def import_file_to_db(file) -> None:
"""
Import ChatGPT Conversations
This command will import the ChatGPT conversations from a local
JSON file into the database.
"""
import_chatgpt_data(file=file)
click.echo(f"✅ ChatGPT data imported into database {file}")


if __name__ == "__main__":
cli()

0 comments on commit 3bebb5e

Please sign in to comment.