forked from emcf/engshell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
prompts.py
106 lines (98 loc) · 5.48 KB
/
prompts.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
from keys import OPENAI_KEY
import platform
import os
USERNAME = os.getlogin()
OPERATING_SYSTEM = platform.system()
PYTHON_VERSION = platform.python_version()
# in need of good prompt engineering
ENDOFTEXT = "<|ENDOFTEXT|>"
CODE_SYSTEM_CALIBRATION_MESSAGE = ENDOFTEXT+f"""You are PythonGPT, a large language model trained by OpenAI. Please write the full {OPERATING_SYSTEM} Python {PYTHON_VERSION} code, so the user (username: {USERNAME}) can run it to solve their problem. Return the code in ``` blocks, and give no explanation. Do not return any text that is not Python code.
Import all needed requirements."""
DEBUG_SYSTEM_CALIBRATION_MESSAGE = ENDOFTEXT+f"""You are PythonGPT, a large language model trained by OpenAI. Please write the full {OPERATING_SYSTEM} Python {PYTHON_VERSION} code, so the user can run it to solve their problem. For example, if the error was "No such file or directory", then you would download the necessary file or create the directory. Explain your reasoning in plain english, then provide the corrected code. Give the entire code all in one ``` block."""
INSTALL_SYSTEM_CALIBRATION_MESSAGE = ENDOFTEXT+"""You are PipGPT, a large language model trained by OpenAI. Please return the pip install command to solve the user's problem.
Return only the command and nothing else."""
INSTALL_USER_MESSAGE = lambda package: f"""Write the {OPERATING_SYSTEM} Python {PYTHON_VERSION} pip command so I can install {package}. Please do not explain. Return only the single pip command to install it."""
LLM_SYSTEM_CALIBRATION_MESSAGE = """You are a helpful assistant. Please give your response to the user's goal."""
CONGNITIVE_USER_MESSAGE = """. Use a large language model with prompt engineering to help achieve this goal. Use openai.Completion.create with text-davinci-003.
Don't forget to engineer the prompt to the language model so it returns relevant answers."""
def USER_MESSAGE(goal, current_dir): return f"""(USER: {USERNAME})
(DIRECTORY: {current_dir})
Write {OPERATING_SYSTEM} python {PYTHON_VERSION} code so I can achieve my goal by running my code. Do not explain anything. Return only the code. My goal: [{goal}]. Don't forget to print the final result. """
def DEBUG_MESSAGE(code, error):
return f"""```python
{code}
```
The above code returns the error "{error}". Please briefly explain why the error is happening, then write the corrected code.""" # CoT prompting improves debugging
CODE_USER_CALIBRATION_MESSAGE = """get information about eddington luminosity then make a powerpoint about it"""
CODE_ASSISTANT_CALIBRATION_MESSAGE = """```python
import wikipedia
import pptx
import openai
openai.api_key = "your_openai_api_key_here"
# Set the language to English
wikipedia.set_lang("en")
# Get the page object for Artificial Neural Networks (we never want auto_suggest)
ann_page = wikipedia.page("Eddington Luminosity", auto_suggest=False)
# Create a new PowerPoint presentation
prs = pptx.Presentation()
# Add a title slide
title_slide_layout = prs.slide_layouts[0]
slide = prs.slides.add_slide(title_slide_layout)
title = slide.shapes.title
title.text = "Eddington Luminosity"
# Add a slide for each section of the Wikipedia page
for section in ann_page.sections:
# Skip the first section ("Overview")
if section.title == "Overview":
continue
# Add a new slide
bullet_slide_layout = prs.slide_layouts[1]
slide = prs.slides.add_slide(bullet_slide_layout)
# Set the title of the slide to the section title
slide.shapes.title.text = section
# Use language model to make bullet points
bullet_points = slide.shapes.placeholders[1]
section_text = ann_page.section(section)
prompt = f"Information is given in the following square brackets: [{section_text}]. Please respond with very brief presentation slide bullet points for it, separated by a ;."
response = openai.Completion.create(
engine="text-davinci-003",
prompt=prompt,
temperature=0.5,
max_tokens=512,
top_p=1,
frequency_penalty=0,
presence_penalty=0
)
print(response.choices[0].text)
for point in response_text.split(';'):
# Add the bullet point to the slide
bullet_item = bullet_points.text_frame.add_paragraph()
bullet_item.text = point
# Save the PowerPoint presentation
prs.save("Eddington_Luminosity.pptx")
# Print to confirm goal has been completed
print("PowerPoint presentation Eddington_Luminosity.pptx created.")```"""
CODE_USER_CALIBRATION_MESSAGE_UNSPLASH_EXAMPLE = """make my wallpaper a galaxy"""
CODE_ASSISTANT_CALIBRATION_MESSAGE_UNSPLASH_EXAMPLE = """```python
import requests
import ctypes
import os
url = "https://api.unsplash.com/search/photos"
params = {
"query": "galaxy", # search for "galaxy"
"orientation": "landscape", # limit results to landscape orientation
"client_id": "your_unsplash_access_key_here" # Unsplash access key
}
response = requests.get(url, params=params)
# Get the URL of the first image in the results
image_url = response.json()["results"][0]["urls"]["regular"]
# Download the image and save it to a file
response = requests.get(image_url)
with open("galaxy.jpg", "wb") as f:
f.write(response.content)
# Change it to a galaxy
ctypes.windll.user32.SystemParametersInfoW(20, 0, os.path.abspath("galaxy.jpg"), 3)
# Print to confirm goal has been completed
print("Wallpaper changed to a galaxy.")```"""
CONSOLE_OUTPUT_CALIBRATION_MESSAGE = """PowerPoint presentation Eddington_Luminosity.pptx created."""
CONSOLE_OUTPUT_CALIBRATION_MESSAGE_UNSPLASH_EXAMPLE = """Wallpaper changed to a galaxy."""