bano1 commited on
Commit
5fcb7fe
·
verified ·
1 Parent(s): 2becc17

Create ai_functions.py

Browse files
Files changed (1) hide show
  1. src/ai_functions.py +57 -0
src/ai_functions.py ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ def get_summary(text):
2
+ """Simple summary of abstract (concise)."""
3
+ if not text:
4
+ return "No abstract available."
5
+ prompt = f"""
6
+ You are an academic assistant. Summarize the abstract concisely in 3-5 sentences, focusing on contributions, methods and main findings. Use simple language suitable for a researcher.
7
+ Abstract:
8
+ {text}
9
+ """
10
+ response = client.chat.completions.create(
11
+ model="llama-3.1-8b-instant",
12
+ messages=[{"role": "user", "content": prompt}]
13
+ )
14
+ return response.choices[0].message.content.strip()
15
+
16
+ def chunk_text(text, max_chars=4000):
17
+ """Split text into smaller parts safely for Groq API."""
18
+ return [text[i:i + max_chars] for i in range(0, len(text), max_chars)]
19
+
20
+ def get_section_summaries(text):
21
+ summaries = []
22
+ chunks = chunk_text(text)
23
+ for chunk in chunks:
24
+ response = client.chat.completions.create(
25
+ model="llama-3.1-8b-instant",
26
+ messages=[{"role": "user", "content": f"Summarize this section:\n{chunk}"}],
27
+ temperature=0.3,
28
+ )
29
+ summaries.append(response.choices[0].message.content)
30
+ return "\n\n".join(summaries)
31
+
32
+ def get_limitations(text):
33
+ if not text:
34
+ return "No abstract available."
35
+ prompt = f"Extract only the limitations or challenges discussed in this abstract (if any). If none, write 'No explicit limitations mentioned'.\n\n{text}"
36
+ response = client.chat.completions.create(
37
+ model="llama-3.1-8b-instant",
38
+ messages=[{"role": "user", "content": prompt}]
39
+ )
40
+ return response.choices[0].message.content.strip()
41
+
42
+ def get_research_gaps(text):
43
+ """Return 2-4 potential research gaps based on abstract."""
44
+ if not text:
45
+ return "No abstract available."
46
+ prompt = f"""
47
+ You are a research assistant. Based on this abstract, list 2–4 realistic research gaps or unexplored questions that follow logically from the study. Provide concise bullet points.
48
+ Abstract:
49
+ {text}
50
+ """
51
+ response = client.chat.completions.create(
52
+ model="llama-3.1-8b-instant",
53
+ messages=[{"role": "user", "content": prompt}]
54
+ )
55
+ return response.choices[0].message.content.strip()
56
+
57
+