Compare commits
2 Commits
d497707a05
...
751affef70
Author | SHA1 | Date | |
---|---|---|---|
|
751affef70 | ||
|
2503b8ecaa |
7
Jenkinsfile
vendored
7
Jenkinsfile
vendored
@ -45,14 +45,13 @@ pipeline {
|
|||||||
string(credentialsId: 'OpenAI-API-Token', variable: 'OPEN_AI_TOKEN'),
|
string(credentialsId: 'OpenAI-API-Token', variable: 'OPEN_AI_TOKEN'),
|
||||||
string(credentialsId: 'PapaHashingSecret', variable: 'PAPA_HASH'),
|
string(credentialsId: 'PapaHashingSecret', variable: 'PAPA_HASH'),
|
||||||
string(credentialsId: 'PapaAsyncUrl', variable: 'ASYNC_URL'),
|
string(credentialsId: 'PapaAsyncUrl', variable: 'ASYNC_URL'),
|
||||||
sshUserPrivateKey(credentialsId: 'dockeruserOn192.168.1.115', keyFileVariable: 'sshkey')
|
sshUserPrivateKey(credentialsId: 'dockeruserOn192.168.1.115', keyFileVariable: 'sshkey')]) {
|
||||||
]) {
|
|
||||||
sh '#!/bin/sh \n' +
|
sh '#!/bin/sh \n' +
|
||||||
'mkdir -p ~/.ssh; cp "$sshkey" ~/.ssh/id_rsa'
|
'mkdir -p ~/.ssh; cp "$sshkey" ~/.ssh/id_rsa'
|
||||||
sh '#!/bin/sh \n' +
|
sh '#!/bin/sh \n' +
|
||||||
/* groovylint-disable-next-line GStringExpressionWithinString */
|
/* groovylint-disable-next-line GStringExpressionWithinString */
|
||||||
'docker run --name=aidgaf-server -eSERVERPORT=8087 -eHOSTNAME=0.0.0.0 -eHASHKEY="${PAPA_HASH}" -eAPIKEY="${OPEN_AI_TOKEN}" -eASYNC_METHOD="PATCH" -eASYNC_URL="${PapaAsyncUrl}" -p8087:8087 -d --restart=always aidgaf'
|
'docker run --name=aidgaf-server -eSERVERPORT=8087 -eHOSTNAME=0.0.0.0 -eHASHKEY="${PAPA_HASH}" -eAPIKEY="${OPEN_AI_TOKEN}" -eASYNC_METHOD="PATCH" -eASYNC_URL="${ASYNC_URL}" -p8087:8087 -d --restart=always aidgaf'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,7 @@ from const import UTF8, REPORTING_TIMEOUT
|
|||||||
default_request_body = b'{"message":{"command":"aidgaf","data":{"username":"AdamOutler"}}}'
|
default_request_body = b'{"message":{"command":"aidgaf","data":{"username":"AdamOutler"}}}'
|
||||||
request_headers = {}
|
request_headers = {}
|
||||||
|
|
||||||
|
|
||||||
class IDGAFServer(BaseHTTPRequestHandler):
|
class IDGAFServer(BaseHTTPRequestHandler):
|
||||||
""" This class handles the requests from the client. """
|
""" This class handles the requests from the client. """
|
||||||
|
|
||||||
@ -28,7 +29,7 @@ class IDGAFServer(BaseHTTPRequestHandler):
|
|||||||
def do_PATCH(self):
|
def do_PATCH(self):
|
||||||
""" This function handles PATCH requests. """
|
""" This function handles PATCH requests. """
|
||||||
body = self.get_body().decode(UTF8)
|
body = self.get_body().decode(UTF8)
|
||||||
check_result=perform_sanity_checks(body)
|
check_result = perform_sanity_checks(body)
|
||||||
if check_result:
|
if check_result:
|
||||||
self.send_response(403)
|
self.send_response(403)
|
||||||
self.end_headers()
|
self.end_headers()
|
||||||
@ -52,26 +53,28 @@ class IDGAFServer(BaseHTTPRequestHandler):
|
|||||||
Parameters:
|
Parameters:
|
||||||
command: The command object received from the client. """
|
command: The command object received from the client. """
|
||||||
if not settings.ASYNC_URL:
|
if not settings.ASYNC_URL:
|
||||||
[code,body]=self.getGPTResponse(command)
|
[code, body] = self.getGPTResponse(command)
|
||||||
self.handle_response(code,body)
|
self.handle_response(code, body)
|
||||||
return
|
return
|
||||||
|
|
||||||
thread = threading.Thread(target=self.send_async_request, args=(command,))
|
thread = threading.Thread(
|
||||||
|
target=self.send_async_request, args=(command,))
|
||||||
thread.start()
|
thread.start()
|
||||||
self.handle_response(200,json.dumps(command))
|
self.handle_response(200, json.dumps(command))
|
||||||
|
|
||||||
def send_async_request(self,command):
|
def send_async_request(self, command):
|
||||||
""" This function sends the request to the async URL. It will generate a
|
""" This function sends the request to the async URL. It will generate a
|
||||||
response and send it to the client. This function is called in a separate
|
response and send it to the client. This function is called in a separate
|
||||||
thread. It will not block the main thread.
|
thread. It will not block the main thread.
|
||||||
|
|
||||||
Parameters:
|
Parameters:
|
||||||
command: The command object received from the client. """
|
command: The command object received from the client. """
|
||||||
[code,body] = self.getGPTResponse(command)
|
print("using async for response")
|
||||||
merged=merge.merge_dict_no_overwrite(json.loads(body),command)
|
[code, body] = self.getGPTResponse(command)
|
||||||
merged['hash']=security.get_message_hash(json.dumps(merged))
|
merged = merge.merge_dict_no_overwrite(json.loads(body), command)
|
||||||
merged['service']='JavaShark'
|
merged['hash'] = security.get_message_hash(json.dumps(merged))
|
||||||
data=json.dumps(merged)
|
merged['service'] = 'JavaShark'
|
||||||
|
data = json.dumps(merged)
|
||||||
print(str(code)+": "+data)
|
print(str(code)+": "+data)
|
||||||
|
|
||||||
if (code != 200):
|
if (code != 200):
|
||||||
@ -83,12 +86,10 @@ class IDGAFServer(BaseHTTPRequestHandler):
|
|||||||
requests.put(settings.ASYNC_URL, data=data, headers=request_headers,
|
requests.put(settings.ASYNC_URL, data=data, headers=request_headers,
|
||||||
timeout=REPORTING_TIMEOUT)
|
timeout=REPORTING_TIMEOUT)
|
||||||
elif (settings.ASYNC_METHOD == "PATCH"):
|
elif (settings.ASYNC_METHOD == "PATCH"):
|
||||||
resp=requests.patch(settings.ASYNC_URL, data=data, headers=request_headers,
|
resp = requests.patch(settings.ASYNC_URL, data=data, headers=request_headers,
|
||||||
timeout=REPORTING_TIMEOUT)
|
timeout=REPORTING_TIMEOUT)
|
||||||
print(str(resp)+resp.text)
|
print(str(resp)+resp.text)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# gpt_response = requests.post(URL, json=data, headers=request_headers)
|
# gpt_response = requests.post(URL, json=data, headers=request_headers)
|
||||||
|
|
||||||
def getGPTResponse(self, command) -> [int, str]:
|
def getGPTResponse(self, command) -> [int, str]:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user