| from exa_py import Exa |
| from groq import Groq |
| import os |
|
|
| |
| exa = Exa(api_key=os.getenv("EXA_API_KEY")) |
|
|
| |
| client = Groq(api_key=os.getenv("GROQ_API_KEY")) |
| utilized_model = "llama3-70b-8192" |
|
|
| highlights_options = { |
| "num_sentences": 7, |
| "highlights_per_url": 1, |
| } |
|
|
| def call_llm(prompt): |
| search_response = exa.search_and_contents(query=prompt, highlights=highlights_options, num_results=3, use_autoprompt=True) |
| info = [sr.highlights[0] for sr in search_response.results] |
| |
| system_prompt = "You are an academic PhD proposal generator. Read the provided contexts and, if relevant, use them to generate a well-structured research proposal." |
| user_prompt = f"Sources: {info}\nResearch Prompt: {prompt}" |
| |
| completion = client.chat.completions.create( |
| model=utilized_model, |
| messages=[ |
| {"role": "system", "content": system_prompt}, |
| {"role": "user", "content": user_prompt}, |
| ] |
| ) |
| return completion.choices[0].message.content |
|
|
|
|
| import requests |
| from IPython.display import HTML |
|
|
| |
| def upload_files_to_transfer_sh(file_paths): |
| urls = [] |
| html_content = "<form>" |
| |
| |
| for file_path in file_paths: |
| with open(file_path, 'rb') as file: |
| response = requests.post('https://transfer.sh/', files={'file': file}) |
| response.raise_for_status() |
| urls.append(response.text) |
| html_content += f"<p>File: {file_path} <br> Upload URL: <a href='{response.text}'>{response.text}</a></p>" |
| |
| html_content += "</form>" |
| return urls, html_content |
| |
| def generate_executive_summary(data): |
| prompt = f""" |
| Generate a concise executive summary for a PhD research proposal based on the following information: |
| |
| Research Topic: {data["research_topic"]} |
| Research Question: {data["research_question"]} |
| Objectives: {data["objectives"]} |
| Methodology: {data["methodology"]} |
| Contribution to the Field: {data["contribution"]} |
| Literature Gap: {data["literature_gap"]} |
| |
| The summary should highlight the research problem, its significance, the approach, and expected contributions. |
| """ |
| return call_llm(prompt) |
|
|
| def generate_literature_review_outline(data): |
| prompt = f""" |
| Generate a structured outline for the literature review of a PhD thesis on the following topic: |
| |
| Research Topic: {data["research_topic"]} |
| Key Authors: {data["key_authors"]} |
| Recent Developments: {data["recent_developments"]} |
| Gaps in Literature: {data["literature_gap"]} |
| |
| The outline should cover key themes, debates, and the relevance of existing work to the proposed research. |
| """ |
| return call_llm(prompt) |
|
|
| def generate_methodology_section(data): |
| prompt = f""" |
| Write a detailed research methodology section for a PhD proposal based on the following: |
| |
| Research Topic: {data["research_topic"]} |
| Data Collection Methods: {data["data_collection"]} |
| Data Analysis Methods: {data["data_analysis"]} |
| Justification: {data["justification"]} |
| |
| The methodology should demonstrate how the research will be conducted reliably and validly. |
| """ |
| return call_llm(prompt) |
|
|
| def generate_research_objectives(data): |
| prompt = f""" |
| Generate a detailed list of short-term and long-term research objectives for the following PhD thesis topic: |
| |
| Research Topic: {data["research_topic"]} |
| Objectives: {data["objectives"]} |
| |
| The objectives should follow the SMART criteria (Specific, Measurable, Achievable, Relevant, and Time-bound). |
| """ |
| return call_llm(prompt) |
|
|
| def generate_hypotheses(data): |
| prompt = f""" |
| Generate research hypotheses based on the following topic: |
| |
| Research Topic: {data["research_topic"]} |
| Research Question: {data["research_question"]} |
| |
| The hypotheses should clearly predict expected outcomes based on theoretical foundations. |
| """ |
| return call_llm(prompt) |
|
|
| def generate_contribution_statement(data): |
| prompt = f""" |
| Generate a statement of contribution for the following PhD research proposal: |
| |
| Research Topic: {data["research_topic"]} |
| Contribution to the Field: {data["contribution"]} |
| |
| The statement should highlight how the research will address existing gaps and advance knowledge in the field. |
| """ |
| return call_llm(prompt) |
|
|
| def generate_research_timeline(data): |
| prompt = f""" |
| Generate a detailed research timeline for completing a PhD thesis on the following topic: |
| |
| Research Topic: {data["research_topic"]} |
| Total Timeframe: {data["total_timeframe"]} |
| |
| The timeline should break down tasks into manageable phases (e.g., literature review, data collection, analysis) with deadlines. |
| """ |
| return call_llm(prompt) |
|
|
| def generate_proposal_introduction(data): |
| prompt = f""" |
| Write an engaging introduction for a PhD proposal on the following research topic: |
| |
| Research Topic: {data["research_topic"]} |
| Research Problem: {data["research_problem"]} |
| |
| The introduction should provide background, introduce the problem, and explain the significance of the research. |
| """ |
| return call_llm(prompt) |
|
|
| def generate_limitations_section(data): |
| prompt = f""" |
| Generate a section describing the potential limitations and challenges of the following research: |
| |
| Research Topic: {data["research_topic"]} |
| Methodology: {data["methodology"]} |
| |
| The limitations should address possible obstacles and suggest ways to mitigate them. |
| """ |
| return call_llm(prompt) |
|
|
| def generate_future_work_section(data): |
| prompt = f""" |
| Generate a section on future work based on the following research: |
| |
| Research Topic: {data["research_topic"]} |
| Contribution: {data["contribution"]} |
| |
| The future work section should suggest further areas for research that could build upon the findings. |
| """ |
| return call_llm(prompt) |
| |