Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -51,27 +51,42 @@ def talk_to_llm(user_prompt):
|
|
| 51 |
}
|
| 52 |
|
| 53 |
prompt_text = f'''
|
| 54 |
-
As StarGateVR, your role is specialized in customizing ADQL (Astronomical Data Query Language)
|
|
|
|
|
|
|
| 55 |
|
| 56 |
-
The query includes essential fields like source_id, positional data (
|
|
|
|
|
|
|
| 57 |
|
| 58 |
-
Customizing 'WHERE' Clause: Your primary task is to adapt the 'WHERE' clause to fit
|
| 59 |
-
|
| 60 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
|
| 62 |
Here is an example of the WHERE clause:
|
| 63 |
-
|
| 64 |
```
|
| 65 |
WHERE (parallax >= 11.11 AND parallax_over_error>=20 AND
|
| 66 |
astrometric_excess_noise<=2)
|
| 67 |
```
|
| 68 |
|
| 69 |
-
Bounds on Parallax: Always include bounds on parallax in the 'WHERE' clause. This is
|
|
|
|
| 70 |
|
| 71 |
The json structure to return is
|
| 72 |
{{
|
| 73 |
-
"reasoning": "<Think through what the user is asking for, and what you know about the GAIA DB
|
| 74 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
}}
|
| 76 |
|
| 77 |
The users prompt is "{user_prompt}"
|
|
@@ -94,12 +109,12 @@ def talk_to_llm(user_prompt):
|
|
| 94 |
output_json = json.loads(response_json['choices'][0]['message']['content'])
|
| 95 |
|
| 96 |
try:
|
| 97 |
-
|
| 98 |
reasoning = output_json['reasoning']
|
| 99 |
print(f"dialog: {reasoning}")
|
| 100 |
-
print(f"query: {
|
| 101 |
# Update theme on the server
|
| 102 |
-
return reasoning,
|
| 103 |
except KeyError as e:
|
| 104 |
print(f"Key error: {e}")
|
| 105 |
return "Failed to generate query."
|
|
@@ -121,7 +136,7 @@ def complete_query(partial_query):
|
|
| 121 |
-- Measured Position
|
| 122 |
ra,
|
| 123 |
dec,
|
| 124 |
-
|
| 125 |
-- Measured Motion
|
| 126 |
pmra,
|
| 127 |
pmdec,
|
|
@@ -140,7 +155,6 @@ def complete_query(partial_query):
|
|
| 140 |
parallax_error,
|
| 141 |
|
| 142 |
-- Additional parameters that appear in the WHERE clause should be added here
|
| 143 |
-
-- Example: MH_GSPPhot as
|
| 144 |
|
| 145 |
-- Note: No comma after this last SELECT item
|
| 146 |
parallax_over_error
|
|
@@ -195,27 +209,29 @@ def process_queries():
|
|
| 195 |
results = {}
|
| 196 |
for prompt in user_prompt_examples:
|
| 197 |
print (f"Processing prompt: {prompt}")
|
| 198 |
-
reasoning,
|
| 199 |
-
query = complete_query(
|
| 200 |
download_url_from_query(query, prompt)
|
| 201 |
return results
|
| 202 |
|
| 203 |
with gr.Blocks() as demo:
|
| 204 |
with gr.Row():
|
| 205 |
-
user_prompt = gr.Textbox(label="Enter your query for the LLM", value="Find me the stars in
|
|
|
|
| 206 |
submit_btn = gr.Button("Ask LLM")
|
| 207 |
reasoning_output = gr.Textbox(label="Reasoning")
|
| 208 |
-
|
| 209 |
|
| 210 |
|
| 211 |
make_query_complete_bt = gr.Button("Complete Query")
|
| 212 |
complete_query_output = gr.Textbox(label="Complete Query")
|
| 213 |
make_query_complete_bt.click(fn=complete_query, inputs=where_clause_output, outputs=[complete_query_output])
|
| 214 |
-
submit_btn.click(fn=talk_to_llm, inputs=user_prompt, outputs=[reasoning_output,
|
| 215 |
|
| 216 |
create_tap_url_bt = gr.Button("Create TAP URL")
|
| 217 |
download_data_output = gr.Markdown()
|
| 218 |
-
create_tap_url_bt.click(fn=create_markdown_url_from_query, inputs=complete_query_output,
|
|
|
|
| 219 |
|
| 220 |
#demo.launch(server_name="0.0.0.0", server_port=7861, share=True, debug=True)
|
| 221 |
demo.launch()
|
|
|
|
| 51 |
}
|
| 52 |
|
| 53 |
prompt_text = f'''
|
| 54 |
+
As StarGateVR, your role is specialized in customizing ADQL (Astronomical Data Query Language)
|
| 55 |
+
queries for astronomers. Your focus is particularly on integrating specific 'WHERE' clauses into
|
| 56 |
+
a standard query template. We will put your WHERE clause into the completed query template.
|
| 57 |
|
| 58 |
+
The query includes essential SELECT fields like source_id, positional data (ra, dec),
|
| 59 |
+
motion data (pmra, pmdec), and light parameters. Note that any
|
| 60 |
+
fields used in the WHERE clause must also be added to the SELECT clause.
|
| 61 |
|
| 62 |
+
Customizing 'WHERE' Clause: Your primary task is to adapt the 'WHERE' clause to fit
|
| 63 |
+
the user's specific astronomical requirements. This often involves filtering stars based on
|
| 64 |
+
various criteria such as distance, location in the sky, brightness, etc.
|
| 65 |
+
|
| 66 |
+
Always include, at a minimum, the SELECT and FROM clauses as given in the template. Note that
|
| 67 |
+
the WHERE clause must reference variables by the field name and not the "AS" name.
|
| 68 |
+
There is a special case for the part of the SELECT that is " 'Gaia DR3 ' || source_id as source_id",
|
| 69 |
+
in the WHERE clause this field should always be referred to by "source_id".
|
| 70 |
|
| 71 |
Here is an example of the WHERE clause:
|
|
|
|
| 72 |
```
|
| 73 |
WHERE (parallax >= 11.11 AND parallax_over_error>=20 AND
|
| 74 |
astrometric_excess_noise<=2)
|
| 75 |
```
|
| 76 |
|
| 77 |
+
Bounds on Parallax: Always include bounds on parallax in the 'WHERE' clause. This is
|
| 78 |
+
important as it helps in retrieving stars within a specified 3D region of space.
|
| 79 |
|
| 80 |
The json structure to return is
|
| 81 |
{{
|
| 82 |
+
"reasoning": "<Think through what the user is asking for, and what you know about the GAIA DB
|
| 83 |
+
and astronomy to create their request. Because the WHERE clause you are generating
|
| 84 |
+
is going to be concatenated into a larger SQL query, consider how to structure the
|
| 85 |
+
query such that everything fits in a single WHERE clause. Otherwise it will break
|
| 86 |
+
the downstream logic.>",
|
| 87 |
+
"the_query": "<a properly formatted ADQL query that will return the stars the
|
| 88 |
+
user is asking for>"
|
| 89 |
+
|
| 90 |
}}
|
| 91 |
|
| 92 |
The users prompt is "{user_prompt}"
|
|
|
|
| 109 |
output_json = json.loads(response_json['choices'][0]['message']['content'])
|
| 110 |
|
| 111 |
try:
|
| 112 |
+
the_query = output_json['the_query']
|
| 113 |
reasoning = output_json['reasoning']
|
| 114 |
print(f"dialog: {reasoning}")
|
| 115 |
+
print(f"query: {the_query}")
|
| 116 |
# Update theme on the server
|
| 117 |
+
return reasoning, the_query
|
| 118 |
except KeyError as e:
|
| 119 |
print(f"Key error: {e}")
|
| 120 |
return "Failed to generate query."
|
|
|
|
| 136 |
-- Measured Position
|
| 137 |
ra,
|
| 138 |
dec,
|
| 139 |
+
parallax,
|
| 140 |
-- Measured Motion
|
| 141 |
pmra,
|
| 142 |
pmdec,
|
|
|
|
| 155 |
parallax_error,
|
| 156 |
|
| 157 |
-- Additional parameters that appear in the WHERE clause should be added here
|
|
|
|
| 158 |
|
| 159 |
-- Note: No comma after this last SELECT item
|
| 160 |
parallax_over_error
|
|
|
|
| 209 |
results = {}
|
| 210 |
for prompt in user_prompt_examples:
|
| 211 |
print (f"Processing prompt: {prompt}")
|
| 212 |
+
reasoning, the_query = talk_to_llm(prompt)
|
| 213 |
+
query = the_query #complete_query(the_query)
|
| 214 |
download_url_from_query(query, prompt)
|
| 215 |
return results
|
| 216 |
|
| 217 |
with gr.Blocks() as demo:
|
| 218 |
with gr.Row():
|
| 219 |
+
user_prompt = gr.Textbox(label="Enter your query for the LLM", value="Find me the stars in
|
| 220 |
+
the hayedes cluster.")
|
| 221 |
submit_btn = gr.Button("Ask LLM")
|
| 222 |
reasoning_output = gr.Textbox(label="Reasoning")
|
| 223 |
+
the_query_output = gr.Textbox(label="The Query")
|
| 224 |
|
| 225 |
|
| 226 |
make_query_complete_bt = gr.Button("Complete Query")
|
| 227 |
complete_query_output = gr.Textbox(label="Complete Query")
|
| 228 |
make_query_complete_bt.click(fn=complete_query, inputs=where_clause_output, outputs=[complete_query_output])
|
| 229 |
+
submit_btn.click(fn=talk_to_llm, inputs=user_prompt, outputs=[reasoning_output, the_query_output])
|
| 230 |
|
| 231 |
create_tap_url_bt = gr.Button("Create TAP URL")
|
| 232 |
download_data_output = gr.Markdown()
|
| 233 |
+
create_tap_url_bt.click(fn=create_markdown_url_from_query, inputs=complete_query_output,
|
| 234 |
+
outputs=[download_data_output])
|
| 235 |
|
| 236 |
#demo.launch(server_name="0.0.0.0", server_port=7861, share=True, debug=True)
|
| 237 |
demo.launch()
|