Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions examples/langtail-youtube-context/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# DO NOT COMMIT THIS FILE - IT WILL CONTAIN YOUR SENSITIVE KEYS.
# Instead, rename this file to ".env" instead of ".env.example". (.env will not be committed)

# Create an OpenAI API key at https://platform.openai.com/account/api-keys
OPENAI_API_KEY="sk-123..."
LANGTAIL_API_KEY=""
DATABASE_URL="file:./dev.db"
43 changes: 43 additions & 0 deletions examples/langtail-youtube-context/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js
.yarn/install-state.gz

# testing
/coverage

# next.js
/.next/
/out/

# production
/build

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# local env files
.env*.local
.env

# vercel
.vercel

# typescript
*.tsbuildinfo
next-env.d.ts

# python env
venv

# ignore temp folder
temp
55 changes: 55 additions & 0 deletions examples/langtail-youtube-context/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Hackathon Project: Youtube Context + Langtail

## Description
User provides youtube link and the app will provide summary of the video in the language of their choice.

## Restrictions
- Long videos will have large transcriptions. E.g. 1 hour interview video could have >200K tokens.

# TypeScript Next.js example

This is a really simple project that shows the usage of Next.js with TypeScript.

## Deploy your own

Deploy the example using [Vercel](https://vercel.com?utm_source=github&utm_medium=readme&utm_campaign=next-example) or preview live with [StackBlitz](https://stackblitz.com/github/vercel/next.js/tree/canary/examples/with-typescript)

[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https://github.com/vercel/next.js/tree/canary/examples/with-typescript&project-name=with-typescript&repository-name=with-typescript)

## How to use it?

Execute [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app) with [npm](https://docs.npmjs.com/cli/init), [Yarn](https://yarnpkg.com/lang/en/docs/cli/create/), or [pnpm](https://pnpm.io) to bootstrap the example:

```bash
npx create-next-app --example with-typescript with-typescript-app
```

```bash
yarn create next-app --example with-typescript with-typescript-app
```

```bash
pnpm create next-app --example with-typescript with-typescript-app
```

Deploy it to the cloud with [Vercel](https://vercel.com/new?utm_source=github&utm_medium=readme&utm_campaign=next-example) ([Documentation](https://nextjs.org/docs/deployment)).

## Notes

This example shows how to integrate the TypeScript type system into Next.js. Since TypeScript is supported out of the box with Next.js, all we have to do is to install TypeScript.

```
npm install --save-dev typescript
```

To enable TypeScript's features, we install the type declarations for React and Node.

```
npm install --save-dev @types/react @types/react-dom @types/node
```

When we run `next dev` the next time, Next.js will start looking for any `.ts` or `.tsx` files in our project and builds it. It even automatically creates a `tsconfig.json` file for our project with the recommended settings.

Next.js has built-in TypeScript declarations, so we'll get autocompletion for Next.js' modules straight away.

A `type-check` script is also added to `package.json`, which runs TypeScript's `tsc` CLI in `noEmit` mode to run type-checking separately. You can then include this, for example, in your `test` scripts.
17 changes: 17 additions & 0 deletions examples/langtail-youtube-context/components.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"$schema": "https://ui.shadcn.com/schema.json",
"style": "new-york",
"rsc": true,
"tsx": true,
"tailwind": {
"config": "tailwind.config.js",
"css": "globals.css",
"baseColor": "red",
"cssVariables": true,
"prefix": ""
},
"aliases": {
"components": "@/components",
"utils": "@/lib/utils"
}
}
28 changes: 28 additions & 0 deletions examples/langtail-youtube-context/get_context.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# get_context.py

import sys
import subprocess
import os

def download_transcript(video_url):
command = f"yt-dlp --write-auto-sub --sub-lang en --skip-download {video_url} -o 'transcript.%(ext)s'"
subprocess.run(command, shell=True, check=True)
transcript_file = 'transcript.en.vtt'
if os.path.exists(transcript_file):
with open(transcript_file, 'r') as file:
transcript = file.read()
return transcript
else:
raise FileNotFoundError(f"Transcript file {transcript_file} not found")

if __name__ == "__main__":
if len(sys.argv) < 2:
print("Usage: python get_context.py <YouTube URL>")
sys.exit(1)

video_url = sys.argv[1]
try:
transcript = download_transcript(video_url)
print(transcript)
except Exception as e:
print(f"Error: {e}")
69 changes: 69 additions & 0 deletions examples/langtail-youtube-context/globals.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
@tailwind base;
@tailwind components;
@tailwind utilities;

@layer base {
:root {
--background: 0 0% 100%;
--foreground: 0 0% 3.9%;
--card: 0 0% 100%;
--card-foreground: 0 0% 3.9%;
--popover: 0 0% 100%;
--popover-foreground: 0 0% 3.9%;
--primary: 0 72.2% 50.6%;
--primary-foreground: 0 85.7% 97.3%;
--secondary: 0 0% 96.1%;
--secondary-foreground: 0 0% 9%;
--muted: 0 0% 96.1%;
--muted-foreground: 0 0% 45.1%;
--accent: 0 0% 96.1%;
--accent-foreground: 0 0% 9%;
--destructive: 0 84.2% 60.2%;
--destructive-foreground: 0 0% 98%;
--border: 0 0% 89.8%;
--input: 0 0% 89.8%;
--ring: 0 72.2% 50.6%;
--radius: 0.5rem;
--chart-1: 12 76% 61%;
--chart-2: 173 58% 39%;
--chart-3: 197 37% 24%;
--chart-4: 43 74% 66%;
--chart-5: 27 87% 67%;
}

.dark {
--background: 0 0% 3.9%;
--foreground: 0 0% 98%;
--card: 0 0% 3.9%;
--card-foreground: 0 0% 98%;
--popover: 0 0% 3.9%;
--popover-foreground: 0 0% 98%;
--primary: 0 72.2% 50.6%;
--primary-foreground: 0 85.7% 97.3%;
--secondary: 0 0% 14.9%;
--secondary-foreground: 0 0% 98%;
--muted: 0 0% 14.9%;
--muted-foreground: 0 0% 63.9%;
--accent: 0 0% 14.9%;
--accent-foreground: 0 0% 98%;
--destructive: 0 62.8% 30.6%;
--destructive-foreground: 0 0% 98%;
--border: 0 0% 14.9%;
--input: 0 0% 14.9%;
--ring: 0 72.2% 50.6%;
--chart-1: 220 70% 50%;
--chart-2: 160 60% 45%;
--chart-3: 30 80% 55%;
--chart-4: 280 65% 60%;
--chart-5: 340 75% 55%;
}
}

@layer base {
* {
@apply border-border;
}
body {
@apply bg-background text-foreground;
}
}
13 changes: 13 additions & 0 deletions examples/langtail-youtube-context/lib/prisma.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { PrismaClient } from "@prisma/client";

const prismaClientSingleton = () => {
return new PrismaClient();
};

declare global {
var prisma: undefined | ReturnType<typeof prismaClientSingleton>;
}

export const prisma = globalThis.prisma ?? prismaClientSingleton();

if (process.env.NODE_ENV !== "production") globalThis.prisma = prisma;
6 changes: 6 additions & 0 deletions examples/langtail-youtube-context/lib/styles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { type ClassValue, clsx } from "clsx";
import { twMerge } from "tailwind-merge";

export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs));
}
47 changes: 47 additions & 0 deletions examples/langtail-youtube-context/lib/trpc.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { httpBatchLink } from "@trpc/client";
import { createTRPCNext } from "@trpc/next";
import type { AppRouter } from "@/server/routers/_app";

