-
Notifications
You must be signed in to change notification settings - Fork 62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rishabh/clarify questions system prompt #181
Conversation
JP/Wendy - for whenever you review this, feel free to make any changes needed and merge! |
else: | ||
# raise Exception("Replace this with your private data import") | ||
from defog_data_private.metadata import dbs | ||
|
||
with open(self.prompt_file) as file: | ||
model_prompt = file.read() | ||
question_instructions = question + " " + instructions | ||
if table_metadata_string == "": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oooh good catch that we missed out on this logic for the anthropic runner
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for updating, left a small comment on the advanced question.
data/instruct_advanced_postgres.csv
Outdated
@@ -41,7 +41,7 @@ SPM (Selling Profit Margin) = (Total Amount from Sells - (Tax + Commission)) / T | |||
TAC = Total Active Customers who joined within a specified timeframe | |||
CR = Rank customers by their total transaction volume, identifying the customer with the highest transaction volume as rank 1. This involves joining price data with ticker identifiers and filtering for a specified date range." | |||
car_dealership,instructions_cte_join,"What is the average number of days between the sale date and payment received date, rounded to 2 decimal places?","When getting duration between sale and payment date for each sale, get the latest payment for sale by aggregating over the payments_received table first.","WITH sale_payments AS (SELECT s.id AS sale_id, s.sale_date, MAX(p.payment_date) AS latest_payment_date FROM sales s JOIN payments_received p ON s.id = p.sale_id GROUP BY 1,2) SELECT ROUND(AVG(latest_payment_date - sale_date), 2) AS avg_days_to_payment FROM sale_payments","When getting duration between sale and payment date for each sale, get the latest payment for sale by aggregating over the payments_received table first. ASP = Calculate the average price of sales within a specific timeframe Last 30 days = Use a range from the current date minus a certain interval to the current date, always ensure to make the necessary joins before utilizing the sales data. TSC = Count of sales within a specified period" | |||
car_dealership,instructions_cte_join,"Return the highest sale price for each make and model of cars that have been sold and are no longer in inventory, ordered by the sale price from highest to lowest.","When getting a car's inventory status, always take the latest status from the inventory_snapshots table","WITH latest_inventory_status AS (SELECT car_id, is_in_inventory, ROW_NUMBER() OVER(PARTITION BY car_id ORDER BY snapshot_date DESC, crtd_ts DESC) AS rn FROM inventory_snapshots) SELECT c.make, c.model, MAX(s.sale_price) AS highest_sale_price FROM cars c JOIN sales s ON c.id = s.car_id JOIN latest_inventory_status lis ON c.id = lis.car_id WHERE lis.is_in_inventory = FALSE AND lis.rn = 1 GROUP BY c.make, c.model ORDER BY highest_sale_price DESC","TSC = Count of sales within a specified period | |||
car_dealership,instructions_cte_join,"Return the highest sale price for each make and model of cars that have been sold and are no longer in inventory, ordered by the sale price from highest to lowest.","When getting a car's inventory status, always take the latest status from the inventory_snapshots table","WITH latest_inventory_status AS (SELECT car_id, is_in_inventory FROM inventory_snapshots) SELECT c.make, c.model, MAX(s.sale_price) AS highest_sale_price FROM cars c JOIN sales s ON c.id = s.car_id JOIN latest_inventory_status lis ON c.id = lis.car_id WHERE lis.is_in_inventory = FALSE GROUP BY c.make, c.model ORDER BY highest_sale_price DESC","TSC = Count of sales within a specified period |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a tricky one and it took me awhile to figure out what's going on here. I think the golden query seems right, and the key lies in the instruction:
"When getting a car's inventory status, always take the latest status from the inventory_snapshots table"
ie to get the inventory status, we'll need to first get the latest row for each car in inventory_snapshot, hence the window function that partitions by car id and orders by snapshot_date (crtd_ts can be safely ignored). That said, I think this might still be ambiguous because this could mean either:
- get the latest snapshot date, and only consider cars whose is_in_inventory on that specific date. in our data, the latest snapshot date is 2023-04-15, and there is only 1 entry on 2023-04-15 (car 9), and that means only that car is considered.
- for each car, get its respective latest date. eg car 1's latest date is 2023-03-28, while car 9's latest date is 2023-04-15, and then use the is_in_inventory for that latest date. in our data this means that we have 10 cars that we can consider, out of which 8 is_in_inventory is false.
I think this is hard to clarify much further without an extensive glossary about how the tables work, and I think we might need to adapt the data, such that we get full snapshots of all cars on each snapshot date so that either of both interpretations return the same result. wdyt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok i'm slightly confused. I'm not getting how the instructions could mean the first point. From "When getting a car's inventory status" I just thought it's pretty straightforward for it to mean an individual car, the same way your second pointer implies. Which means the row_number() is still important to the question.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aye! From looking at the data underneath,the same car can have multiple entries in the inventory_snapshots table. For example, if this was (say) a second hand car store that can have the same car floating in and out of the system. M
Just clarifying this in either the instructions or questions should work (without updating the underlying data). From the question + instructions, it’s unclear that this would be the case!
I'll do this in a bit :D Thanks JP and Wendy!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the inputs all! On a second read, I agree that the second point is the more natural interpretation and am for clarifying the question/instructions, possibly something along the lines of for each car, get its latest entry in the snapshots table and use that entry's inventory status
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in latest push!
eval/bedrock_runner.py
Outdated
generated_query = ( | ||
generated_query.split("```sql")[-1].split("```")[0].split(";")[0].strip() + ";" | ||
) | ||
print(generated_query) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: should we remove the print statement?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do!
shuffle, | ||
) | ||
pruned_metadata_str = pruned_metadata_ddl + join_str | ||
elif columns_to_keep == 0: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for adding this! sorry I missed this while updating the columns_to_keep
earlier.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All good!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the improvements!
Made a final change (couldn't find this yesterday because it was a Monday)! For this question in v1: Our previous golden query was: SELECT
payment_date,
payment_method,
SUM(payment_amount) AS total_amount
FROM
payments_received
WHERE
payment_date BETWEEN
DATE_TRUNC('WEEK', CURRENT_DATE) - INTERVAL '1 week'
AND DATE_TRUNC('WEEK', CURRENT_DATE)
GROUP BY
payment_date, payment_method
ORDER BY payment_date DESC, payment_method ASC; However, the question was ambiguous. Last week can mean both the last 7 days, and the last ISO week. So I have changed this to the harder and intended variant Additionally, the SELECT
payment_date,
payment_method,
SUM(payment_amount) AS total_amount
FROM
payments_received
WHERE
payment_date >= DATE_TRUNC('WEEK', CURRENT_DATE) - INTERVAL '1 week'
AND payment_date < DATE_TRUNC('WEEK', CURRENT_DATE)
GROUP BY
payment_date, payment_method
ORDER BY payment_date DESC, payment_method ASC; |
ooh good find. thanks for the change! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm thanks for the detailed fixes and explanation as well!
- Remove 'MoM will always be zero for the first month that appears in your answer.'
- Remove 'MoM will always be zero for the first month that appears in your answer.'
Return the highest sale price for each make and model of cars that have been sold and are no longer in inventory, ordered by the sale price from highest to lowest.
)prompt_cot.md