GAF to handle various server failures
This commit is contained in:
parent
f7564146be
commit
5e0442a366
@ -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
|
||||||
|
@ -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)
|
||||||
|
try:
|
||||||
response_text = gpt_response.json()['choices'][0]['text'].strip()
|
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")
|
||||||
|
if (settings.HASHKEY is not None):
|
||||||
hash_value = hash_calculator.calculate_hash(json_value, settings.HASHKEY)
|
hash_value = hash_calculator.calculate_hash(json_value, settings.HASHKEY)
|
||||||
return hash_value
|
return hash_value
|
||||||
|
return ""
|
||||||
|
|
||||||
|
|
||||||
def verify_message_time(json_command) -> bool:
|
def verify_message_time(json_command) -> bool:
|
||||||
|
@ -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
|
||||||
|
APIKEY: str = os.getenv('APIKEY') # secret key from OpenAPI website
|
||||||
if APIKEY is None:
|
if APIKEY is None:
|
||||||
raise Exception("APIKEY Environmental Variable must be set")
|
raise Exception("APIKEY Environmental Variable must be set")
|
||||||
#The hash key
|
# The hash key
|
||||||
HASHKEY:str = bytes(os.getenv('HASHKEY'),'utf-8') #shared secret for hmac of message
|
HASHKEY: str = None
|
||||||
#The prompts used for OpenAI.
|
hashKey = os.getenv('HASHKEY') # shared secret for hmac of message
|
||||||
PROMPTS=["Say \"USERNAME does not give a fuck\" in a thoughtful and clever paragraph of 5 sentences.",
|
if (hashKey is not None and hashKey.replace(" ", "") != ""):
|
||||||
|
HASKHEY = bytes(hashKey, "utf-8")
|
||||||
|
# The prompts used for OpenAI.
|
||||||
|
PROMPTS = ["Say \"USERNAME does not give a fuck\" in a thoughtful and clever paragraph of 5 sentences.",
|
||||||
"Say \"USERNAME does not give a fuck\" in a Dr Suess poem.",
|
"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."]
|
"Tell me all about how much \"USERNAME does not give a fuck\" using your most colorful words."]
|
||||||
OPEN_AI_MAX_TOKENS=500
|
OPEN_AI_MAX_TOKENS = 500
|
||||||
OPEN_AI_COMPLETION_MODEL="text-davinci-003"
|
OPEN_AI_COMPLETION_MODEL = "text-davinci-003"
|
||||||
MAX_MESSAGE_AGE=600
|
MAX_MESSAGE_AGE = 600
|
||||||
|
Loading…
x
Reference in New Issue
Block a user