-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFinetuned.py
106 lines (97 loc) · 3.53 KB
/
Finetuned.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 langchain.prompts import PromptTemplate
from langchain.prompts.few_shot import FewShotPromptTemplate
from langchain.prompts.example_selector import SemanticSimilarityExampleSelector
from langchain.vectorstores import Chroma
from langchain.embeddings import OpenAIEmbeddings
#Few Shot Prompts
# The few shot prompts will guide the algorithm to craft a catchy political headline.
headline_examples = [
{
"question": "Can you write me a political headline?",
"answer":
"""
topic: Politics Unveiled: A Closer Look at the Game of Power and Influence
"""
},
{
"question": "Can you write me a political headline?",
"answer":
"""
topic: Political Turmoil: Challenges and Controversies Shape the World of Politics
"""
},
{
"question": "Can you write me a political headline?",
"answer":
"""
topic: Political Landscape Shifts as New Policies and Candidates Emerge
"""
},
{
"question": "Can you write me a political headline?",
"answer":
"""
topic: Politics: Shaping Society and Nation Through Governance and Policy-Making
"""
},
{
"question": "Can you write me a political headline?",
"answer":
"""
topic: Breaking News: Political Turmoil Shakes the Nation
"""
},
{
"question": "Can you write me a political headline?",
"answer":
"""
topic: Political Turmoil Grips Nation as Controversial Policies Divide Citizen
"""
},
{
"question": "Can you write me a political headline?",
"answer":
"""
topic: Political Landscape Shifts as New Policies Take Center Stage
"""
},
]
example_selector = SemanticSimilarityExampleSelector.from_examples(
# This is the list of examples available to select from.
headline_examples,
# This is the embedding class used to produce embeddings which are used to measure semantic similarity.
OpenAIEmbeddings(),
# This is the VectorStore class that is used to store the embeddings and do a similarity search over.
Chroma,
# This is the number of examples to produce.
k=1
)
#Prompt Templates
#The prompt templates will determine the app's output.
#Prompt Templates for Enhanced Outputs
headline_template = PromptTemplate(
input_variables = ["question","answer"],
template = 'question: {question} \n {answer}'
)
headline_prompt = FewShotPromptTemplate(
example_selector=example_selector,
example_prompt=headline_template,
suffix="Prompt: {topic}",
input_variables=["topic"]
)
press_template = PromptTemplate(
input_variables = ["headline", "wikipedia_research","google"],
template = 'I want you to act as a politician. You will research and analyze cultural, economic, political, and social events in the past, collect data from primary sources and use it to develop a press release about what happened during various periods of history. My first suggestion request is: write me a press release based on this headline: {headline} while leveraging this wikipedia research: {wikipedia_research} and google research: {google}'
)
twitter_template = PromptTemplate(
input_variables = ["press_release"],
template = 'write me a twitter post based on this press release written by a politician: {press_release}'
)
facebook_template = PromptTemplate(
input_variables = ["twitter"],
template = 'write me a facebook post based on this twitter post tweeted by a politician: {twitter}. Do not use emojis excessively.'
)
instagram_template = PromptTemplate(
input_variables = ["facebook"],
template = 'write me an instagram post based on this facebook post written by a politician: {facebook}. Do not use emojis excessively.'
)