From 6f4f7f8ac3421faa5ee73d397395320e68169a41 Mon Sep 17 00:00:00 2001 From: adamoutler Date: Sun, 5 Feb 2023 21:28:41 +0000 Subject: [PATCH] Initial GAF --- .devcontainer/devcontainer.json | 29 ++++++ .vscode/extensions.json | 5 + .vscode/settings.json | 5 + README.md | 0 src/aidgaf/aidgaf-server/__init__.py | 3 + .../__pycache__/idgaf.cpython-39.pyc | Bin 0 -> 3008 bytes .../__pycache__/settings.cpython-39.pyc | Bin 0 -> 331 bytes src/aidgaf/aidgaf-server/idgaf.py | 90 ++++++++++++++++++ src/aidgaf/aidgaf-server/server.py | 17 ++++ src/aidgaf/aidgaf-server/settings.py | 7 ++ src/aidgaf/setup.py | 12 +++ 11 files changed, 168 insertions(+) create mode 100755 .devcontainer/devcontainer.json create mode 100644 .vscode/extensions.json create mode 100644 .vscode/settings.json create mode 100644 README.md create mode 100644 src/aidgaf/aidgaf-server/__init__.py create mode 100644 src/aidgaf/aidgaf-server/__pycache__/idgaf.cpython-39.pyc create mode 100644 src/aidgaf/aidgaf-server/__pycache__/settings.cpython-39.pyc create mode 100644 src/aidgaf/aidgaf-server/idgaf.py create mode 100644 src/aidgaf/aidgaf-server/server.py create mode 100644 src/aidgaf/aidgaf-server/settings.py create mode 100644 src/aidgaf/setup.py diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100755 index 0000000..da9f50e --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,29 @@ +// For format details, see https://aka.ms/devcontainer.json. For config options, see the +// README at: https://github.com/devcontainers/templates/tree/main/src/debian +{ + "name": "Debian", + // Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile + "image": "mcr.microsoft.com/devcontainers/base:bullseye", + "features": { + "ghcr.io/devcontainers/features/python:1": {} + }, + "onCreateCommand": "pip install openai; apt update; apt install git", + "customizations": { + "vscode": { + "extensions": [ + "pomdtr.secrets" + ] + } + } + // Features to add to the dev container. More info: https://containers.dev/features. + // "features": {}, + + // Use 'forwardPorts' to make a list of ports inside the container available locally. + // "forwardPorts": [], + + // Configure tool-specific properties. + // "customizations": {}, + + // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. + // "remoteUser": "root" +} diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..f7cafaf --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,5 @@ +{ + "recommendations": [ + "pomdtr.secrets" + ] +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..0ac257d --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "secrets.enabledFolders": [ + "aidgaf" + ] +} \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/src/aidgaf/aidgaf-server/__init__.py b/src/aidgaf/aidgaf-server/__init__.py new file mode 100644 index 0000000..8f68f05 --- /dev/null +++ b/src/aidgaf/aidgaf-server/__init__.py @@ -0,0 +1,3 @@ + + +name = 'aidgaf' \ No newline at end of file diff --git a/src/aidgaf/aidgaf-server/__pycache__/idgaf.cpython-39.pyc b/src/aidgaf/aidgaf-server/__pycache__/idgaf.cpython-39.pyc new file mode 100644 index 0000000000000000000000000000000000000000..76841ca9c0e3b7f525789af2904bfd6d83d068ac GIT binary patch literal 3008 zcma)8O>^7E8OGv^6iHdKEn9Mvb}*b|TDFlWlBP(iY9@;9#F^N##-jUy=@hfXEaG7IhyH>+Wu_+|`Ug7GPTv5+~PoE_FsuxVmV%7+5?T{*%B*!Z@SB@$d`_9t!u2rmcQ5C zmCrSHi>-XCu@!E-Hr!RV%5HzFxwqLJb{FzHY>nN6{4TriuJL6isvr~9HHPx{Y|;jG6lf`sK55`r%N@IN7aMX*}ABVm_v$Ek6pY zr?o0%aR75f_jK)xu!)P)X z%Kjv9U}=sYa9ENPQ$YuU#zQCSJ549yW68%pPqwD5|9j@g!a0I1Cr%vkaBJ#zc@Q`u zd>%5|izd<;MrTeq@rV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YaK zWf~J@ozh^!#Ru4xO6V?@e)7k(l$uL^FZ0%qQKtz8G(RUhx-{InZGpKMIos#g)>IyH+b(Ri3uW847dLKlc@x{!asZXY5g% zmF;*fE#rc3G&`4e<#fk*D;j=xT;FrobdGl|v!?!4|AtnYtu)L^=UUa+lkUk!$wrHZ QwLHaei46f_azGBr4<~9^B>(^b literal 0 HcmV?d00001 diff --git a/src/aidgaf/aidgaf-server/idgaf.py b/src/aidgaf/aidgaf-server/idgaf.py new file mode 100644 index 0000000..4d3cc50 --- /dev/null +++ b/src/aidgaf/aidgaf-server/idgaf.py @@ -0,0 +1,90 @@ +import json +import requests +from http.server import BaseHTTPRequestHandler, HTTPServer +import time +from datetime import datetime +import openai +import random +import settings + +openai.organization = "org-hNNV1yHjZp7T3pn5pdZWaKLm" +#print(openai.Model.list()) + + + +URL="https://api.openai.com/v1/completions" +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.", + "Tell me all about how much \"USERNAME does not give a fuck\" using your most colorful words."] +DATA = {"model": "text-davinci-003", + "prompt": PROMPTS[0], + "temperature":1, + "max_tokens": 200 +} + +request_headers={"Authorization": "Bearer "+settings.APIKEY,"Content-Type": "application/json"} + + +class IDGAFServer(BaseHTTPRequestHandler): + + def do_PATCH(self): +# print("Request: "+self.request+ " "+webServer.get_request()) + request_body=self.rfile.read(int(self.headers.get('Content-Length'))) + command=json.loads(request_body) + print(command) + if command['message']['command'] == 'aidgaf': + [responseCode,response_body]=parse_idgaf_request(command) + self.handle_response(responseCode,response_body) + print("sending:"+response_body) + + + + def handle_response(self,code,body): + self.send_response(code) + self.send_header("Content-type", "text/html") + self.end_headers() + self.wfile.write(bytes(body,"UTF-8")) + + +def get_response_base_object(text): + resultObject={} + resultObject["message"]={} + resultObject["message"]["data"]={} + resultObject["message"]["data"]["resultObject"]=text + resultObject["timestamp"]=datetime.utcnow().timestamp() + return resultObject + + +def parse_idgaf_request(command): + the_data=get_prompt(command) + gpt_response=requests.post(URL, json=the_data, headers=request_headers) + print(gpt_response) + response_text=gpt_response.json()['choices'][0]['text'].strip() + obj=get_response_base_object(response_text) + json_result=json.dumps(obj) + return [gpt_response.status_code,json_result] + +def get_prompt(command): + my_prompt=random.choice(PROMPTS) + my_prompt=my_prompt.replace("USERNAME",command['message']['data']['username']) + + print("Prompt selected: "+my_prompt) + the_data=DATA + the_data["prompt"]=my_prompt + return the_data + + +value='{"service": "papa", "message": {"command": "aidgaf", "data": {"username": "AdamOutler"}, "timestamp": 1675373229}, "hash": "de08e85b8afc3b7d257fa559fd1dd295838ea1387f1e0fa75ceb11d9da81e59fadfc878d028281dfb739002bae818b89a8363e49d68e923874c969716a90f8e3"}' +if __name__ == "__main__": + print(parse_idgaf_request(command=json.loads(value))) + + +#curl https://api.openai.com/v1/completions \ +# -H "Content-Type: application/json" \ +# -H "Authorization: Bearer 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" \ +# -d '{"model": "text-curie-001", +# "prompt": "Say \"Adam does not give a fuck\" in a thoughtful and clever prose consisting of one to five paragraphs.", +# "temperature":1, "max_tokens": 500}' +# |jq -r .choices[0].text +# curl -X PATCH 127.0.0.1:8087 -d '{"message":{"command":"aidgaf","data":{"username":"AdamOutler"}}}' +#2,500,000 tokens = $5 \ No newline at end of file diff --git a/src/aidgaf/aidgaf-server/server.py b/src/aidgaf/aidgaf-server/server.py new file mode 100644 index 0000000..6e81c4e --- /dev/null +++ b/src/aidgaf/aidgaf-server/server.py @@ -0,0 +1,17 @@ +import idgaf +from idgaf import IDGAFServer +from http.server import HTTPServer +import settings + + +if __name__ == "__main__": + webServer = HTTPServer((settings.HOSTNAME, settings.SERVERPORT), idgaf.IDGAFServer) + print("Server started http://%s:%s" % (settings.HOSTNAME, settings.SERVERPORT)) + + try: + webServer.serve_forever() + except KeyboardInterrupt: + pass + + webServer.server_close() + print("Server stopped.") diff --git a/src/aidgaf/aidgaf-server/settings.py b/src/aidgaf/aidgaf-server/settings.py new file mode 100644 index 0000000..e863195 --- /dev/null +++ b/src/aidgaf/aidgaf-server/settings.py @@ -0,0 +1,7 @@ +import os +#The hostname used by this app +HOSTNAME:str = os.getenv('HOSTNAME') #localhost +#The port to broadcast the server +SERVERPORT:int = int(os.getenv('SERVERPORT')) #8087 +#The API key for OpenAI +APIKEY:str = os.getenv('APIKEY') #secret key \ No newline at end of file diff --git a/src/aidgaf/setup.py b/src/aidgaf/setup.py new file mode 100644 index 0000000..eac3869 --- /dev/null +++ b/src/aidgaf/setup.py @@ -0,0 +1,12 @@ +from setuptools import setup, find_namespace_packages + +setup( + name='aidgaf', + version='1', + description='', + long_description='', + author='Adam Outler', + author_email='adamoutler@gmail.com', + license='IDGAF License', + packages=find_namespace_packages(include=['aidgaf-server.*']) +) \ No newline at end of file