function getBaseUrl() {
if (typeof window !== "undefined")
// browser should use relative path
return "";

if (process.env.VERCEL_URL)
// reference for vercel.com
return `https://${process.env.VERCEL_URL}`;

if (process.env.RENDER_INTERNAL_HOSTNAME)
// reference for render.com
return `http://${process.env.RENDER_INTERNAL_HOSTNAME}:${process.env.PORT}`;

// assume localhost
return `http://localhost:${process.env.PORT ?? 3000}`;
}

export const trpc = createTRPCNext<AppRouter>({
config(opts) {
return {
links: [
httpBatchLink({
/**
* If you want to use SSR, you need to use the server's full URL
* @link https://trpc.io/docs/v11/ssr
**/
url: `${getBaseUrl()}/api/trpc`,

// You can pass any HTTP headers you wish here
async headers() {
return {
// authorization: getAuthCookie(),
};
},
}),
],
};
},
/**
* @link https://trpc.io/docs/v11/ssr
**/
ssr: false,
});
5 changes: 5 additions & 0 deletions examples/langtail-youtube-context/lib/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Langtail } from "langtail";

export const lt = new Langtail({
apiKey: process.env.LANGTAIL_API_KEY ?? "",
});
42 changes: 42 additions & 0 deletions examples/langtail-youtube-context/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"private": true,
"scripts": {
"dev": "next",
"build": "next build",
"start": "next start",
"type-check": "tsc"
},
"dependencies": {
"@hookform/resolvers": "^3.3.4",
"@prisma/client": "5.17.0",
"@radix-ui/react-icons": "^1.3.0",
"@tanstack/react-query": "^5.51.3",
"@trpc/client": "11.0.0-rc.465",
"@trpc/next": "11.0.0-rc.465",
"@trpc/react-query": "11.0.0-rc.465",
"@trpc/server": "11.0.0-rc.465",
"autoprefixer": "^10.4.19",
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.1",
"langtail": "^0.5.4",
"next": "latest",
"openai": "^4.52.7",
"postcss": "^8.4.39",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-hook-form": "^7.45.4",
"sqlite3": "^5.1.7",
"tailwind-merge": "^2.4.0",
"tailwindcss": "^3.4.6",
"tailwindcss-animate": "^1.0.7",
"youtube-dl-exec": "^3.0.6",
"zod": "^3.23.8"
},
"devDependencies": {
"@types/node": "^12.12.21",
"@types/react": "^17.0.2",
"@types/react-dom": "^17.0.1",
"prisma": "^5.17.0",
"typescript": "^4.8.3"
}
}
8 changes: 8 additions & 0 deletions examples/langtail-youtube-context/pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import type { AppType } from "next/app";
import { trpc } from "@/lib/trpc";
import "../globals.css";

const MyApp: AppType = ({ Component, pageProps }) => {
return <Component {...pageProps} />;
};
export default trpc.withTRPC(MyApp);
8 changes: 8 additions & 0 deletions examples/langtail-youtube-context/pages/api/trpc/[trpc].ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import * as trpcNext from "@trpc/server/adapters/next";
import { appRouter } from "../../../server/routers/_app";
// export API handler
// @link https://trpc.io/docs/v11/server/adapters
export default trpcNext.createNextApiHandler({
router: appRouter,
createContext: () => ({}),
});
Empty file.
Loading