GAF to handle various server failures

This commit is contained in:
adamoutler 2023-02-08 18:31:48 +00:00
parent f7564146be
commit 5e0442a366
3 changed files with 31 additions and 21 deletions

View File

@ -1,6 +1,6 @@
# docker build -t aidgaf . # docker build -t aidgaf .
#for test #for test
# docker run --rm -eSERVERPORT=8087 -eAPIKEY=sk-AaKV.........................HZ4v2ipzFm6 -p8087:8087 -it aidgaf # docker run --rm -eAPIKEY=sk-AaKV.........................HZ4v2ipzFm6 -p8087:8087 -it aidgaf
# curl -X PATCH http://127.0.0.1:8087 -d "{\"message\":{\"command\":\"aidgaf\",\"data\":{\"username\":\"AdamOutler\"}}}" # curl -X PATCH http://127.0.0.1:8087 -d "{\"message\":{\"command\":\"aidgaf\",\"data\":{\"username\":\"AdamOutler\"}}}"
#for deployment #for deployment

View File

@ -69,7 +69,11 @@ def parse_idgaf_request(command):
the_data = get_prompt(command) the_data = get_prompt(command)
gpt_response = requests.post(URL, json=the_data, headers=request_headers) gpt_response = requests.post(URL, json=the_data, headers=request_headers)
print(gpt_response) print(gpt_response)
response_text = gpt_response.json()['choices'][0]['text'].strip() try:
response_text = gpt_response.json()['choices'][0]['text'].strip()
except (KeyError):
response_text=gpt_response.text
obj = get_response_base_object(response_text) obj = get_response_base_object(response_text)
obj['hash']=get_message_hash(json.dumps(obj)) obj['hash']=get_message_hash(json.dumps(obj))
json_result = json.dumps(obj) json_result = json.dumps(obj)
@ -94,8 +98,10 @@ def get_message_hash(json_command) -> bytes:
strip1 = re.sub('.*\"message\":', "", json_command, 1) strip1 = re.sub('.*\"message\":', "", json_command, 1)
strip2 = re.sub(',\"hash\":.*', '', strip1) strip2 = re.sub(',\"hash\":.*', '', strip1)
json_value = bytes(strip2, "utf-8") json_value = bytes(strip2, "utf-8")
hash_value = hash_calculator.calculate_hash(json_value, settings.HASHKEY) if (settings.HASHKEY is not None):
return hash_value hash_value = hash_calculator.calculate_hash(json_value, settings.HASHKEY)
return hash_value
return ""
def verify_message_time(json_command) -> bool: def verify_message_time(json_command) -> bool:

View File

@ -1,18 +1,22 @@
import os import os
#The hostname used by this app # The hostname used by this app
HOSTNAME:str = os.getenv('HOSTNAME') #localhost or some name HOSTNAME: str = os.getenv('HOSTNAME') # localhost or some name
#The port to broadcast the server # The port to broadcast the server
SERVERPORT:int = int(os.getenv('SERVERPORT')) #8087 or the port you want to run on. pass in with docker -e command. # 8087 or the port you want to run on. pass in with docker -e command.
#The API key for OpenAI SERVERPORT: int = 8087
APIKEY:str = os.getenv('APIKEY') #secret key from OpenAPI website # The API key for OpenAI
if APIKEY is None: APIKEY: str = os.getenv('APIKEY') # secret key from OpenAPI website
raise Exception("APIKEY Environmental Variable must be set") if APIKEY is None:
#The hash key raise Exception("APIKEY Environmental Variable must be set")
HASHKEY:str = bytes(os.getenv('HASHKEY'),'utf-8') #shared secret for hmac of message # The hash key
#The prompts used for OpenAI. HASHKEY: str = None
PROMPTS=["Say \"USERNAME does not give a fuck\" in a thoughtful and clever paragraph of 5 sentences.", hashKey = os.getenv('HASHKEY') # shared secret for hmac of message
"Say \"USERNAME does not give a fuck\" in a Dr Suess poem.", if (hashKey is not None and hashKey.replace(" ", "") != ""):
"Tell me all about how much \"USERNAME does not give a fuck\" using your most colorful words."] HASKHEY = bytes(hashKey, "utf-8")
OPEN_AI_MAX_TOKENS=500 # The prompts used for OpenAI.
OPEN_AI_COMPLETION_MODEL="text-davinci-003" PROMPTS = ["Say \"USERNAME does not give a fuck\" in a thoughtful and clever paragraph of 5 sentences.",
MAX_MESSAGE_AGE=600 "Say \"USERNAME does not give a fuck\" in a Dr Suess poem.",
"Tell me all about how much \"USERNAME does not give a fuck\" using your most colorful words."]
OPEN_AI_MAX_TOKENS = 500
OPEN_AI_COMPLETION_MODEL = "text-davinci-003"
MAX_MESSAGE_AGE = 600