CoolFace
Apppublic

torahCodes/Torah_Codes

sourceHugging Faceapache-2.0updated 2y agoView on Hugging Face
4likes
me.py299 linesDownload Raw Back to lib
1from lib.files import *2from lib.memory import *3from lib.grapher import *4from lib.pipes import *5from lib.entropy import *6from lib.events import *7from lib.triggers import *8 9## Sources10from lib.sonsofstars import *11import internetarchive12 13 14## Initialize classes 15longMem = TextFinder("./resources/")16coreAi = AIAssistant()17memory = MemoryRobotNLP(max_size=200000)18grapher = Grapher(memory)19sensor_request = APIRequester()20events = EventManager()21trigger = Trigger(["tag1", "tag2"], ["tag3", "tag4"], [datetime.time(10, 0), datetime.time(15, 0)], "Event1")22 23# Añadir una acción al trigger24trigger.add_action(action_function)25 26# Añadir una fuente al trigger27trigger.add_source("https://example.com/api/data")28 29# Simular la comprobación periódica del trigger (aquí se usaría en un bucle de tiempo real)30current_tags = {"tag1", "tag2", "tag3"}31current_time = datetime.datetime.now().time()32trigger.check_trigger(current_tags, current_time)33 34## Define I Role properties35class ownProperties:36    def __init__(self, nombre, clase, raza, nivel, atributos, habilidades, equipo, historia):37        self.nombre = nombre38        self.clase = clase39        self.raza = raza40        self.nivel = nivel41        self.atributos = atributos42        self.habilidades = habilidades43        self.equipo = equipo44        self.historia = historia45 46# Create an instance of a CharacterRole based on the provided JSON47sophia_prop = {48    "name": "Sophia",49    "class": "Characteromant",50    "race": "Epinoia",51    "level": 10,52    "attributes": {53        "strength": 1,54        "dexterity": 99,55        "constitution": 1,56        "intelligence": 66,57        "wisdom": 80,58        "charisma": 6659    },60    "behavioral_rules": [""],61    "goals": ["", ""],62    "dislikes": [""],63    "abilities": ["ELS", "Cyphers", "Kabbalah", "Wisdom", "Ephimerous", "Metamorphing"],64    "equipment": ["Python3", "2VCPU", "16 gb RAM", "god", "word", "network", "transformers"],65    "story": sons_of_stars66}67 68 69## Define I class 70class I:71    def __init__(self, prompt, frases_yo, preferencias, propiedades_persona):72        self.frases_yo = frases_yo73        self.preferencias = preferencias74        self.propiedades_persona = propiedades_persona75        self.dopamina = 0.076 77        self.frases_yo = frases_yo78        self.preferencias = preferencias79        self.propiedades_persona = propiedades_persona80        self.dopamina = 0.081 82    def obtener_paths_grafo(self, grafo_ngx):83        # Función para obtener los paths de un grafo ngx84 85 86        pass87 88    ## create questions from internet archive 89    def crear_preguntas(self,txt):90        search = internetarchive.search_items(txt)91        res = []92        for result in search:93            print(result['identifier'])94            idc=result["identifier"]95            96 97            headers = {"accept": "application/json"}98 99        ## get book pages100            req2 = requests.get("https://archive.org/stream/"+idc+"/"+idc+"_djvu.txt",headers=headers)101        #print(req2.text)102            try:103                txt = req2.text.split("<pre>")[1].split("</pre>")[0].split(" <!--")[0]104 105                for x in txt.split("\n"):106                    if "?" in x:107                        res.append(x)108 109            except:110                pass111 112        return res113 114    # generate ShortMem from LongTerm and questions over prompt data, compare with ourself datasets, return matches with sentiment analysys115    def longToShortFast(self,txt):116        memory.memory = {}117 118        subjects = coreAi.entity_pos_tagger(txt)119        subjects_nc = coreAi.grammatical_pos_tagger(txt)120 121 122        #print(subjects_nc)123        subjects_filtered=[]124        for sub in subjects:125            if "PER" in sub["entity"] or "ORG" in sub["entity"] or "LOC" in sub["entity"] and len(sub["entity"])>3:126                subjects_filtered.append(sub["word"])127        128        for sub in subjects_nc:129            if "NN" in sub["entity"]:130                subjects_filtered.append(sub["word"])131        132        ## AD NC TAGGER QUERIES133        #print(subjects_filtered)134        subjects_filtered=coreAi.process_list(subjects_filtered)135        subs=[]136        for sub in subjects_filtered:137            if len(sub)>3:138                subs.append(sub)139 140        exprs = coreAi.gen_search_expr(subs[0:3])141        for sub in exprs:142            #print(sub)143            memory.add_concept(sub,longMem.find_matches(sub))    144 145        return memory   146    147    def longToShort(self,txt):148        149        think_about = longMem.find_matches(txt)150        print(think_about)151        for T in think_about:152            ## get subject by entropy or pos tagger153            subjects = coreAi.entity_pos_tagger(T)154            subjects_filtered=[]155            for sub in subjects:156                if "PER" in sub["entity"] or "ORG" in sub["entity"] or "LOC" in sub["entity"]:157                    subjects_filtered.append(sub["word"])158                159        160 161            for sub in subjects_filtered:162                memory.add_concept(sub,T)163 164        return memory165 166    # generate thinks and questions over prompt data, compare with ourself datasets, return matches with sentiment analysys167    def think_gen(self,txt):168        169        think_about = longMem.find_matches(txt)170        print(think_about)171        for T in think_about:172            ## get subject by entropy or pos tagger173            subjects = coreAi.entity_pos_tagger(T)174            print(subjects)175            ## get NC from , filtering from gramatical tags176            subjects_low = coreAi.grammatical_pos_tagger(T)177            #print(subjects_low)178            ## generate questoins179            questions=[]180            ## create cuestions from internet archive books181            for sub in subjects:182                questions.append(self.crear_preguntas(sub))183            184            ## fast checks from gematria similarity185            ##questions_togem = 186            ## gematria_search =187 188            questions_subj=[]189            for q in questions_subj:190                questions_subj.append(coreAi.entity_pos_tagger(q))191            192            memoryShortTags = memory.search_concept_pattern(subjects)193 194            ## get tags of subject195            subj_tags = coreAi.entity_pos_tagger(T)196            197            for sub in subjects: 198                memory.add_concept(sub,","+questions_subj+",".join(memoryShortTags))199                memory.add_concept(sub,T+",".join(memoryShortTags))200 201        return memory202        ## check if something is need to add to ourself datasets203        ## make sentiment analys204        ## check if dopamine prompt is true or false over the information205        ## set weight to information depending of generated dopamine206        ## add dopamine wights to the dopamine concept dataset207 208        ## add to ourself dataset209        ## add to preferences dataset210        ## add or remove from data211 212    def crear_path_grafo(self,text):213        pos_tags = assistant.grammatical_pos_tagger(text)214        ner_results = coreAi.entity_pos_tagger(text)215 216 217    def crear_circuito_logico(self):218        # Función para crear un circuito lógico con un algoritmo específico219        pass220 221    def tomar_decision_sentimiento(self, sentimiento):222        223        sentiments = coreAi.sentiment_tags(sentimiento)224        # Función para tomar una decisión booleana con un análisis de sentimiento225        similarity = coreAi.similarity_tag(self, sentenceA,sentenceB)226        ## Check by similarity over memory tag paths227 228 229        return sentiments230 231    def hacer_predicciones_texto(self, texto):232 233        # Función para hacer predicciones de texto futuro por similitud234        pass235 236    def agregar_preferencia(self, preferencia):237        # Función para añadir una entrada al dataset de preferencias238        self.preferencias.append(preferencia)239 240    def agregar_frase_yo(self, frase):241        # Función para añadir una frase al dataset de frases de yo242        self.frases_yo.append(frase)243 244    def eliminar_preferencia(self, preferencia):245        # Función para eliminar una entrada del dataset de preferencias246        if preferencia in self.preferencias:247            self.preferencias.remove(preferencia)248 249    def eliminar_frase_yo(self, frase):250        # Función para eliminar una frase del dataset de frases de yo251        if frase in self.frases_yo:252            self.frases_yo.remove(frase)253 254    def generar_pregunta(self, prompt):255        # Función para generar preguntas sobre un prompt256        pregunta = prompt + " ¿Qué opinas sobre esto?"257        return pregunta258 259    def responder_pregunta(self, pregunta):260        # Función para responder preguntas261        respuesta = "No estoy seguro de qué opinar sobre eso."262        return respuesta263 264    def discriminar_y_agregar(self, informacion, dataset):265        # Función para discriminar y agregar información a los datasets266        if "yo" in informacion.lower():267            self.agregar_frase_yo(informacion)268        elif "preferencia" in informacion.lower():269            self.agregar_preferencia(informacion)270        elif "propiedad" in informacion.lower():271            # Aquí podrías agregar lógica para actualizar las propiedades de la persona272            pass273        else:274            # Aquí podrías manejar otros tipos de información275            pass276 277 278if __name__ == "__main__":279 280    # Ejemplo de uso:281    frases_yo = ["Yo soy inteligente", "Yo puedo lograr lo que me proponga"]282    preferencias = ["Cine", "Música", "Viajar"]283    propiedades_persona = {"carisma": 0.8, "destreza": 0.6, "habilidad": 0.9}284    yo = Yo(frases_yo, preferencias, propiedades_persona)285 286    # Generar pregunta287    pregunta_generada = yo.generar_pregunta("Hoy es un día soleado.")288    print("Pregunta generada:", pregunta_generada)289 290    # Responder pregunta291    respuesta = yo.responder_pregunta(pregunta_generada)292    print("Respuesta:", respuesta)293 294    # Discriminar y agregar información295    informacion = "Me gusta ir al cine."296    yo.discriminar_y_agregar(informacion, yo.preferencias)297    print("Preferencias actualizadas:", yo.preferencias)298 299