aquibmoin commited on
Commit
20010b0
·
verified ·
1 Parent(s): e36e61e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -50
app.py CHANGED
@@ -19,6 +19,9 @@ from pinecone import Pinecone
19
  import logging
20
  import re
21
 
 
 
 
22
  from langchain_openai import ChatOpenAI
23
  from langchain_openai import OpenAIEmbeddings
24
  llm = ChatOpenAI(model="gpt-4o")
@@ -129,56 +132,6 @@ def clean_retrieved_context(raw_context):
129
  # Return explicitly cleaned context
130
  return cleaned.strip()
131
 
132
-
133
- def extract_keywords_with_gpt(context, max_tokens=100, temperature=0.3):
134
-
135
- keyword_prompt = f"Extract 3 most important scientific keywords from the following user query:\n\n{context}"
136
-
137
- response = client.chat.completions.create(
138
- model="gpt-4",
139
- messages=[
140
- {"role": "system", "content": "You are an expert in identifying key scientific terms and concepts."},
141
- {"role": "user", "content": keyword_prompt}
142
- ],
143
- max_tokens=max_tokens,
144
- temperature=temperature
145
- )
146
-
147
- extracted_keywords = response.choices[0].message.content.strip()
148
-
149
- cleaned_keywords = re.sub(r'\d+\.\s*', '', extracted_keywords)
150
-
151
- keywords_list = [kw.strip() for kw in cleaned_keywords.split("\n") if kw.strip()]
152
-
153
- return keywords_list
154
-
155
- def fetch_nasa_ads_references(ads_query):
156
- """Fetch relevant NASA ADS papers and format them for readability."""
157
- try:
158
- # Query NASA ADS for relevant papers
159
- papers = ADS.query_simple(ads_query)
160
-
161
- if not papers or len(papers) == 0:
162
- return [("No results found", "N/A", "N/A", "N/A", "N/A", "N/A")]
163
-
164
- # Include authors in the references
165
- references = []
166
- for paper in papers[:5]: # Limit to 5 references
167
- title = paper.get('title', ['Title not available'])[0]
168
- abstract = paper.get('abstract', 'Abstract not available')
169
- authors = ", ".join(paper.get('author', [])[:3]) + (" et al." if len(paper.get('author', [])) > 3 else "")
170
- bibcode = paper.get('bibcode', 'N/A')
171
- pub = paper.get('pub', 'Unknown Journal')
172
- pubdate = paper.get('pubdate', 'Unknown Date')
173
-
174
- references.append((title, abstract, authors, bibcode, pub, pubdate))
175
-
176
- return references
177
-
178
- except Exception as e:
179
- logging.error(f"Error fetching ADS references: {str(e)}")
180
- return [("Error fetching references", "See logs for details", "N/A", "N/A", "N/A", "N/A")]
181
-
182
  def fetch_exoplanet_data():
183
  # Connect to NASA Exoplanet Archive TAP Service
184
  tap_service = vo.dal.TAPService("https://exoplanetarchive.ipac.caltech.edu/TAP")
 
19
  import logging
20
  import re
21
 
22
+ from utils.ads_references import fetch_nasa_ads_references, extract_keywords_with_gpt
23
+
24
+
25
  from langchain_openai import ChatOpenAI
26
  from langchain_openai import OpenAIEmbeddings
27
  llm = ChatOpenAI(model="gpt-4o")
 
132
  # Return explicitly cleaned context
133
  return cleaned.strip()
134
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
135
  def fetch_exoplanet_data():
136
  # Connect to NASA Exoplanet Archive TAP Service
137
  tap_service = vo.dal.TAPService("https://exoplanetarchive.ipac.caltech.edu/TAP")