SoDa12321 commited on
Commit
d0239f7
·
verified ·
1 Parent(s): 8860641

Create functions.py

Browse files
Files changed (1) hide show
  1. functions.py +193 -0
functions.py ADDED
@@ -0,0 +1,193 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from exa_py import Exa
2
+ from groq import Groq
3
+ import os
4
+
5
+ # Declare the exa search API
6
+ exa = Exa(api_key=os.getenv("EXA_API_KEY"))
7
+
8
+ # Define your API Model and key
9
+ client = Groq(api_key=os.getenv("GROQ_API_KEY"))
10
+ utilized_model = "llama3-70b-8192"
11
+
12
+ # Options for highlights from Exa search
13
+ highlights_options = {
14
+ "num_sentences": 7, # Length of highlights
15
+ "highlights_per_url": 1, # Get the best highlight for each URL
16
+ }
17
+
18
+ def call_llm(prompt):
19
+ """
20
+ Call the Exa and Groq APIs to generate content using the provided prompt.
21
+ """
22
+ # Perform search with Exa
23
+ search_response = exa.search_and_contents(query=prompt, highlights=highlights_options, num_results=3, use_autoprompt=True)
24
+ info = [sr.highlights[0] for sr in search_response.results]
25
+
26
+ # System prompt for Groq LLM
27
+ system_prompt = "You are an academic PhD proposal generator. Read the provided contexts and generate a well-structured research proposal based on them."
28
+ user_prompt = f"Sources: {info}\nResearch Prompt: {prompt}"
29
+
30
+ # Call the Groq model
31
+ completion = client.chat.completions.create(
32
+ model=utilized_model,
33
+ messages=[
34
+ {"role": "system", "content": system_prompt},
35
+ {"role": "user", "content": user_prompt},
36
+ ]
37
+ )
38
+
39
+ # Return the generated content
40
+ return completion.choices[0].message.content
41
+
42
+
43
+ # Functions to generate different sections of the research proposal
44
+
45
+ def generate_executive_summary(data):
46
+ """
47
+ Generate an executive summary based on the user's input data.
48
+ """
49
+ prompt = f"""
50
+ Generate a concise executive summary for a PhD research proposal with the following details:
51
+
52
+ Research Topic: {data.get("research_topic")}
53
+ Research Question: {data.get("research_question")}
54
+ Objectives: {data.get("objectives")}
55
+ Methodology: {data.get("methodology")}
56
+ Contribution: {data.get("contribution")}
57
+ Literature Gap: {data.get("literature_gap")}
58
+ """
59
+ return call_llm(prompt)
60
+
61
+
62
+ def generate_literature_review_outline(data):
63
+ """
64
+ Generate a literature review outline based on the user's input data.
65
+ """
66
+ prompt = f"""
67
+ Generate a structured outline for the literature review of a PhD thesis on the following topic:
68
+
69
+ Research Topic: {data.get("research_topic")}
70
+ Key Authors: {data.get("key_authors")}
71
+ Recent Developments: {data.get("recent_developments")}
72
+ Gaps in Literature: {data.get("literature_gap")}
73
+ """
74
+ return call_llm(prompt)
75
+
76
+
77
+ def generate_methodology_section(data):
78
+ """
79
+ Generate a methodology section for a PhD proposal.
80
+ """
81
+ prompt = f"""
82
+ Write a detailed research methodology section for a PhD proposal based on the following:
83
+
84
+ Research Topic: {data.get("research_topic")}
85
+ Data Collection Methods: {data.get("data_collection")}
86
+ Data Analysis Methods: {data.get("data_analysis")}
87
+ Justification: {data.get("justification")}
88
+ """
89
+ return call_llm(prompt)
90
+
91
+
92
+ def generate_research_objectives(data):
93
+ """
94
+ Generate research objectives using the SMART framework.
95
+ """
96
+ prompt = f"""
97
+ Generate a detailed list of short-term and long-term research objectives for the following PhD thesis topic:
98
+
99
+ Research Topic: {data.get("research_topic")}
100
+ Objectives: {data.get("objectives")}
101
+
102
+ The objectives should follow the SMART criteria (Specific, Measurable, Achievable, Relevant, Time-bound).
103
+ """
104
+ return call_llm(prompt)
105
+
106
+
107
+ def generate_hypotheses(data):
108
+ """
109
+ Generate hypotheses for the research.
110
+ """
111
+ prompt = f"""
112
+ Generate research hypotheses based on the following topic:
113
+
114
+ Research Topic: {data.get("research_topic")}
115
+ Research Question: {data.get("research_question")}
116
+ """
117
+ return call_llm(prompt)
118
+
119
+
120
+ def generate_contribution_statement(data):
121
+ """
122
+ Generate a contribution statement for a PhD proposal.
123
+ """
124
+ prompt = f"""
125
+ Generate a statement of contribution for the following PhD research proposal:
126
+
127
+ Research Topic: {data.get("research_topic")}
128
+ Contribution to the Field: {data.get("contribution")}
129
+
130
+ The statement should highlight how the research will address existing gaps and advance knowledge in the field.
131
+ """
132
+ return call_llm(prompt)
133
+
134
+
135
+ def generate_research_timeline(data):
136
+ """
137
+ Generate a detailed research timeline for a PhD thesis.
138
+ """
139
+ prompt = f"""
140
+ Generate a detailed research timeline for completing a PhD thesis on the following topic:
141
+
142
+ Research Topic: {data.get("research_topic")}
143
+ Total Timeframe: {data.get("total_timeframe")}
144
+
145
+ The timeline should break down tasks into manageable phases (e.g., literature review, data collection, analysis) with deadlines.
146
+ """
147
+ return call_llm(prompt)
148
+
149
+
150
+ def generate_proposal_introduction(data):
151
+ """
152
+ Generate a proposal introduction based on the user's input data.
153
+ """
154
+ prompt = f"""
155
+ Write an engaging introduction for a PhD proposal on the following research topic:
156
+
157
+ Research Topic: {data.get("research_topic")}
158
+ Research Problem: {data.get("research_problem")}
159
+
160
+ The introduction should provide background, introduce the problem, and explain the significance of the research.
161
+ """
162
+ return call_llm(prompt)
163
+
164
+
165
+ def generate_limitations_section(data):
166
+ """
167
+ Generate a section on research limitations.
168
+ """
169
+ prompt = f"""
170
+ Generate a section describing the potential limitations and challenges of the following research:
171
+
172
+ Research Topic: {data.get("research_topic")}
173
+ Methodology: {data.get("methodology")}
174
+
175
+ The limitations should address possible obstacles and suggest ways to mitigate them.
176
+ """
177
+ return call_llm(prompt)
178
+
179
+
180
+ def generate_future_work_section(data):
181
+ """
182
+ Generate a future work section for a research proposal.
183
+ """
184
+ prompt = f"""
185
+ Generate a section on future work based on the following research:
186
+
187
+ Research Topic: {data.get("research_topic")}
188
+ Contribution: {data.get("contribution")}
189
+
190
+ The future work section should suggest further areas for research that could build upon the findings.
191
+ """
192
+ return call_llm(prompt)
193
+