Skip to content

Commit d17d29e

Browse files
committed
Wrap AiShell as module
1 parent 1e373d6 commit d17d29e

File tree

6 files changed

+38
-113
lines changed

6 files changed

+38
-113
lines changed

aishell/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from .cli import cli_app
2+
3+
4+
def main():
5+
cli_app()

aishell/__main__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import aishell
2+
3+
if __name__ == '__main__':
4+
aishell.main()

aishell/cli.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import os
2+
3+
import typer
4+
from rich.console import Console
5+
6+
from aishell.query_clients import ChatGPTClient, GPT3Client, QueryClient
7+
8+
cli_app = typer.Typer()
9+
10+
11+
@cli_app.command()
12+
def ask(question: str, use_chatgpt: bool = False):
13+
query_client: QueryClient
14+
if use_chatgpt:
15+
query_client = ChatGPTClient()
16+
else:
17+
query_client = GPT3Client()
18+
19+
console = Console()
20+
with console.status(f'[green] Asking `{question}` ...'):
21+
response = query_client.query(question)
22+
console.print(f'[italic]ai$hell: {response}\n')
23+
24+
os.system(response)

aishell/main.py

Lines changed: 0 additions & 109 deletions
This file was deleted.

aishell/query_clients/chatgpt_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ def query(self, prompt: str) -> str:
3636

3737
response_text = ''
3838
for data in chatbot.ask(prompt):
39-
responsed_text = data['message']
39+
response_text = data['message']
4040

41-
responsed_text = make_executable_command(responsed_text)
41+
response_text = make_executable_command(response_text)
4242

4343
return response_text

aishell/query_clients/gpt3_client.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
from typing import cast
33

44
import openai
5-
from models import OpenAIResponseModel
6-
from utils import make_executable_command
5+
6+
from aishell.models import OpenAIResponseModel
7+
from aishell.utils import make_executable_command
78

89
from .query_client import QueryClient
910

0 commit comments

Comments
 (0)