Skip to content

Commit

Permalink
Merge pull request #44 from CharlesCNorton/main
Browse files Browse the repository at this point in the history
Fix datetime timezone reference and improve asynchronous handling
  • Loading branch information
darrenburns authored Sep 8, 2024
2 parents 61ef601 + 060d235 commit 6bbd438
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 deletions.
9 changes: 1 addition & 8 deletions elia_chat/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,11 @@

console = Console()


def create_db_if_not_exists() -> None:
if not sqlite_file_name.exists():
click.echo(f"Creating database at {sqlite_file_name!r}")
asyncio.run(create_database())


def load_or_create_config_file() -> dict[str, Any]:
config = config_file()

Expand All @@ -42,12 +40,10 @@ def load_or_create_config_file() -> dict[str, Any]:

return file_config


@click.group(cls=DefaultGroup, default="default", default_if_no_args=True)
def cli() -> None:
"""Interact with large language models using your terminal."""


@cli.command()
@click.argument("prompt", nargs=-1, type=str, required=False)
@click.option(
Expand All @@ -64,7 +60,7 @@ def cli() -> None:
help="Run in inline mode, without launching full TUI.",
default=False,
)
def default(prompt: tuple[str, ...], model: str, inline: bool):
def default(prompt: tuple[str, ...], model: str, inline: bool) -> None:
prompt = prompt or ("",)
joined_prompt = " ".join(prompt)
create_db_if_not_exists()
Expand All @@ -77,7 +73,6 @@ def default(prompt: tuple[str, ...], model: str, inline: bool):
app = Elia(LaunchConfig(**launch_config), startup_prompt=joined_prompt)
app.run(inline=inline)


@cli.command()
def reset() -> None:
"""
Expand Down Expand Up @@ -109,7 +104,6 @@ def reset() -> None:
asyncio.run(create_database())
console.print(f"♻️ Database reset @ {sqlite_file_name}")


@cli.command("import")
@click.argument(
"file",
Expand All @@ -127,6 +121,5 @@ def import_file_to_db(file: pathlib.Path) -> None:
asyncio.run(import_chatgpt_data(file=file))
console.print(f"[green]ChatGPT data imported from {str(file)!r}")


if __name__ == "__main__":
cli()
8 changes: 4 additions & 4 deletions elia_chat/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,15 @@ def runtime_config(self, new_runtime_config: RuntimeConfig) -> None:
self.runtime_config_signal.publish(self.runtime_config)

async def on_mount(self) -> None:
self.push_screen(HomeScreen(self.runtime_config_signal))
await self.push_screen(HomeScreen(self.runtime_config_signal))
if self.startup_prompt:
await self.launch_chat(
prompt=self.startup_prompt,
model=self.runtime_config.selected_model,
)

async def launch_chat(self, prompt: str, model: EliaChatModel) -> None:
current_time = datetime.datetime.now(datetime.UTC)
current_time = datetime.datetime.now(datetime.timezone.utc)
system_message: ChatCompletionSystemMessageParam = {
"content": self.runtime_config.system_prompt,
"role": "system",
Expand Down Expand Up @@ -102,9 +102,9 @@ async def launch_chat(self, prompt: str, model: EliaChatModel) -> None:

async def action_help(self) -> None:
if isinstance(self.screen, HelpScreen):
self.app.pop_screen()
self.pop_screen()
else:
await self.app.push_screen(HelpScreen())
await self.push_screen(HelpScreen())


if __name__ == "__main__":
Expand Down

0 comments on commit 6bbd438

Please sign in to comment.