Update utils/ads_references.py
Browse files- utils/ads_references.py +21 -21
utils/ads_references.py
CHANGED
|
@@ -1,3 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
|
| 2 |
def fetch_nasa_ads_references(ads_query):
|
| 3 |
"""Fetch relevant NASA ADS papers and format them for readability."""
|
|
@@ -26,24 +47,3 @@ def fetch_nasa_ads_references(ads_query):
|
|
| 26 |
logging.error(f"Error fetching ADS references: {str(e)}")
|
| 27 |
return [("Error fetching references", "See logs for details", "N/A", "N/A", "N/A", "N/A")]
|
| 28 |
|
| 29 |
-
def extract_keywords_with_gpt(context, max_tokens=100, temperature=0.3):
|
| 30 |
-
|
| 31 |
-
keyword_prompt = f"Extract 3 most important scientific keywords from the following user query:\n\n{context}"
|
| 32 |
-
|
| 33 |
-
response = client.chat.completions.create(
|
| 34 |
-
model="gpt-4",
|
| 35 |
-
messages=[
|
| 36 |
-
{"role": "system", "content": "You are an expert in identifying key scientific terms and concepts."},
|
| 37 |
-
{"role": "user", "content": keyword_prompt}
|
| 38 |
-
],
|
| 39 |
-
max_tokens=max_tokens,
|
| 40 |
-
temperature=temperature
|
| 41 |
-
)
|
| 42 |
-
|
| 43 |
-
extracted_keywords = response.choices[0].message.content.strip()
|
| 44 |
-
|
| 45 |
-
cleaned_keywords = re.sub(r'\d+\.\s*', '', extracted_keywords)
|
| 46 |
-
|
| 47 |
-
keywords_list = [kw.strip() for kw in cleaned_keywords.split("\n") if kw.strip()]
|
| 48 |
-
|
| 49 |
-
return keywords_list
|
|
|
|
| 1 |
+
def extract_keywords_with_gpt(context, max_tokens=100, temperature=0.3):
|
| 2 |
+
|
| 3 |
+
keyword_prompt = f"Extract 3 most important scientific keywords from the following user query:\n\n{context}"
|
| 4 |
+
|
| 5 |
+
response = client.chat.completions.create(
|
| 6 |
+
model="gpt-4",
|
| 7 |
+
messages=[
|
| 8 |
+
{"role": "system", "content": "You are an expert in identifying key scientific terms and concepts."},
|
| 9 |
+
{"role": "user", "content": keyword_prompt}
|
| 10 |
+
],
|
| 11 |
+
max_tokens=max_tokens,
|
| 12 |
+
temperature=temperature
|
| 13 |
+
)
|
| 14 |
+
|
| 15 |
+
extracted_keywords = response.choices[0].message.content.strip()
|
| 16 |
+
|
| 17 |
+
cleaned_keywords = re.sub(r'\d+\.\s*', '', extracted_keywords)
|
| 18 |
+
|
| 19 |
+
keywords_list = [kw.strip() for kw in cleaned_keywords.split("\n") if kw.strip()]
|
| 20 |
+
|
| 21 |
+
return keywords_list
|
| 22 |
|
| 23 |
def fetch_nasa_ads_references(ads_query):
|
| 24 |
"""Fetch relevant NASA ADS papers and format them for readability."""
|
|
|
|
| 47 |
logging.error(f"Error fetching ADS references: {str(e)}")
|
| 48 |
return [("Error fetching references", "See logs for details", "N/A", "N/A", "N/A", "N/A")]
|
| 49 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|