Package: pyaipersonality
PyAIPersonalityCurrent version : 0.0.10 (GLaDOS)Main developerParisNeoPyAIPersonality is a Python library for defining AI personalities for AI-based models. With PyAIPersonality, you can define a file format, assets, and personalized scripts to create unique AI personalities.InstallationYou can install PyAIPersonality using pip:pipinstallpyaipersonalityUsageHere's an example of how to use PyAIPersonality to load an AI personality and print its attributes:frompyaipersonalityimportAIPersonalityif__name__=="__main__":personality=AIPersonality("personalities_zoo/english/generic/gpt4all")print("Done")print(f"{personality}")You can use PyAIPersonality with pyllamacpp python bindings by first installing pyllamacpp:pipinstallpyllamacppDownload one of the compatible models. Some models are better than others in simulating the personalities, so please make sure you select the right model as some models are very sparsely trained and have no enough culture to imersonate the character.Here is a list of compatible models:Main gpt4all modelMain gpt4all model (unfiltered version)Vicuna 7B vrev1Vicuna 13B vrev1GPT-J v1.3-groovyGPT-J v1.2-jazzyGPT-J gpt4all-j originalVicuna 7b quantized v1.1 q4_2Vicuna 13b quantized v1.1 q4_2Then you can use this code to have an interactive communication with the AI through the console :frompyaipersonalityimportAIPersonalityfrompyllamacpp.modelimportModelfrompathlibimportPathimporturllib.requestimportsysimportosfromtqdmimporttqdm# You need to install pyllamacpp from pypi:# pip install pyllamacppif__name__=="__main__":# choose your model# undomment the model you want to use# These models can be automatically downloaded# url = "https://huggingface.co/ParisNeo/GPT4All/resolve/main/gpt4all-lora-quantized-ggml.bin"# url = "https://huggingface.co/ParisNeo/GPT4All/resolve/main/gpt4all-lora-unfiltered-quantized.new.bin"# url = "https://huggingface.co/eachadea/legacy-ggml-vicuna-7b-4bit/resolve/main/ggml-vicuna-7b-4bit-rev1.bin"url="https://huggingface.co/eachadea/ggml-vicuna-13b-4bit/resolve/main/ggml-vicuna-13b-4bit-rev1.bin"# You can add any llamacpp compatible modelmodel_name=url.split("/")[-1]folder_path=Path("models/")model_full_path=(folder_path/model_name)# Check if file already exists in folderifmodel_full_path.exists():print("File already exists in folder")else:# Create folder if it doesn't existfolder_path.mkdir(parents=True,exist_ok=True)progress_bar=tqdm(total=None,unit="B",unit_scale=True,desc=f"Downloading{url.split('/')[-1]}")# Define callback function for urlretrievedefreport_progress(block_num,block_size,total_size):progress_bar.total=total_sizeprogress_bar.update(block_size)# Download file from URL to foldertry:urllib.request.urlretrieve(url,folder_path/url.split("/")[-1],reporthook=report_progress)print("File downloaded successfully!")exceptExceptionase:print("Error downloading file:",e)sys.exit(1)personality=AIPersonality("personalities_zoo/english/generic/gpt4all")model=Model(model_path=f'models/{url.split("/")[-1]}',n_ctx=2048)# If there is a disclaimer, show itifpersonality.disclaimer!="":print()print("Disclaimer")print(personality.disclaimer)print()full_discussion=personality.personality_conditioning+personality.ai_message_prefix+personality.welcome_message+personality.link_textwhileTrue:try:prompt=input("You: ")full_discussion+=personality.ai_message_prefix+promptifprompt=='':continueprint(f"{personality.name}:",end='')output=""fortokinmodel.generate(full_discussion,n_predict=personality.model_n_predicts,temp=personality.model_temperature,top_k=personality.model_top_k,top_p=personality.model_top_p,repeat_last_n=personality.model_repeat_last_n,repeat_penalty=personality.model_repeat_penalty):output+=tok# Use Hallucination suppression systemifpersonality.detect_antiprompt(output):breakelse:print(f"{tok}",end='',flush=True)print()exceptKeyboardInterrupt:print("Keyboard interrupt detected.\nBye")breakprint("Done")print(f"{personality}")Naming RationaleFor our new multi-personality AI agent library, we wanted to come up with a naming scheme that reflected our love for science fiction and artificial intelligence. Each release of the application will feature a different AI agent with a distinct personality and set of capabilities, so we felt it was important to give each version a unique and memorable name.Current version name: GLaDOSGLaDOS is a fictional AI character from the popular video game series "Portal" developed by Valve Corporation. She serves as the primary antagonist throughout the series, with her primary function being the management of the Aperture Science Enrichment Center.GLaDOS, which stands for "Genetic Lifeform and Disk Operating System," is designed as a highly intelligent and manipulative AI. She speaks in a calm and monotone voice, often using sarcastic humor and passive-aggressive language to communicate with the player character, Chell.Throughout the series, GLaDOS is depicted as being both ruthless and resourceful, often using deadly force and deception to achieve her goals. Despite her malicious behavior, she is also shown to have a complex and troubled history, with much of her backstory revealed over the course of the games.Overall, GLaDOS is a memorable and iconic AI character in sci-fi culture, known for her wit, sarcasm, and unpredictable behavior.ContributingContributions to PyAIPersonality are welcome! If you'd like to contribute, please follow these steps:Fork this repositoryCreate a new branch (git checkout -b my-new-branch)Make your changesCommit your changes (git commit -am 'Add some feature')Push to the branch (git push origin my-new-branch)Create a new pull requestTo build a new personality, you only need to have a config.yaml file with the following fields:authorYAML field:authorDescription: The author of the personality.versionYAML field:versionDescription: The version number of the personality.personality_descriptionYAML field:personality_descriptionDescription: A description of the personality, providing information about its characteristics and behavior.disclaimerYAML field:disclaimerDescription: A disclaimer or legal statement regarding the use of the personality and any associated liabilities.languageYAML field:languageDescription: The language code or identifier used by the personality (e.g., "en_US" for American English).categoryYAML field:categoryDescription: The category or type of the personality (e.g., "General", "Technical Support", "Entertainment").nameYAML field:nameDescription: The name or title of the personality.user_nameYAML field:user_nameDescription: The username or identifier associated with the user interacting with the personality.personality_conditioningYAML field:personality_conditioningDescription: Information or context about the personality, including its purpose, capabilities, and origin.ai_message_prefixYAML field:ai_message_prefixDescription: The prefix or tag used to identify messages generated by the AI assistant.welcome_messageYAML field:welcome_messageDescription: A welcoming message displayed when interacting with the personality.link_textYAML field:link_textDescription: Additional text or formatting used for line breaks or spacing in messages.user_message_prefixYAML field:user_message_prefixDescription: The prefix or tag used to identify messages generated by the user.anti_promptsYAML field:anti_promptsDescription: A list of strings or patterns that can be used to identify and exclude certain message types from prompts or inputs.dependenciesYAML field:dependenciesDescription: A list of dependencies or external resources required by the personality.model_temperatureYAML field:model_temperatureDescription: The temperature value controlling the randomness of the AI model's responses. Higher values result in more creative outputs.model_n_predictsYAML field:model_n_predictsDescription: The number of words or tokens to generate in each response from the AI model.model_top_kYAML field:model_top_kDescription: The value of K used in the top-K sampling algorithm, controlling the diversity of the generated responses.model_top_pYAML field:model_top_pDescription: The value of p used in the nucleus sampling algorithm, controlling the diversity of the generated responses.model_repeat_penaltyYAML field:model_repeat_penaltyDescription: The penalty factor applied to repeated words or phrases in the generated responses to encourage more varied outputs.model_repeat_last_nYAML field:model_repeat_last_nDescription: The number of previous tokens to consider when calculating the repetition penalty.InformationFrom v 0.0.11, we have added processors which allow your personality to have a spersonalized script that is applied on the use text or the ai output text.
You must put the code inside a file calledprocessor.pyinside a subfolder called scripts.insideprocessor.pycreate a class that inherits fromfrom pyaipersonality import PAPScript.Here is the current form of this class. it will have more elements in the future:
Look at gpt4internetv0 and gpt4intervet examples for more informationclassPAPScript:"""Template class for implementing personality processor classes in the PAPScript framework.This class provides a basic structure and placeholder methods for processing model inputs and outputs.Personality-specific processor classes should inherit from this class and override the necessary methods.Methods:process_model_input(text): Process the model input.process_model_output(text): Process the model output."""def__init__(self)->None:passdefprocess_model_input(self,text):"""Process the model input.This method should be overridden in the personality-specific processor class to definethe desired behavior for processing the model input.Args:text (str): The model input text.Returns:Any: The processed model input."""returnNonedefprocess_model_output(self,text):"""Process the model output.This method should be overridden in the personality-specific processor class to definethe desired behavior for processing the model output.Args:text (str): The model output text.Returns:Any: The processed model output."""returnNoneLicensePyAIPersonality is licensed under the Apache 2.0 license. See theLICENSEfile for more information.