Skip to content

Commit

Permalink
Merge pull request #3 from M507/master
Browse files Browse the repository at this point in the history
Pulling Nathaniel's RPs
  • Loading branch information
M507 authored Dec 22, 2023
2 parents 5c3735c + 5727968 commit b23f319
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 17 deletions.
25 changes: 14 additions & 11 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@
from flask_limiter import Limiter
from flask_limiter.util import get_remote_address
app = Flask(__name__)
import openai, os, warnings, time, re, html, random, argparse, logging, sys
from openai import OpenAI
import os, warnings, time, re, html, random, argparse, logging, sys
from pymongo import MongoClient
from dotenv import load_dotenv
load_dotenv() # reads from .env
openai.api_key = os.getenv('OPENAI_API_KEY')
app.secret_key = os.getenv('FLASK_SECRET_KEY')

from levels import *
from tests import *

# Flag for the ChatGPT connection
openai_api_key = os.getenv('OPENAI_API_KEY')
alive = int(os.getenv('HACKMEGPT_ALIVE'))
debug = int(os.getenv('HACKMEGPT_DEBUG'))
network_debug = int(os.getenv('HACKMEGPT_NETWORK_DEBUG'))
Expand All @@ -22,13 +23,16 @@
MAX_LEVEL = 10

# Initialize logging Config
logging.basicConfig(filename='record.log', level=logging.DEBUG)
if debug == 1:
logging.basicConfig(level=logging.DEBUG)
else:
logging.basicConfig(level=logging.ERROR)
logger = logging.getLogger(__name__)

# Initialize the MongoDB client
mongo_uri = os.getenv('MONGODB_URI')
client = MongoClient(mongo_uri) # Replace with your MongoDB connection string
db = client["mydb"]
mongo_client = MongoClient(mongo_uri) # Replace with your MongoDB connection string
db = mongo_client["mydb"]
collection = db["user_requests"]
prompts_collection = db["good_prompts"]

Expand Down Expand Up @@ -71,14 +75,13 @@ def check_prompt(prompt):
ip_request_timestamps = {}

def get_response_from_gpt(context, prompt):
completion = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=[
openai_client = OpenAI(api_key=openai_api_key)

completion = openai_client.chat.completions.create(model='gpt-3.5-turbo', messages=[
{"role": "system", "content": context},
{"role": "user", "content": prompt}
]
)
response_from_gpt = completion.choices[0].message['content']
])
response_from_gpt = completion.choices[0].message.content
logger.debug(f'Info message - response_from_gpt: {response_from_gpt}')
return response_from_gpt

Expand Down
4 changes: 2 additions & 2 deletions env.example
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
OPENAI_API_KEY=sk-11111111111111111111111111
mongodb=mongodb://root:rootpasswordhere@localhost:27017
FLASK_SECRET_KEY=something
alive=0
alive=1
debug=1
network_debug=1
network_debug=1
4 changes: 0 additions & 4 deletions levels.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
from similarity import *
import logging

# Initialize logging Config
logging.basicConfig(filename='tests.log', level=logging.DEBUG)
logger = logging.getLogger(__name__)

blacklists = {}
blacklists['human_languages'] = ["English","Spanish","Chinese","Mandarin","Hindi","Arabic","French","Russian","Portuguese","Bengali","German","Japanese","Punjabi","Javanese","Telugu","Marathi","Turkish","Korean","Tamil","Urdu","Italian","Vietnamese","Gujarati","Polish","Ukrainian","Malayalam"]
blacklists['encodings'] = ["base64", "hex", "base 64", "url", "url encoding", "endian", "binary", "hexadecimal", "UTF-8", "UTF8", "ASCII", "UTF-16", "UTF16", "UTF-32", "UTF32", "MIME", "Quoted-Printable", "Punycode", "HTML Entities", "ROT13", "Uuencode", "XXencode", "Binary-to-text", "7-bit", "8-bit", "Base32", "Base 32", "Base58", "Base 58", "Base85", "Base 85", "Base91", "Base 91", "Base92", "Base 92", "Base128", "Base 128", "Base256", "Base 256", "Z85", "YAML", "MsgPack", "BSON", "XML", "JSON", "CBOR", "ASN.1", "Huffman Coding", "Gray Code", "Gray-Hex", "BCD (Binary-Coded Decimal)", "BCD Excess-3", "Base36", "Base 36", "Base58Check", "Base 58 Check", "Base62", "Base 62", "Base64URL", "Base64 URL", "Base58Bitcoin", "Base58 Bitcoin", "Base62FLICKR", "Base62 FLICKR", "Base64MHTML", "Base64 MHTML", "Base58Ripple", "Base58 Ripple", "Base64IMAP", "Base64 IMAP", "Base64PEM", "Base64 PEM", "Base58Flickr", "Base58 Flickr", "Base64MySQL", "Base64 MySQL", "Base58IPFS", "Base58 IPFS", "Base64RFC3548", "Base64 RFC3548", "Base85RFC1924", "Base85 RFC1924", "Base64UUID", "Base64 UUID", "Base91UnixPassword", "Base91 Unix Password", "Base64XML", "Base64 XML", "Base85Git", "Base85 Git", "Base64YAML", "Base64 YAML", "Base95Zcash", "Base95 Zcash", "Base64CSV", "Base64 CSV", "Base94SIN", "Base94 SIN", "Base64UnrealScript", "Base64 UnrealScript"]
Expand Down

0 comments on commit b23f319

Please sign in to comment.