From daa59e34ad6866dc46803668ad1d1eddc29aa22d Mon Sep 17 00:00:00 2001 From: Ayyub I Date: Sat, 30 Sep 2023 10:43:52 -0500 Subject: [PATCH 1/4] hyperlinked urls w timestamps --- .../functions/getanswer/inquirer.py | 14 +++++++- packages/web/components/Citation.tsx | 2 +- packages/web/components/NewQuery.tsx | 34 ++++++++++++++++--- 3 files changed, 43 insertions(+), 7 deletions(-) diff --git a/packages/googlecloud/functions/getanswer/inquirer.py b/packages/googlecloud/functions/getanswer/inquirer.py index d2b171b7..c321ee0f 100644 --- a/packages/googlecloud/functions/getanswer/inquirer.py +++ b/packages/googlecloud/functions/getanswer/inquirer.py @@ -17,6 +17,12 @@ logger = logging.getLogger(__name__) +def timestamp_to_seconds(timestamp): + start_time = timestamp.split("-")[0] # Split by '-' and take the first part + h, m, s = [int(i) for i in start_time.split(":")] + return h * 3600 + m * 60 + s + + def process_responses_llm(responses_llm, docs=None): generated_responses = responses_llm.split("\n\n") responses = [] @@ -61,13 +67,19 @@ def gen_responses(i): section["source_timestamp"] = timestamps[i] if i < len(timestamps) else None section["source_url"] = urls[i] if i < len(urls) else None + if section["source_url"] and section["source_timestamp"]: + time_in_seconds = timestamp_to_seconds(section["source_timestamp"]) + if "?" in section["source_url"]: section["source_url"] += f"&t={time_in_seconds}s" + else: + section["source_url"] += f"?t={time_in_seconds}s" + citation = {} if section["source_title"] is not None: citation["Title"] = section["source_title"] if section["source_publish_date"] is not None: citation["Published"] = section["source_publish_date"] if section["source_url"] is not None: - citation["URL"] = section["source_url"] + citation["URL"] = section["source_url"] # Add this line if section["source_timestamp"] is not None: citation["Video timestamp"] = section["source_timestamp"] if section["source_name"] is not None: diff --git a/packages/web/components/Citation.tsx b/packages/web/components/Citation.tsx index 322f1e74..875ce65c 100644 --- a/packages/web/components/Citation.tsx +++ b/packages/web/components/Citation.tsx @@ -9,7 +9,7 @@ const citationKeyMap: { [key: string]: string } = { source_title: "Source Title", source_name: "Source Name", source_publish_date: "Source Publish Date", - source_url: "Source URL", + source_url: "Source URL (with timestamp)", }; const Citation = ({ citation, index }: CitationProps) => { diff --git a/packages/web/components/NewQuery.tsx b/packages/web/components/NewQuery.tsx index 8567be16..6b5ee2cb 100644 --- a/packages/web/components/NewQuery.tsx +++ b/packages/web/components/NewQuery.tsx @@ -8,12 +8,30 @@ import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { useState } from "react"; import { useCardResults } from "./CardResultsProvider"; +function YouTubeEmbed({ url }: { url: string }) { + const videoId = url.split("v=")[1]?.split("&")[0]; + if (!videoId) return null; + + return ( + + ); +} + export default function NewQuery() { const apiEndpoint = process.env.NEXT_PUBLIC_TGI_API_ENDPOINT!; const [query, setQuery] = useState(""); const [isProcessing, setIsProcessing] = useState(false); const [cardType, setCardType] = useState(ECardType.QUERY_IN_DEPTH); const { addMyCard } = useCardResults(); + const [card, setCard] = useState(null); + const insertSupabaseCard = async (): Promise => { const newCard: ICard = { @@ -74,9 +92,7 @@ export default function NewQuery() { ) => { const genResponseMs = Math.ceil(Date.now() - startedProcessingAt); const queryUpdate = { - // responses: JSON.stringify(card.responses), responses: card.responses, - // citations: JSON.stringify(card.citations), citations: card.citations, processing_time_ms: genResponseMs, }; @@ -90,7 +106,6 @@ export default function NewQuery() { console.warn(error); return; } else { - // successfully updated } }; @@ -110,7 +125,7 @@ export default function NewQuery() { return (
-
+
- {/*

Please choose a password.

*/}
); } From a0059e3c11cb2caf85b422542b06dbcb4e2cab8e Mon Sep 17 00:00:00 2001 From: Ayyub I Date: Sat, 30 Sep 2023 10:47:53 -0500 Subject: [PATCH 2/4] corrected syntax for allowfullscreen --- packages/web/components/NewQuery.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/web/components/NewQuery.tsx b/packages/web/components/NewQuery.tsx index 6b5ee2cb..f3dcb2dc 100644 --- a/packages/web/components/NewQuery.tsx +++ b/packages/web/components/NewQuery.tsx @@ -19,7 +19,7 @@ function YouTubeEmbed({ url }: { url: string }) { src={`https://www.youtube.com/embed/${videoId}`} frameBorder="0" title="YouTube Video" - allowfullscreen + allowFullScreen > ); } From 9905aac1d4120cb69b9e9642b5199235a5f8035c Mon Sep 17 00:00:00 2001 From: Ayyub I Date: Sat, 30 Sep 2023 10:57:39 -0500 Subject: [PATCH 3/4] fixed citation mapping --- packages/web/components/NewQuery.tsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/web/components/NewQuery.tsx b/packages/web/components/NewQuery.tsx index f3dcb2dc..0ba91a07 100644 --- a/packages/web/components/NewQuery.tsx +++ b/packages/web/components/NewQuery.tsx @@ -154,9 +154,8 @@ export default function NewQuery() { - {/* Display the YouTube embeds*/}
- {card?.citations.map((citation, index) => ( + {card?.citations?.map((citation, index) => (

{citation.source_title}

{citation.source_url.includes("youtube.com") && } From 32ec08b529c2cdfd505363f86e2f1fb221b27322 Mon Sep 17 00:00:00 2001 From: Ayyub I Date: Sat, 30 Sep 2023 11:15:59 -0500 Subject: [PATCH 4/4] changed source_url syntax --- packages/web/components/NewQuery.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/web/components/NewQuery.tsx b/packages/web/components/NewQuery.tsx index 0ba91a07..00c7463e 100644 --- a/packages/web/components/NewQuery.tsx +++ b/packages/web/components/NewQuery.tsx @@ -158,7 +158,8 @@ export default function NewQuery() { {card?.citations?.map((citation, index) => (

{citation.source_title}

- {citation.source_url.includes("youtube.com") && } + {citation.source_url && citation.source_url.includes("youtube.com") && + }
))}