From cf1ecc8376bae74f6d530162e8de442a00bbc311 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20=C5=81uczak?= Date: Tue, 23 Jul 2024 15:35:33 +0200 Subject: [PATCH] v1.2.0 - fixes and adds gpt-4o-mini --- .github/workflows/docker-build.yaml | 9 +++++++-- .pre-commit-config.yaml | 9 +++++++++ VERSION | 1 + src/langchain-openai.ts | 17 +++++++++++++---- src/youtube.ts | 13 +++++++------ 5 files changed, 37 insertions(+), 12 deletions(-) create mode 100644 .pre-commit-config.yaml create mode 100644 VERSION diff --git a/.github/workflows/docker-build.yaml b/.github/workflows/docker-build.yaml index 9672e4a..98c56b4 100644 --- a/.github/workflows/docker-build.yaml +++ b/.github/workflows/docker-build.yaml @@ -21,14 +21,19 @@ jobs: - name: 🛠️ Set up Docker Buildx uses: docker/setup-buildx-action@v3 + - name: 📝 Get application version + id: version + run: | + echo "APP_VERSION=$(cat ./VERSION)" >> "$GITHUB_ENV" + - name: 📝 Docker meta id: meta - uses: docker/metadata-action@v4 + uses: docker/metadata-action@v5 with: images: thevops/youtube-summarizer tags: | type=sha - type=semver,pattern={{raw}} + type=raw,value=${{ steps.version.outputs.APP_VERSION }} type=ref,event=branch type=ref,event=pr diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..3f0abca --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,9 @@ +repos: + - repo: local + hooks: + - id: check-version-file + name: Check VERSION file + entry: | + sh -c 'git diff --quiet master ./VERSION || echo "ERROR: The VERSION file must be different from the one in the master branch."' + language: system + files: VERSION diff --git a/VERSION b/VERSION new file mode 100644 index 0000000..79127d8 --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +v1.2.0 diff --git a/src/langchain-openai.ts b/src/langchain-openai.ts index 1212697..a6f37d9 100644 --- a/src/langchain-openai.ts +++ b/src/langchain-openai.ts @@ -13,8 +13,9 @@ export async function summaryYouTubeTranscript(transcript: string) { Słowa kluczowe: `; const model = new ChatOpenAI({ - model: "gpt-4o", + model: "gpt-4o-mini", temperature: 0.2, + topP: 0.9, apiKey: Config.openai_api_key, }); @@ -56,8 +57,12 @@ if (import.meta.main) { async function test_one() { // Podrabianie sprzętu komputerowego, w tym #cisco, #yubikey - Mateusz Chrobok const transcript_1 = await youtube.getTranscript( - "https://www.youtube.com/watch?v=oDlMrMgGGA4", + "oDlMrMgGGA4", ); + if (transcript_1 === null) { + console.log("Transcript is null"); + return; + } console.log(transcript_1); console.log("--------------------------------------------------"); const [summary_1, usage_1] = await summaryYouTubeTranscript(transcript_1); @@ -68,8 +73,12 @@ if (import.meta.main) { async function test_two() { // O co chodzi z Passkeys? Pytacie, odpowiadam(y). Q&A @secfense const transcript_1 = await youtube.getTranscript( - "https://www.youtube.com/watch?v=rf6LriO_dy8", + "rf6LriO_dy8", ); + if (transcript_1 === null) { + console.log("Transcript is null"); + return; + } console.log(transcript_1); console.log("--------------------------------------------------"); const [summary_1, usage_1] = await summaryYouTubeTranscript(transcript_1); @@ -77,6 +86,6 @@ if (import.meta.main) { console.log(usage_1); } - // await test_one(); + await test_one(); // await test_two(); } diff --git a/src/youtube.ts b/src/youtube.ts index e4d5db5..a2db054 100644 --- a/src/youtube.ts +++ b/src/youtube.ts @@ -1,4 +1,5 @@ import { Innertube } from "youtubei.js/web"; +import { logger } from "./config.ts"; export async function extractVideoId(videoUrl: string): Promise { const urlParts = videoUrl.split("v="); @@ -34,6 +35,7 @@ export async function getTranscript(videoId: string): Promise { .join(" ") ?? "" ); } catch (error) { + logger.error(`Failed to get the transcript: ${error}`); return null; } } @@ -65,30 +67,29 @@ if (import.meta.main) { async function test_getTranscript() { // Jak pół sekundy uratowało świat przed zagładą? - Mateusz Chrobok const transcript_1 = await getTranscript( - "https://www.youtube.com/watch?v=44HSTVBvAO4", + "44HSTVBvAO4", ); console.log(transcript_1); console.log("--------------------------------------------------"); // Nix for Everyone: Unleash Devbox for Simplified Development - DevOps Toolkit const transcript_2 = await getTranscript( - "https://www.youtube.com/watch?v=WiFLtcBvGMU", + "WiFLtcBvGMU", ); console.log(transcript_2); console.log("--------------------------------------------------"); // J.K. Rowling czeka na bycie aresztowaną? | Przegląd Idei #111 (08.04.2024) - Szymon mówi const transcript_3 = await getTranscript( - "https://www.youtube.com/watch?v=Rcw-eWn8hWQ", + "Rcw-eWn8hWQ", ); console.log(transcript_3); } async function test_getVideoDetails() { - // const videoUrl = "https://www.youtube.com/watch?v=rK8gII2FWqA"; - const videoUrl2 = "https://www.youtube.com/watch?v=44HSTVBvAO4"; + const videoId = "44HSTVBvAO4"; const [title, channel, duration, upload_date] = - await getVideoDetails(videoUrl2); + await getVideoDetails(videoId); console.log(`${title} ${channel} ${duration} ${upload_date}`); }