AI Generated Summary
Learn how to add AI-Generated Summaries useing Codatum's Text Panel feature and Vertex AI.
Last updated
Was this helpful?
Was this helpful?
SELECT
DATE_TRUNC(trip_start_timestamp, month) as month,
company,
payment_type,
COUNT(distinct unique_key) as trip_count,
SUM(trip_seconds) / 60 as total_trip_min,
AVG(trip_seconds) / 60 as average_trip_min,
MAX(trip_seconds) / 60 as max_trip_min,
MIN(trip_seconds) / 60 as min_trip_min,
SUM(trip_miles) as total_trip_miles,
AVG(trip_miles) as average_trip_miles,
MAX(trip_miles) as max_trip_miles,
MIN(trip_miles) as min_trip_miles,
SUM(fare) as total_fare,
AVG(fare) as average_fare,
MAX(fare) as max_fare,
MIN(fare) as min_fare
FROM
`bigquery-public-data.chicago_taxi_trips.taxi_trips`
WHERE trip_start_timestamp >= '2017-01-01' AND trip_start_timestamp < '2018-01-01' -- Data from 2017
--outlier exclusion
AND trip_seconds != 0 AND fare != 0 AND trip_miles != 0
AND trip_seconds < 21600
AND CASE {Company} WHEN '' THEN TRUE ELSE company = {Company} END
AND CASE {PaymentType} WHEN '' THEN TRUE ELSE payment_type = {PaymentType} END
GROUP BY DATE_TRUNC(trip_start_timestamp, month), company, payment_type
ORDER BY monthSELECT
TO_JSON_STRING(STRUCT(
average_fare,average_trip_miles,average_trip_min,company,max_fare,max_trip_miles,max_trip_min,min_fare,min_trip_miles,min_trip_min,month,payment_type,total_fare,total_trip_miles,total_trip_min,trip_count
)) as input_text
FROM
Monthly_basis_summariesSELECT
CONCAT('[', STRING_AGG(input_text, ','), ']') AS all_input_texts
FROM
JSON_formatted_summariesSELECT
JSON_VALUE(ml_generate_text_result.candidates[0].content.parts[0].text) as output,
FROM ML.GENERATE_TEXT(
MODEL `codatum-example.example.vertex_ai`,
(
SELECT
CONCAT(
'The following data is a summary of monthly taxi ride data by company and payment type.',
'Summarize the trends by payment method and month, and create a report in Markdown format.',
'After explaining the overview of the data, such as the total number of rides and the month with the most rides, explain the distinctive items in separate sections.'
'There is no need to enclose the entire Markdown.',
'Please use various Markdown elements.',
'Please ensure that the generated summary is complete. No further editing of the summary will be required. However, additional analysis suggestions are possible.',
'Since code execution is not possible within the summary, please do not embed any code.'
'Payment methods for the taxi ride data in question is ', CASE WHEN {PaymentType} = '' THEN 'All' ELSE {PaymentType} END,', ',
'company is ', CASE WHEN {Company} = '' THEN 'all' ELSE {Company} END, '. Input data:',
all_input_texts
) as prompt,
*,
FROM All_JSON_formatted_summaries
),
STRUCT(
0.3 AS temperature,
1000 AS max_output_tokens)
)