-
Notifications
You must be signed in to change notification settings - Fork 0
/
promptTesting.py
52 lines (40 loc) · 1.87 KB
/
promptTesting.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
import wikipedia
from openai import OpenAI
import os
def userSearchToTopPage (userSearch):
topArticle = wikipedia.search(userSearch, 1)
return topArticle[0]
def pageToText (concept):
wikiPage = wikipedia.WikipediaPage(title=concept)
return wikiPage.content
def createPrompt (pageContent):
prompt = ("summarize this wikipedia article delimited by quotes in extremely easy to read "
"and very simple language that highlights the intuition and main idea "
"of the concept as opposed to focusing on the specific details. "
"make this summary a very short 30 second read (max 100 words) and "
"broken into 2-3 paragraphs of 1-2 sentences where each paragraph "
"covers a different piece of the intuition. place that piece as a "
"bolded title before each paragraph. Make sure the paragraphs do not "
"repeat themselves. do not use words from the article in the summary, make the summary readable for a kindergartener. make it more simple: \n\n\n"
+ "\"" + pageContent + "\"")
return prompt
def promptToAIResponse (prompt):
client = OpenAI(api_key = os.getenv("my_api_key"))
response = client.chat.completions.create(
messages=[{"role": "assistant", "content": prompt,}],
model="gpt-3.5-turbo",
)
return response
def userSearchToAIResponse(userSearch):
topPage = userSearchToTopPage(userSearch)
pageText = pageToText(topPage)
prompt = createPrompt(pageText)
response = promptToAIResponse(prompt)
return response.choices[0].message.content
def userSearchToPageContent(userSearch):
topPage = userSearchToTopPage(userSearch)
pageText = pageToText(topPage)
prompt = createPrompt(pageText)
return prompt
# print(userSearchToAIResponse("strawberries"))
print(userSearchToPageContent("Immigration and Nationality Act of 1965"))