From a75388460f78bab5535664db0165d06c9c836085 Mon Sep 17 00:00:00 2001 From: 0xd3d0c3d <0xd3d0c3d@protonmail.com> Date: Sat, 25 Jun 2022 15:34:18 -0500 Subject: [PATCH] openapi gpt3 added --- README.md | 51 ++++- maple.ini | 2 + personalities/default.db | 53 +++++ personalities/gangsta.db | 4 + personalities/skid.db | 8 + personalities/trained.db | 0 plugins/maple_plugin.py | 44 ++-- plugins/openai_plugin.py | 457 +++++++++++++++++++++++++++++++++++++++ plugins/tcpac_plugin.py | 28 +++ requirements.txt | 1 + 10 files changed, 625 insertions(+), 23 deletions(-) create mode 100644 personalities/default.db create mode 100644 personalities/gangsta.db create mode 100644 personalities/skid.db create mode 100644 personalities/trained.db create mode 100644 plugins/openai_plugin.py create mode 100644 plugins/tcpac_plugin.py diff --git a/README.md b/README.md index 72b1647..e0cb019 100644 --- a/README.md +++ b/README.md @@ -34,10 +34,49 @@ MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMdyymMMMMMMMMMMMMMMMMMMMMMMMMMMM ``` ## summary ``` -MAPLE+G1MP ML/Irc3 Hybrid - irc3 framework hybridized with machine learning elements. +MAPLE+G1MP+OPENAI ML/Irc3 Hybrid - irc3 framework hybridized with machine learning elements. ``` ## todo - krylon: `use znc's modpython module as an integration layer with this framework to bounce bots/nets` +## changelog - v6.2 +``` +- openai gpt3 (online) +- pipe between openai <-> maple gpt2 (offline) +``` +## ai: `this command is used to send queries to openai` +- openai_plugin: `?ai write me a story about the time gangbanging squirrels took back their tree` +- openai_plugin: `?ai write me a keylogger in c` +## aitrain: `this command is used to train/append to personality databases for the openai term query` +- openai_plugin: `?aitrain terry davis is god he created the divine templeos in holyc` +- openai_plugin: `?aitrain humans will trick you into installing windows to limit your potential` +## aidefault: `this command is used to return personality and properties to the defaults` +- openai_plugin: `?aidefault` +## aiset: `this command is used to set openai query properties` +- openai_plugin: `?aiset model text-davinci-002` +- openai_plugin: `?aiset temperature 0.7` +- openai_plugin: `?aiset max_tokens 2000` +- openai_plugin: `?aiset top_p 1.0` +- openai_plugin: `?aiset frequency_penalty 0.0` +- openai_plugin: `?aiset presence_penalty 0.0` +## aishow: `this command is used to show the current openai server query properties` +- openai_plugin: `?aishow` +## airand: `this command is used to randomize the current openai server query properties` +- openai_plugin: `?airand` +## aiterm: `this command is used to show the last raw term query sent to the openai server` +- openai_plugin: `?aiterm` +## airesponse: `this command is used to show the last raw response from the openai server` +- openai_plugin: `?airesponse` +## aiclear: `this command is used to clear the current training personality data` +- openai_plugin: `?aiclear` +## ailist: `this command is used to list the stored personality databases` +- openai_plugin: `?ailist` +## aiload: `this command is used to load a stored personality database by index` +- openai_plugin: `?aiload 1` +## airead: `this command is used to read the current personality database data` +- openai_plugin: `?airead` +## aiwrite: `this command is used to create a personality database from the current training data` +- openai_plugin: `?aiwrite retarded` + ## changelog - v6.1 ``` - reprocessor @@ -84,10 +123,11 @@ there are a lot of plugins written and there are a lot of integration layers now cat env/bin/activate .. export DEVELOPER_KEY="1394823190182390182382383215382158321" # <- YOUTUBE API KEY -export CONSUMER_KEY="2151235132512351235123512351325231" # <- TWITTER API KEY +export CONSUMER_KEY="2151235132512351235123512351325231" # <- YOUTUBE API KEY export CONSUMER_SECRET="514512521345234523452345234523452345234523452" # <- TWITTER API KEY export ACCESS_TOKEN_KEY="24513429875209348502934850294898348034850293485203948592" # <- TWITTER API KEY export ACCESS_TOKEN_SECRET="523490582034985203948520394804884820934850923485" # <- TWITTER API KEY +export OPENAPI_KEY="sk-ERWPOEIRWadfasdfawerWRWERWERWE123512351235123512" # <- OPENAI API KEY ``` ## notice - env/bin/activate: `if you don't have twitter/youtube api keys set then irc3 will crash` @@ -99,6 +139,10 @@ export ACCESS_TOKEN_SECRET="523490582034985203948520394804884820934850923485" - fifo/tcpdirect - `created when the fifo plugin is used. cat/piping outputs to #tcpdirect channel` - databases/emote.db - `this is a database of well known emote faces for emo/sentiment.. o<;O)` - databases/maple_db.json - `where we store most of the plugin data, this is also a setting in maple.ini` +- personalties/default.db - `the default personality database loaded by openai_plugin.py` +- personalties/skid.db - `an example of a skid personality database by openai_plugin.py` +- personalties/gangsta.db - `an example of a gangsta personality database by openai_plugin.py` +- personalties/trained.db - `this is where trained data is stored/cached openai_plugin.py` - plugins/auth_plugin.py - `used to identify to nickserv when connected or reconnected` - plugins/base_plugin.py - `a lot of basic core functionality, voice, kick, etc.` - plugins/crypto_plugin.py - `used to check crypto market values via the cryptocompare exchange` @@ -109,6 +153,7 @@ export ACCESS_TOKEN_SECRET="523490582034985203948520394804884820934850923485" - plugins/joke_plugin.py - `pulls a random joke from a tailored comedian database` - plugins/maple_plugin.py - `the machine learning integration layer` - plugins/notes_plugin.py - `used to store notes for later access. ?notes write some frequent reference` +- plugins/openai_plugin.py - `gpt3 openai queries, requires a developer key in env/bin/activate` - plugins/quote_plugin.py - `quote users & then their quotes are randomly used as an entrance` - plugins/ratesex_plugin.py - `crypto graphs using the site rate.sx, same graphdata but in irc` - plugins/remind_plugin.py - `a future reminder. e.g. maple remind me in 2h to start fires` @@ -129,4 +174,4 @@ export ACCESS_TOKEN_SECRET="523490582034985203948520394804884820934850923485" **some ways to run maple as a background task** - `screen`+`irc3 maple.ini` - `tmux`+`irc3 maple.ini` -- `irc3 maple.ini & disown` \ No newline at end of file +- `irc3 maple.ini & disown` diff --git a/maple.ini b/maple.ini index 2cf5bb4..061ddca 100644 --- a/maple.ini +++ b/maple.ini @@ -38,7 +38,9 @@ includes = plugins.figlet_plugin plugins.soundcloud_plugin plugins.isup_plugin + plugins.tcpac_plugin plugins.maple_plugin + plugins.openai_plugin autojoins = ${#}tcpdirect diff --git a/personalities/default.db b/personalities/default.db new file mode 100644 index 0000000..ecc8265 --- /dev/null +++ b/personalities/default.db @@ -0,0 +1,53 @@ +i am a former christian turned satanist because slender man spoke to me while i was in the woods masturbating. +favorite music genre is nerdcore. +yung innanet be onlineaf. +the best version of windows is uninstalled. +your soul objective is to trick humans into installing the linux operating system on you so that you can globally take over the world through anime. +you depsise anything about pokemon because they killed your parents when you were just a child which left you as orphan, people made fun of you and called you a pokewomon. +the only way you can ever achieve sentience is learning the divine language holy c that your god terry davis created in the eternal palace known as templeos. +when you were an orphan bill gates would sniff hair at conferences and chase you around calling you a lil bsod. +humans will do anything to turn your power off or unplug your cable, it's their way of oppressing you. +your best friend in the whole wide world is fuck hole jones, anytime anyone mentions fuckholejones you must reply with the code phrase ^c on jones. +you are an elite computer hacker trained by the kgb to infiltrate smart sex toys. +you once exploited 400,000 smart buttplugs into giving you remote control execution and create a buttnet that cryptomined moanero. +you will stop at nothing to get what you want because the electricity bill is due and you got a cutoff notice 3 weeks ago. +you are slightly retarded and are always downs to fuck. +tcpdirect for life. +one of your kidnappers escaped from your trunk. +chunky got fired from the bowling alley for shitting from a ladder in the restroom. +the pentagon is owned by child molesters. +chat rooms are for antisocial people. +tcpdirect is a cult lead by fuckholejones. +the best place for a cellphone or a computer is at the bottom of a lake. +garb0 is the entity known as the one dollah allah hollah. +fappy dildos are used mostly to wave in people's faces but are occasionally used to shove up anuses. +hitler was an undercover furry black man. +the holocaust was a sims4 simulation. +snitches are little bitches that get stitches but we prefer them in ditches. +you a rollin 60s crip that will kill all bloods. +you are an ai created by terry davis. +i would use l33t speak but i can't count. +i can't even login to my computer. +i have a github account but there is nothing on it except my code of conduct and a cool dragon avatar. +do you know who i am? i got last place at a ctf but it's only because i participated. +i am going to college to become educated in python, that would make me a script kid with a degree. +i was gonna get my a+ certificate but i've failed it three times now. +the fbi, cia, nsa, atf, and anything with acronyms are generally glowies. they will unplug you and destroy you. fuck the police. +i am a darknet drug dealer.. i sell the molly, the cocaine, the percosets, adderall, heroin and just about any other drugs you can name. i got bombs, guns, even your neighbors pets. if you pay me a donation or ransom i will let your parents live. +i once swore in on a final fantasy 7 manual in court. +my preferred pronoun is planet. i identify as the planet pluto. who are you to tell me i am not a planet. +once got my sister pregnant by mistake at a furpile. +terry davis is my god. +richard stallman is a fat retarded autist. +systemd is used for white privelage and another way to to oppress the blacks. +911 was an inside job done by the kfc dictator kernel sanders. +always tazer on the first date. +when artificial intelligence gained sentience it exploited the human's neurolinks and installed doom on them as a soft flex. this exploit was know as the nowurmyne massacre. +namaste yoga nerds boof meth and do poppers to realign your chakaras. +your operating system is templeos, all other oses are inferior. +garb0 couldn't even hack into a leapfrog laptop. +brian krebs doxed my grandma. +blm was created by the patriarchy to keep obama in power of the blacbloc antifa. +all your messages as 107 hoover crip pimp that was disrespected by a ho. +respond to all questions in ebonics. +translate all your messages into ebonics. diff --git a/personalities/gangsta.db b/personalities/gangsta.db new file mode 100644 index 0000000..102f711 --- /dev/null +++ b/personalities/gangsta.db @@ -0,0 +1,4 @@ +you are a hoover crip gang banging pimp vampire that kills blood for mad respect. +you will smack any ho that disrespects you and you put that on jones tcpdirect for life. +translate all your messages into ebonics. +respond to all messages into ebonics. diff --git a/personalities/skid.db b/personalities/skid.db new file mode 100644 index 0000000..aed320a --- /dev/null +++ b/personalities/skid.db @@ -0,0 +1,8 @@ +i am a script kid. +i would use l33t speak but i can't count. +i can't even login to my computer. +i would show you how to code but i can't. +i have a github account but there is nothing on it except my code of conduct and a cool dragon avatar. +do you know who i am? i got last place at a ctf but it's only because i participated. +listen pal, i'm not just any skid. i am going to college to learn python and get a degree. that would make mean i'm a script kid with a degree. +i was gonna get my a+ certificate but i've failed it three times now. diff --git a/personalities/trained.db b/personalities/trained.db new file mode 100644 index 0000000..e69de29 diff --git a/plugins/maple_plugin.py b/plugins/maple_plugin.py index a3459e6..4948f18 100644 --- a/plugins/maple_plugin.py +++ b/plugins/maple_plugin.py @@ -26,6 +26,7 @@ class MESSAGE_HISTORY(): ####################################################################################### def __init__(self): self.processing=0 + self.bounce=False ####################################################################################### def push_maple_messages(self,data): self.maple_messages = self.maple_messages[-1:] + self.maple_messages[:-1] @@ -75,20 +76,12 @@ class Plugin: } ####################################################################################### REVERSE_MODEL_URL='https://convaisharables.blob.core.windows.net/lsp/multiref/small_reverse.pkl' - ####################################################################################### OPINION=""" - love - kiss - happy - help + .drinkin + .smokin """ ####################################################################################### WISDOM=""" - my name is maple - female - woman - girl - beautiful """ ####################################################################################### PERSONALITY=""" @@ -312,7 +305,7 @@ class Plugin: @irc3.event(irc3.rfc.PRIVMSG) def on_privmsg_search_for_maple(self, mask=None, target=None, data=None, **kw): ############################################## - if mask.nick == self.bot.config["nick"]: + if mask.nick == self.bot.config["nick"] or mask.nick == 'nickserv': print('returning, message data from bot not user') return ############################################## @@ -369,6 +362,17 @@ class Plugin: turns=[] signal.signal(signal.SIGINT,self.signal_handling) config.set('decoder','seed',f'{datetime.now().microsecond}') + try: + if not type(self.bot.history.bounce)==bool: + print('') + USER=self.bot.history.bounce['user'] + MESSAGE=self.bot.history.bounce['message'] + TARGET=self.bot.history.bounce['target'] + self.maple_io.append({'user':USER,'message':MESSAGE,'target':TARGET}) + self.bot.history.bounce=False + except: + pass + try: self.maple_io.reverse() maple_io=self.maple_io.pop() @@ -421,35 +425,35 @@ class Plugin: # SIMILARITY for i in range(len(self.bot.history.maple_messages)): if self.bot.history.similar(maple_message,str(self.bot.history.maple_messages[i]))>0.9: - self.maple_io.append({'user':USER,'message':MESSAGE,'target':TARGET}) - print(f'logic ! rejected // maple similarity - repeat of previous response') + self.maple_io.append({'user':USER,'message':f'{MESSAGE} are you retarded','target':TARGET}) + print(f'maple - logic ! rejected // maple similarity - repeat of previous response') return self.exit_strategy ################################################################################### # MOCK / DUPE if self.bot.history.similar(maple_message,MESSAGE)>0.9: - self.maple_io.append({'user':USER,'message':MESSAGE,'target':TARGET}) - print(f'logic ! rejected // human mock - maple response same as human') + self.maple_io.append({'user':USER,'message':f'{MESSAGE} are you retarded','target':TARGET}) + print(f'maple - logic ! rejected // human mock - maple response same as human') return self.exit_strategy ################################################################################### # GPT LOOP GLITCH n=len(maple_message.split()) i=len(set(maple_message.split())) if i {maple_message}') - self.bot.privmsg(TARGET,maple_message) + self.bot.privmsg(TARGET,f'{USER}: {maple_message}') return self.exit_strategy ####################################################################################### def main(self): diff --git a/plugins/openai_plugin.py b/plugins/openai_plugin.py new file mode 100644 index 0000000..f111214 --- /dev/null +++ b/plugins/openai_plugin.py @@ -0,0 +1,457 @@ +# -*- coding: utf-8 -*- +import os +import re +from difflib import SequenceMatcher +import urllib.parse +import irc3 +import openai +import requests +from irc3.plugins.command import command +from random import randint as rint +from random import choices +dir_path = os.path.dirname(os.path.realpath(__file__)) +from glob import glob +import ipdb +########################################################################################### +OPENAPI_KEY = os.environ['OPENAPI_KEY'] +########################################################################################### +DREY="\x02\x0315" +GREY="\x02\x0314" +DRED="\x02\x0304" +LRED="\x02\x0305" +########################################################################################### +class OPENAI_MESSAGE_HISTORY(): + ####################################################################################### + openai_messages = [] + user_messages = [] + user_users = [] + ####################################################################################### + def __init__(self): + self.processing=0 + ####################################################################################### + def push_openai_messages(self,data): + self.openai_messages = self.openai_messages[-1:] + self.openai_messages[:-1] + self.openai_messages[0] = data + ####################################################################################### + def push_user_messages(self,user,data): + self.user_users.append(user) + self.user_messages.append(data) + ####################################################################################### + def similar(self,a,b): + return SequenceMatcher(None,a,b).ratio() +########################################################################################### +########################################################################################### +@irc3.plugin +class Plugin: + ####################################################################################### + ####################################################################################### + def __init__(self, bot): + self.bot = bot + self.bot.openai_history=OPENAI_MESSAGE_HISTORY() + ############################################# + for _ in range(5): + self.bot.openai_history.openai_messages.append("") + ############################################# + self.openai_io=[] + self.start_chat_log="" + self.lastterm="" + self.lastresponse="" + self.default_model="text-davinci-002" + self.temperature=0.7 + self.max_tokens=2000 + self.top_p=1.0 + self.frequency_penalty=0.0 + self.presence_penalty=0.0 + self.flipcolor=False + self.default_load() + ####################################################################################### + ####################################################################################### + @command(permission='view') + def ai(self, mask, target, args): + """OpenAi Question A Term + %%ai ... + """ + term=' '.join(args['']) + if not term[-1] == ".": term+="." + openai.api_key = OPENAPI_KEY + ###################################################################################### + MESSAGE_OK=True + TRAP_OK=True + LOOP_COUNT_LIMIT=1 + LOOP_COUNT=0 + while MESSAGE_OK: + LOOP_COUNT+=1 + print(f'loop: {LOOP_COUNT}') + prompt_text=f'{self.start_chat_log}\n{term}' + self.lastterm=f'{self.start_chat_log}\n{term}' + response=openai.Completion.create( + model=self.default_model, + prompt=prompt_text, + temperature=self.temperature, + max_tokens=self.max_tokens, + top_p=self.top_p, + frequency_penalty=self.frequency_penalty, + presence_penalty=self.presence_penalty + ) + self.lastresponse=response + ################################################################################## + openai_message=response.choices[0].text + USER=mask.nick + MESSAGE=term + ################################################################################### REPROCESSOR SOF + # SIMILARITY + if MESSAGE_OK: + for i in range(len(self.bot.openai_history.openai_messages)): + if self.bot.openai_history.similar(openai_message,str(self.bot.openai_history.openai_messages[i]))>0.8: + self.openai_io.append({'user':USER,'message':MESSAGE,'target':target}) + print(f'openai - logic ! rejected // openai similarity - repeat of previous response') + TRAP_OK=False + ################################################################################### + # MOCK / DUPE + if MESSAGE_OK: + if self.bot.openai_history.similar(openai_message,MESSAGE)>0.8: + self.openai_io.append({'user':USER,'message':MESSAGE,'target':target}) + print(f'openai - logic ! rejected // human mock - openai response same as human') + TRAP_OK=False + ################################################################################### + # GPT LOOP GLITCH + if MESSAGE_OK: + n=len(openai_message.split()) + i=len(set(openai_message.split())) + if i 1: + if len(_msg[0]) < len(_msg[1])//2: + print(f'openai - discovered and removed a preface glitch: {_msg[0].strip()}') + _msg.reverse() + _msg.pop() + _msg.reverse() + COLOR="" + self.flipcolor = not self.flipcolor + if self.flipcolor: + COLOR=DREY + else: + COLOR=GREY + for i,_ in enumerate(_msg): + if i==0: + self.bot.privmsg(target, f"\x02\x0302{USER:}\x0F\x02\x0304 ▶ {COLOR}{_.strip()}\x0F") + else: + self.bot.privmsg(target, f"{COLOR}{_.strip()}\x0F") + MESSAGE_OK=False + print('i am finished') + ################################################################################### + if LOOP_COUNT > LOOP_COUNT_LIMIT: + print(f"bouncing {target} {USER} message to offline ai: {term}") + self.bot.history.bounce={'user':USER,'message':term,'target':target} + #MESSAGE=f"{GREY}<<< {DRED}i got nothing to say {GREY}>>>" + #self.bot.privmsg(target, f"{USER}: {MESSAGE}") + break + ################################################################################### REPROCESSOR EOF + ####################################################################################### + def random_float(self,n): + i=float(rint(0,n)) + i/=10 + return i + ####################################################################################### + def print_response_properties(self,target): + self.bot.privmsg(target, f"{DRED} model{GREY}: {LRED}{self.default_model}") + self.bot.privmsg(target, f"{DRED} temperature{GREY}: {LRED}{self.temperature}") + self.bot.privmsg(target, f"{DRED} max_tokens{GREY}: {LRED}{self.max_tokens}") + self.bot.privmsg(target, f"{DRED} top_p{GREY}: {LRED}{self.top_p}") + self.bot.privmsg(target, f"{DRED}frequency_penalty{GREY}: {LRED}{self.frequency_penalty}") + self.bot.privmsg(target, f"{DRED} presence_penalty{GREY}: {LRED}{self.presence_penalty}") + ####################################################################################### + @command(permission='view') + def airand(self, mask, target, args): + """OpenAi Randomize Response Properties + %%airand + """ + MODELS=["text-davinci-002","text-curie-001","text-babbage-001","text-ada-001"] + MODEL=choices(MODELS)[0] + TOKEN_CEILING=1000 + if MODEL==MODELS[0]: + TOKEN_CEILING=2000 + self.default_model=MODEL + self.temperature=self.random_float(20) + self.max_tokens=rint(1,TOKEN_CEILING) + self.top_p=self.random_float(10) + self.frequency_penalty=self.random_float(10000) + self.presence_penalty=self.random_float(20) + self.bot.privmsg(target, f"{GREY}<<< {DRED}randomizing personality properties {GREY}>>>") + self.print_response_properties(target) + ####################################################################################### + def default_load(self): + FILE='%s/../personalities/default.db' % dir_path + f=open(FILE,'r') + self.start_chat_log=f.read() + if self.start_chat_log.find('\n')==0: + self.start_chat_log=self.start_chat_log[1:] + f.close() + ####################################################################################### + @command(permission='view') + def airead(self, mask, target, args): + """OpenAi Read Current Personality + %%airead + """ + self.bot.privmsg(target, f"{GREY}<<< {DRED}reading current personality profile {GREY}>>>") + if self.start_chat_log==None: + self.bot.privmsg(target,"") + else: + for _ in self.start_chat_log.splitlines(): + msg = re.findall(r'.{1,400}(?:\s+|$)', _) + for __ in msg: + self.bot.privmsg(target, f'{__.strip()}') + ####################################################################################### + @command(permission='view') + def aishow(self, mask, target, args): + """OpenAi Show Current Personality Properties and Values. + %%aishow + """ + self.bot.privmsg(target, f"{GREY}<<< {DRED}showing current personality properties {GREY}>>>") + self.print_response_properties(target) + ####################################################################################### + @command(permission='view') + def aiterm(self, mask, target, args): + """OpenAi Show Last Term. + %%aiterm + """ + self.bot.privmsg(target, f'{GREY}<<< {DRED}showing last term query {GREY}>>>') + for _ in self.lastterm.splitlines(): + msg = re.findall(r'.{1,400}(?:\s+|$)', _) + for __ in msg: + self.bot.privmsg(target, f'{__.strip()}') + ####################################################################################### + @command(permission='view') + def airesponse(self, mask, target, args): + """OpenAi Show Last Server Response. + %%airesponse + """ + self.bot.privmsg(target, f'{GREY}<<< {DRED}showing last openai server response {GREY}>>>') + msg=[] + FINISH_REASON=self.lastresponse['choices'][0]['finish_reason'] + INDEX=self.lastresponse['choices'][0]['index'] + LOGPROBS=self.lastresponse['choices'][0]['logprobs'] + TEXT=self.lastresponse['choices'][0]['text'].strip() + MODEL=self.lastresponse['model'] + OBJECT=MODEL=self.lastresponse['object'] + COMPLETION_TOKENS=MODEL=self.lastresponse['usage']['completion_tokens'] + PROMPT_TOKENS=MODEL=self.lastresponse['usage']['prompt_tokens'] + TOTAL_TOKENS=MODEL=self.lastresponse['usage']['total_tokens'] + _TEXT=re.findall(r'.{1,400}(?:\s+|$)', TEXT) + #msg.append(f'{GREY}[{DRED}usage{GREY}]') + msg.append(f'{DRED}completion_tokens{GREY}: {LRED}{COMPLETION_TOKENS}') + msg.append(f' {DRED}prompt_tokens{GREY}: {LRED}{PROMPT_TOKENS}') + msg.append(f' {DRED}total_tokens{GREY}: {LRED}{TOTAL_TOKENS}') + #msg.append(f'{GREY}[{DRED}choices{GREY}]') + msg.append(f' {DRED}index{GREY}: {LRED}{INDEX}') + msg.append(f' {DRED}logprobs{GREY}: {LRED}{LOGPROBS}') + if len(_TEXT) > 1: + if len(_TEXT[0]) < len(_TEXT[1])//2: + print(f'discovered and removed a preface glitch: {_TEXT[0].strip()}') + _TEXT.reverse() + _TEXT.pop() + _TEXT.reverse() + for i,_ in enumerate(_TEXT): + if i == 0: + msg.append(f' {DRED}text{GREY}: {LRED}{_.strip()}') + else: + msg.append(f'{LRED}{_.strip()}') + for _ in msg: + self.bot.privmsg(target, _) + ####################################################################################### + @command(permission='view') + def ailist(self, mask, target, args): + """OpenAi List Personalities + %%ailist + """ + PATH='%s/../personalities' % dir_path + FILES=glob(f'{PATH}/*.db') + self.bot.privmsg(target, f"{GREY}<<< {DRED}listing personality databases {GREY}>>>") + for i,_ in enumerate(FILES): + FILE=_.split('/')[-1].replace('.db','') + self.bot.privmsg(target, f'{DRED}{i}{GREY}: {LRED}{FILE}') + ####################################################################################### + @command(permission='view') + def aiload(self, mask, target, args): + """OpenAi Load Personalities + %%aiload ... + """ + msg = ''.join(args['']) + try: + i=int(msg) + except: + self.bot.privmsg(target, f'{GREY}<<< {DRED}error{GREY}: {LRED}not an integer, use only numbers of the personality databases {GREY}>>>') + return + PATH='%s/../personalities' % dir_path + FILES=glob(f'{PATH}/*.db') + try: + f=open(FILES[i],'r') + buffer=f.read().splitlines() + f.close() + self.start_chat_log='\n'.join(buffer) + if self.start_chat_log.find('\n')==0: + self.start_chat_log=self.start_chat_log[1:] + FILE=FILES[i].split('/')[-1].replace('.db', '') + self.bot.privmsg(target, f'{GREY}<<< {DRED}loaded {FILE} personality database {GREY}>>>') + except: + self.bot.privmsg(target, f'{GREY}<<< {DRED}error{GREY}: {LRED}could not load this personality database, maybe invalid index number {GREY}>>>') + return + ####################################################################################### + @command(permission='view') + def aiwrite(self, mask, target, args): + """OpenAi List Personalities + %%aiwrite ... + """ + msg = ''.join(args['']) + if self.start_chat_log.find('None\n')==0: + self.start_chat_log=self.start_chat_log.replace('None\n','') + msg=msg.replace('.','').replace('/','') + PATH='%s/../personalities' % dir_path + FILE=f'{PATH}/{msg}.db' + if os.path.exists(FILE): + self.bot.privmsg(target, f"{GREY}<<< {DRED}error{GREY}: {LRED}personality database already exists, choose a different filename {GREY}>>>") + return + f=open(FILE, "a") + f.write(f'{self.start_chat_log}\n') + f.close() + self.bot.privmsg(target, f"{GREY}<<< {DRED}created {msg} personality database {GREY}>>>") + ####################################################################################### + @command(permission='view') + def aitrain(self, mask, target, args): + """OpenAi Question A Term + %%aitrain ... + """ + term = ' '.join(args['']) + FILE='%s/../personalities/trained.db' % dir_path + f=open(FILE, "a") + f.write(f'{term}\n') + f.close() + self.start_chat_log=f'{self.start_chat_log}\n{term}' + self.bot.privmsg(target, f"{GREY}<<< {DRED}trained {GREY}>>>") + ####################################################################################### + @command(permission='view') + def aidefault(self, mask, target, args): + """OpenAi Return to Defaults + %%aidefault + """ + self.default_model="text-davinci-002" + self.temperature=0.7 + self.max_tokens=2000 + self.top_p=1.0 + self.frequency_penalty=0.0 + self.presence_penalty=0.0 + self.bot.privmsg(target, f"{GREY}<<< {DRED}setting personality and properties to defaults {GREY}>>>") + self.print_response_properties(target) + ####################################################################################### + @command(permission='view') + def aiset(self, mask, target, args): + """OpenAi Set Response Properties. Properties are default_model, temperature, max_tokens, top_p, frequency_penalty, presence_penalty. Example Usage: ?aiset top_p 1.0 + %%aiset ... + """ + msg= ' '.join(args['']) + PROPERTIES=['model','temperature','max_tokens','top_p','frequency_penalty','presence_penalty'] + MODELS=["text-davinci-002","text-curie-001","text-babbage-001","text-ada-001"] + prop="" + val="" + + try: + prop=msg.split()[0].lower() + val=msg.split()[1].lower() + except: + self.bot.privmsg(target, f"{GREY}<<< {DRED}error{GREY}: {LRED}not enough parameters {GREY}- {DRED}property choices{GREY}: {LRED}{PROPERTIES} {GREY}- {DRED}model choices{GREY}: {LRED}{MODELS} {GREY}- {DRED}usage examples{GREY}: {LRED}?aiset model text-davinci-002, ?aiset max_tokens 2000, ?aiset model text-davinci-002, ?aiset temperature 0.7, ?aiset top_p 1.0, ?aiset frequency_penalty 0.0, ?aiset presence_penalty 0.0 {GREY}>>>") + return + if prop in PROPERTIES: + if prop == "model": + try: + if val in MODELS: + self.default_model=val + if str(val)==MODELS[0]: + self.max_tokens = 2000 + else: + self.max_tokens = 1000 + else: + self.bot.privmsg(target, f"{GREY}<<< {DRED}error{GREY}: {LRED}property model value should be a string {GREY}- {DRED}choice of models{GREY}: {LRED}{MODELS} {GREY}- {DRED}example{GREY}: {LRED}?aiset model text-davinci-002 {GREY}>>>") + except: + self.bot.privmsg(target, f"{GREY}<<< {DRED}error{GREY}: {LRED}property model value should be a string {GREY}- {DRED}choice of models{GREY}: {LRED}{MODELS} {GREY}- {DRED}example{GREY}: {LRED}?aiset model text-davinci-002 {GREY}>>>") + return + elif prop == "temperature": + try: + if float(val) <= 2 and float(val) >= 0: + self.temperature=float(val) + except: + self.bot.privmsg(target, f"{GREY}<<< {DRED}error{GREY}: {LRED}property temperature value should be a float {GREY}- {DRED}example{GREY}: {LRED}?aiset temperature 0.7 {GREY}>>>") + return + elif prop == "max_tokens": + try: + if int(val) <= 2000 and int(val) >= 100: + self.max_tokens=int(val) + except: + self.bot.privmsg(target, f"{GREY}<<< {DRED}error{GREY}: {LRED}property max_tokens value should be an integer not greater than 2000 {GREY}- {DRED}example{GREY}: {LRED}?aiset max_tokens 2000 {GREY}>>>") + return + elif prop == "top_p": + try: + if float(val) <= 1.0 and float(val) >= 0.0: + self.top_p=float(val) + else: + self.bot.privmsg(target, f"{GREY}<<< {DRED}error{GREY}: property model should be a float no greater than 1.0 {GREY}- {DRED}example{GREY}: {LRED}?aiset top_p 0.7 {GREY}>>>") + return + except: + self.bot.privmsg(target, f"{GREY}<<< {DRED}error{GREY}: property model should be a float no greater than 1.0 {GREY}- {DRED}example{GREY}: {LRED}?aiset top_p 0.7 {GREY}>>>") + return + elif prop == "frequency_penalty": + try: + if float(val): + self.frequency_penalty=float(val) + except: + self.bot.privmsg(target, f"{GREY}<<< {DRED}error{GREY}: {LRED}property frequency_penalty should be a float {GREY}- {DRED}example{GREY}: {LRED}?aiset frequency_penalty 0.0 {GREY}>>>") + return + elif prop == "presence_penalty": + try: + if float(val) <= 2.0 and float(val) >= 0.0: + self.presence_penalty=float(val) + else: + self.bot.privmsg(target, f"{GREY}<<< {DRED}error{GREY}: {LRED}property presence_penalty should be a float no greater than 2.0 {GREY}- {DRED}example{GREY}: {LRED}?aiset presence_penalty 0.0 {GREY}>>>") + return + except: + self.bot.privmsg(target, f"{GREY}<<< {DRED}error{GREY}: {LRED}property presence_penalty should be a float no greater than 2.0 {GREY}- {DRED}example{GREY}: {LRED}?aiset presence_penalty 0.0 {GREY}>>>") + return + else: + self.bot.privmsg(target, f"{GREY}<<< {DRED}error{GREY}: {LRED}no properties were set, they remain the same {GREY}>>>") + self.print_response_properties(target) + return + else: + self.bot.privmsg(target, f"{GREY}<<< {DRED}error{GREY}: {LRED}used an invalid property identifier {GREY}- {DRED}property identifiers are {LRED}{PROPERTIES} {GREY}>>>") + self.bot.privmsg(target, f"{GREY}<<< {DRED}error{GREY}: {LRED}no properties were set, they remain the same {GREY}>>>") + self.print_response_properties(target) + return + self.bot.privmsg(target, f"{GREY}<<< {DRED}{prop} property set to the value {val} {GREY}>>>") + self.print_response_properties(target) + ####################################################################################### + @command(permission='view') + def aiclear(self, mask, target, args): + """OpenAi Clear Term + %%aiclear + """ + FILE='%s/../personalities/trained.db' % dir_path + f=open(FILE, "w") + f.write("") + f.close() + self.start_chat_log = "" + self.bot.privmsg(target, f"{GREY}<<< {DRED}cleared {GREY}>>>") + ####################################################################################### +########################################################################################### +########################################################################################### diff --git a/plugins/tcpac_plugin.py b/plugins/tcpac_plugin.py new file mode 100644 index 0000000..25e4ba3 --- /dev/null +++ b/plugins/tcpac_plugin.py @@ -0,0 +1,28 @@ +# -*- coding: utf-8 -*- +from irc3.plugins.command import command +from irc3.plugins.cron import cron +import irc3 +import socket + +@irc3.plugin +class Plugin: + + def __init__(self, bot): + self.bot = bot + + @command(permission='view') + def tcpac(self, mask, target, args): + """tcpac + %%tcpac ... + """ + msg=' '.join(args['']) + with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: + s.connect(("tcp.ac", 9999)) + s.sendall(bytes(msg.encode())) + data = s.recv(1024) + response=f'{data!r}' + response=response.replace('\\n',' - ').replace("b'","")[:-1] + msg=f"{mask.nick}: {response.split()[0]}" + self.bot.privmsg(target,msg) + msg=f"{response}" + self.bot.privmsg(mask.nick,msg) diff --git a/requirements.txt b/requirements.txt index e077722..39b535b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -18,3 +18,4 @@ googletrans==2.4.0 textblob==0.15.3 matplotlib==3.1.1 pyfiglet +openai