Skip to content

Commit ac71188

Browse files
committed
Initial Commit
0 parents  commit ac71188

File tree

17 files changed

+2768
-0
lines changed

17 files changed

+2768
-0
lines changed

.gitignore

Lines changed: 205 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,205 @@
1+
# Created by https://www.toptal.com/developers/gitignore/api/git,python,visualstudiocode
2+
# Edit at https://www.toptal.com/developers/gitignore?templates=git,python,visualstudiocode
3+
4+
### Git ###
5+
# Created by git for backups. To disable backups in Git:
6+
# $ git config --global mergetool.keepBackup false
7+
*.orig
8+
9+
# Created by git when using merge tools for conflicts
10+
*.BACKUP.*
11+
*.BASE.*
12+
*.LOCAL.*
13+
*.REMOTE.*
14+
*_BACKUP_*.txt
15+
*_BASE_*.txt
16+
*_LOCAL_*.txt
17+
*_REMOTE_*.txt
18+
19+
### Python ###
20+
# Byte-compiled / optimized / DLL files
21+
__pycache__/
22+
*.py[cod]
23+
*$py.class
24+
25+
# C extensions
26+
*.so
27+
28+
# Distribution / packaging
29+
.Python
30+
build/
31+
develop-eggs/
32+
dist/
33+
downloads/
34+
eggs/
35+
.eggs/
36+
lib/
37+
lib64/
38+
parts/
39+
sdist/
40+
var/
41+
wheels/
42+
share/python-wheels/
43+
*.egg-info/
44+
.installed.cfg
45+
*.egg
46+
MANIFEST
47+
48+
# PyInstaller
49+
# Usually these files are written by a python script from a template
50+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
51+
*.manifest
52+
*.spec
53+
54+
# Installer logs
55+
pip-log.txt
56+
pip-delete-this-directory.txt
57+
58+
# Unit test / coverage reports
59+
htmlcov/
60+
.tox/
61+
.nox/
62+
.coverage
63+
.coverage.*
64+
.cache
65+
nosetests.xml
66+
coverage.xml
67+
*.cover
68+
*.py,cover
69+
.hypothesis/
70+
.pytest_cache/
71+
cover/
72+
73+
# Translations
74+
*.mo
75+
*.pot
76+
77+
# Django stuff:
78+
*.log
79+
local_settings.py
80+
db.sqlite3
81+
db.sqlite3-journal
82+
83+
# Flask stuff:
84+
instance/
85+
.webassets-cache
86+
87+
# Scrapy stuff:
88+
.scrapy
89+
90+
# Sphinx documentation
91+
docs/_build/
92+
93+
# PyBuilder
94+
.pybuilder/
95+
target/
96+
97+
# Jupyter Notebook
98+
.ipynb_checkpoints
99+
100+
# IPython
101+
profile_default/
102+
ipython_config.py
103+
104+
# pyenv
105+
# For a library or package, you might want to ignore these files since the code is
106+
# intended to run in multiple environments; otherwise, check them in:
107+
# .python-version
108+
109+
# pipenv
110+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
111+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
112+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
113+
# install all needed dependencies.
114+
#Pipfile.lock
115+
116+
# poetry
117+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
118+
# This is especially recommended for binary packages to ensure reproducibility, and is more
119+
# commonly ignored for libraries.
120+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
121+
#poetry.lock
122+
123+
# pdm
124+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
125+
#pdm.lock
126+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
127+
# in version control.
128+
# https://pdm.fming.dev/#use-with-ide
129+
.pdm.toml
130+
131+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
132+
__pypackages__/
133+
134+
# Celery stuff
135+
celerybeat-schedule
136+
celerybeat.pid
137+
138+
# SageMath parsed files
139+
*.sage.py
140+
141+
# Environments
142+
.env
143+
.venv
144+
env/
145+
venv/
146+
ENV/
147+
env.bak/
148+
venv.bak/
149+
150+
# Spyder project settings
151+
.spyderproject
152+
.spyproject
153+
154+
# Rope project settings
155+
.ropeproject
156+
157+
# mkdocs documentation
158+
/site
159+
160+
# mypy
161+
.mypy_cache/
162+
.dmypy.json
163+
dmypy.json
164+
165+
# Pyre type checker
166+
.pyre/
167+
168+
# pytype static type analyzer
169+
.pytype/
170+
171+
# Cython debug symbols
172+
cython_debug/
173+
174+
# PyCharm
175+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
176+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
177+
# and can be added to the global gitignore or merged into this file. For a more nuclear
178+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
179+
#.idea/
180+
181+
### Python Patch ###
182+
# Poetry local configuration file - https://python-poetry.org/docs/configuration/#local-configuration
183+
# poetry.toml
184+
185+
186+
### VisualStudioCode ###
187+
.vscode/*
188+
!.vscode/settings.json
189+
!.vscode/tasks.json
190+
!.vscode/launch.json
191+
!.vscode/extensions.json
192+
!.vscode/*.code-snippets
193+
194+
# Local History for Visual Studio Code
195+
.history/
196+
197+
# Built Visual Studio Code Extensions
198+
*.vsix
199+
200+
### VisualStudioCode Patch ###
201+
# Ignore all local history of files
202+
.history
203+
.ionide
204+
205+
# End of https://www.toptal.com/developers/gitignore/api/git,python,visualstudiocode

.type_stubs/.gitkeep

Whitespace-only changes.

.vscode/settings.json

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
{
2+
"[python]": {
3+
"editor.insertSpaces": true,
4+
"editor.tabSize": 4,
5+
"editor.rulers": [
6+
119
7+
],
8+
"editor.codeActionsOnSave": {
9+
"source.organizeImports": true,
10+
"source.fixAll": true
11+
}
12+
},
13+
"python.defaultInterpreterPath": "${workspaceFolder}/.venv/bin/python3",
14+
"python.envFile": "${workspaceFolder}/.venv",
15+
"python.languageServer": "Pylance",
16+
"python.formatting.provider": "yapf",
17+
"python.formatting.yapfPath": "${workspaceFolder}/.venv/bin/yapf",
18+
"python.linting.enabled": true,
19+
"python.linting.pylintEnabled": true,
20+
"python.linting.pylintPath": "${workspaceFolder}/.venv/bin/pylint",
21+
"python.linting.mypyEnabled": true,
22+
"python.linting.mypyArgs": [
23+
"--config-file ${workspaceFolder}/pyproject.toml"
24+
],
25+
"isort.path": [
26+
"${workspaceFolder}/.venv/bin/isort"
27+
],
28+
"python.testing.pytestEnabled": true,
29+
"python.testing.pytestArgs": [
30+
"."
31+
],
32+
"emeraldwalk.runonsave": {
33+
"commands": [
34+
{
35+
"match": "\\.py$",
36+
"cmd": "${workspaceFolder}/.venv/bin/unify --in-place ${file}"
37+
},
38+
{
39+
"match": "\\.py$",
40+
"cmd": "${workspaceFolder}/.venv/bin/pautoflake --in-place ${file}"
41+
}
42+
]
43+
},
44+
"[toml]": {
45+
"editor.defaultFormatter": "tamasfe.even-better-toml"
46+
},
47+
"python.linting.mypyPath": "${workspaceFolder}/.venv/bin/mypy"
48+
}

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2023 YeonGyu Kim
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the Software), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# AiShell
2+
3+
A simple Python code that connects to OpenAI's ChatGPT and executes the returned results.
4+
5+
## Examples
6+
7+
### Simple Utility commands
8+
9+
![terminal example](images/aishell_example.png)
10+
11+
### A git helper
12+
13+
![terminal example](images/aishell_example2.png)
14+
15+
### A powerful git assistant: "add all files & amend last commit & push"
16+
17+
![terminal example3](images/aishell_example3.png)
18+
19+
20+
## Prerequisites
21+
22+
- Python 3.9.5
23+
- Poetry
24+
- OpenAI API Key
25+
26+
## Getting Started
27+
28+
1. Create account on OpenAI
29+
1. Go to <https://platform.openai.com/account/api-keys>, Copy API key
30+
1. Set the API key as an environment variable OPENAI_API_KEY or inject it directly into the code by editing it.
31+
1. Clone this repository to your local machine using git clone <repository-url>
32+
1. Install the dependencies by running poetry install in your terminal
33+
1. Start AiShell by running poetry run python3 aishell/main.py
34+
35+
## Contributions
36+
37+
Feel free to contribute to AiShell by adding more functionality or fixing bugs. Some suggestions for contributions include:
38+
39+
- Adding the ability to execute AiShell as a system command aishell <command>
40+
- Publishing AiShell to PyPI so that others can easily download and use it

aishell/__init__.py

Whitespace-only changes.

aishell/main.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/usr/bin/env python
2+
3+
from revChatGPT.Official import Chatbot
4+
5+
import os
6+
import typer
7+
8+
API_KEY = os.environ.get('OPENAI_API_KEY') or ''
9+
10+
11+
def make_executable_command(command: str) -> str:
12+
# starting '\n' or trailing '\n' should be replaced as ''
13+
# starting ' ' or trailing ' ' should be replaced as ''
14+
if command.startswith('\n'):
15+
command = command[1:]
16+
if command.endswith('\n'):
17+
command = command[:-1]
18+
command = command.strip()
19+
return command
20+
21+
22+
def ask_chatgpt(text: str) -> str:
23+
chatbot = Chatbot(api_key=API_KEY)
24+
response_text: str = chatbot.ask(text)['choices'][0]['text']
25+
return make_executable_command(response_text)
26+
27+
28+
def get_os() -> str:
29+
return os.uname()[0]
30+
31+
32+
def make_prompt(requirements: str) -> str:
33+
return f'''You are now a translater from human language to {get_os} shell command.
34+
No explanation required, respond with only the raw shell command.
35+
What should I type to shell for: {requirements}'''
36+
37+
38+
app = typer.Typer()
39+
40+
41+
@app.command()
42+
def ask(text: str):
43+
question = make_prompt(text)
44+
response = ask_chatgpt(question)
45+
typer.echo(f'\033[3mexecuted: {response}\033[0m')
46+
os.system(response)
47+
48+
49+
if __name__ == '__main__':
50+
app()

aishell/tests/__init__.py

Whitespace-only changes.

aishell/tests/sample_test.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
def test_one_plus_one():
2+
assert 1 + 1 == 2

images/aishell_example.png

561 KB
Loading

0 commit comments

Comments
 (0)