Skip to content

Commit

Permalink
pre-commit test
Browse files Browse the repository at this point in the history
  • Loading branch information
PyRo1121 committed Dec 7, 2022
1 parent ad7f44a commit e19513c
Show file tree
Hide file tree
Showing 6 changed files with 265 additions and 141 deletions.
58 changes: 58 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: debug-statements
- id: double-quote-string-fixer
- id: name-tests-test
- id: requirements-txt-fixer
- repo: https://github.com/psf/black
rev: 22.10.0
hooks:
- id: black
args: [--safe, --quiet]
- repo: https://github.com/asottile/reorder_python_imports
rev: v3.9.0
hooks:
- id: reorder-python-imports
exclude: ^(pre_commit/resources/|testing/resources/python3_hooks_repo/)
args: [--py37-plus, --add-import, 'from __future__ import annotations']
- repo: https://github.com/asottile/add-trailing-comma
rev: v2.3.0
hooks:
- id: add-trailing-comma
args: [--py36-plus]
- repo: https://github.com/asottile/pyupgrade
rev: v3.3.1
hooks:
- id: pyupgrade
args: [--py37-plus]
- repo: https://github.com/pre-commit/mirrors-autopep8
rev: v2.0.0
hooks:
- id: autopep8
- repo: https://github.com/PyCQA/flake8
rev: 6.0.0
hooks:
- id: flake8
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.991
hooks:
- id: mypy
additional_dependencies: [types-all]
exclude: ^testing/resources/
- repo: https://github.com/PyCQA/autoflake
rev: v2.0.0
hooks:
- id: autoflake
exclude: &fixtures tests(/\w*)*/functional/|tests/input|doc/data/messages|tests(/\w*)*data/
args:
- --in-place
- --remove-all-unused-imports
- --expand-star-imports
- --remove-duplicate-keys
- --remove-unused-variables
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"python.linting.pylintEnabled": true,
"python.linting.enabled": true
}
}
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

[metadata]
description_file=README.md
license_files=LICENSE
license_files=LICENSE
12 changes: 8 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
from setuptools import setup, find_packages
from __future__ import annotations

from setuptools import find_packages
from setuptools import setup

setup(
name="revChatGPT",
version="0.0.31.1",
Expand All @@ -7,12 +11,12 @@
author_email="acheong@student.dalat.org",
description="ChatGPT is a reverse engineering of OpenAI's ChatGPT API",
packages=find_packages("src"),
package_dir={'': 'src'},
package_dir={"": "src"},
url="https://github.com/acheong08/ChatGPT",
install_requires=[
"requests",
"tls-client",
],
long_description=open('README.md', encoding='utf-8').read(),
long_description_content_type='text/markdown',
long_description=open("README.md", encoding="utf-8").read(),
long_description_content_type="text/markdown",
)
29 changes: 18 additions & 11 deletions src/revChatGPT/__main__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
from revChatGPT.revChatGPT import Chatbot
from __future__ import annotations

import json
from sys import argv
import textwrap
from os.path import exists
from sys import argv

from revChatGPT.revChatGPT import Chatbot


def get_input(prompt):
Expand All @@ -22,15 +25,17 @@ def get_input(prompt):


if __name__ == "__main__":
print("""
print(
"""
ChatGPT - A command-line interface to OpenAI's ChatGPT (https://chat.openai.com/chat)
Repo: github.com/acheong08/ChatGPT
""")
""",
)
print("Type '!help' to show commands")
print("Press enter twice to submit your question.\n")

if exists("config.json"):
with open("config.json", "r", encoding='utf-8') as f:
with open("config.json", encoding="utf-8") as f:
config = json.load(f)
chatbot = Chatbot(config)
else:
Expand All @@ -41,14 +46,16 @@ def get_input(prompt):
prompt = get_input("\nYou:\n")
if prompt.startswith("!"):
if prompt == "!help":
print("""
print(
"""
!help - Show this message
!reset - Forget the current conversation
!refresh - Refresh the session authentication
!rollback - Rollback the conversation by 1 message
!config - Show the current configuration
!exit - Exit the program
""")
""",
)
continue
elif prompt == "!reset":
chatbot.reset_chat()
Expand All @@ -68,7 +75,7 @@ def get_input(prompt):
elif prompt == "!exit":
break

if '--text' not in argv:
if "--text" not in argv:
messages = []
lines_printed = 0

Expand All @@ -77,14 +84,14 @@ def get_input(prompt):
formatted_parts = []
for message in chatbot.get_chat_response(prompt, output="stream"):
# Split the message by newlines
message_parts = message['message'].split('\n')
message_parts = message["message"].split("\n")

# Wrap each part separately
formatted_parts = []
for part in message_parts:
formatted_parts.extend(textwrap.wrap(part, width=80))
for formatted_line in formatted_parts:
if len(formatted_parts) > lines_printed+1:
if len(formatted_parts) > lines_printed + 1:
print(formatted_parts[lines_printed])
lines_printed += 1
print(formatted_parts[lines_printed])
Expand All @@ -96,7 +103,7 @@ def get_input(prompt):
try:
print("Chatbot: ")
message = chatbot.get_chat_response(prompt)
print(message['message'])
print(message["message"])
except Exception as e:
print("Something went wrong!")
print(e)
Expand Down
Loading

0 comments on commit e19513c

Please sign in to comment.