|
import pyvo as vo |
|
import pandas as pd |
|
|
|
def fetch_exoplanet_data(): |
|
|
|
tap_service = vo.dal.TAPService("https://exoplanetarchive.ipac.caltech.edu/TAP") |
|
|
|
|
|
ex_query = """ |
|
SELECT TOP 10 pl_name, hostname, sy_snum, sy_pnum, discoverymethod, disc_year, disc_facility, pl_controv_flag, pl_orbper, pl_orbsmax, pl_rade, pl_bmasse, pl_orbeccen, pl_eqt, st_spectype, st_teff, st_rad, st_mass, ra, dec, sy_vmag |
|
FROM pscomppars |
|
""" |
|
|
|
qresult = tap_service.search(ex_query) |
|
|
|
|
|
ptable = qresult.to_table() |
|
exoplanet_data = ptable.to_pandas() |
|
|
|
return exoplanet_data |
|
|
|
def generate_data_insights(user_input, client, exoplanet_data, max_tokens=500, temperature=0.3): |
|
""" |
|
Generate insights by passing the user's input along with the exoplanet data to GPT-4. |
|
""" |
|
|
|
data_as_text = exoplanet_data.to_csv(index=False) |
|
|
|
|
|
insights_prompt = ( |
|
f"Analyze the following user query and provide relevant insights based on the provided exoplanet data.\n\n" |
|
f"User Query: {user_input}\n\n" |
|
f"Exoplanet Data:\n{data_as_text}\n\n" |
|
f"Please provide insights that are relevant to the user's query." |
|
) |
|
|
|
|
|
response = client.chat.completions.create( |
|
model="gpt-4o", |
|
messages=[ |
|
{"role": "system", "content": "You are an expert in analyzing astronomical data and generating insights."}, |
|
{"role": "user", "content": insights_prompt} |
|
], |
|
max_tokens=max_tokens, |
|
temperature=temperature |
|
) |
|
|
|
|
|
insights_from_data = response.choices[0].message.content.strip() |
|
return insights_from_data |