Initial GAF
This commit is contained in:
commit
6f4f7f8ac3
29
.devcontainer/devcontainer.json
Executable file
29
.devcontainer/devcontainer.json
Executable file
@ -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"
|
||||||
|
}
|
5
.vscode/extensions.json
vendored
Normal file
5
.vscode/extensions.json
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"recommendations": [
|
||||||
|
"pomdtr.secrets"
|
||||||
|
]
|
||||||
|
}
|
5
.vscode/settings.json
vendored
Normal file
5
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"secrets.enabledFolders": [
|
||||||
|
"aidgaf"
|
||||||
|
]
|
||||||
|
}
|
3
src/aidgaf/aidgaf-server/__init__.py
Normal file
3
src/aidgaf/aidgaf-server/__init__.py
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
|
||||||
|
|
||||||
|
name = 'aidgaf'
|
BIN
src/aidgaf/aidgaf-server/__pycache__/idgaf.cpython-39.pyc
Normal file
BIN
src/aidgaf/aidgaf-server/__pycache__/idgaf.cpython-39.pyc
Normal file
Binary file not shown.
BIN
src/aidgaf/aidgaf-server/__pycache__/settings.cpython-39.pyc
Normal file
BIN
src/aidgaf/aidgaf-server/__pycache__/settings.cpython-39.pyc
Normal file
Binary file not shown.
90
src/aidgaf/aidgaf-server/idgaf.py
Normal file
90
src/aidgaf/aidgaf-server/idgaf.py
Normal file
@ -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
|
17
src/aidgaf/aidgaf-server/server.py
Normal file
17
src/aidgaf/aidgaf-server/server.py
Normal file
@ -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.")
|
7
src/aidgaf/aidgaf-server/settings.py
Normal file
7
src/aidgaf/aidgaf-server/settings.py
Normal file
@ -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
|
12
src/aidgaf/setup.py
Normal file
12
src/aidgaf/setup.py
Normal file
@ -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.*'])
|
||||||
|
)
|
Loading…
x
Reference in New Issue
Block a user