Skip to content

Commit

Permalink
Fix env vars
Browse files Browse the repository at this point in the history
  • Loading branch information
lucas-janon committed Jul 30, 2024
1 parent 868a75d commit 4b604e5
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 6 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
"@t3-oss/env-nextjs": "0.7.1",
"@tailwindcss/line-clamp": "0.4.4",
"@types/react-syntax-highlighter": "15.5.13",
"@upstash/ratelimit": "2.0.1",
"@vercel/kv": "2.0.0",
"@zetachain/addresses": "0.0.13",
"@zetachain/toolkit": "^10.0.0",
"@zetachain/ui-toolkit": "1.0.3",
Expand Down
10 changes: 9 additions & 1 deletion src/app/api/chat/route.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/* eslint-disable no-console */
import { openai } from "@ai-sdk/openai";
import { Ratelimit } from "@upstash/ratelimit";
import kv from "@vercel/kv";
import { CoreMessage, embed, streamText } from "ai";

import { supabaseClient } from "~/lib/supabase/client";
Expand All @@ -20,10 +22,16 @@ const getPrompt = (userPrompt: string, pageSections: any[] | null) => {

// Allow streaming responses up to 45 seconds
export const maxDuration = 45;
export const runtime = "edge";

const ratelimit = new Ratelimit({
redis: kv,
limiter: Ratelimit.fixedWindow(5, "30s"),
});

export async function POST(req: Request) {
try {
const ip = req.ip ?? "ip";
const { success, remaining } = await ratelimit.limit(ip);
const { messages: _messages } = await req.json();
const messages = _messages as CoreMessage[];

Expand Down
7 changes: 2 additions & 5 deletions src/lib/generate-embeddings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,8 @@ import { u } from "unist-builder";
import { filter } from "unist-util-filter";
import yargs from "yargs";

if (process.env.NODE_ENV === "production") {
dotenv.config({ path: path.join(__dirname, "../../.vercel/.env.production.local") });
} else {
dotenv.config({ path: path.join(__dirname, "../../.env.local") });
}
dotenv.config({ path: path.join(__dirname, "../../.vercel/.env.production.local") });
dotenv.config({ path: path.join(__dirname, "../../.env.local") });

const ignoredFiles = ["pages/404.mdx"];

Expand Down
33 changes: 33 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5238,6 +5238,34 @@
"@uniswap/lib" "1.1.1"
"@uniswap/v2-core" "1.0.0"

"@upstash/core-analytics@^0.0.10":
version "0.0.10"
resolved "https://registry.yarnpkg.com/@upstash/core-analytics/-/core-analytics-0.0.10.tgz#e686a313ec2279d5a8d53e6c215085f1c0f5ab4b"
integrity sha512-7qJHGxpQgQr9/vmeS1PktEwvNAF7TI4iJDi8Pu2CFZ9YUGHZH4fOP5TfYlZ4aVxfopnELiE4BS4FBjyK7V1/xQ==
dependencies:
"@upstash/redis" "^1.28.3"

"@upstash/[email protected]":
version "2.0.1"
resolved "https://registry.yarnpkg.com/@upstash/ratelimit/-/ratelimit-2.0.1.tgz#ff617e31f46755ab71b1a6b68ac8a8f86171d736"
integrity sha512-J+0hlkvWUjlVrjcBQhWx7gbaUGsvFF59i+GAx7YQk8L0E0MQ93xzCPu02uaXhGDJGkxiar7nRRPqj3hs+CdAJg==
dependencies:
"@upstash/core-analytics" "^0.0.10"

"@upstash/redis@^1.28.3", "@upstash/redis@^1.31.3":
version "1.34.0"
resolved "https://registry.yarnpkg.com/@upstash/redis/-/redis-1.34.0.tgz#f32cd53ebeeafbba7eca10f8597a573d5a2fed0d"
integrity sha512-TrXNoJLkysIl8SBc4u9bNnyoFYoILpCcFJcLyWCccb/QSUmaVKdvY0m5diZqc3btExsapcMbaw/s/wh9Sf1pJw==
dependencies:
crypto-js "^4.2.0"

"@vercel/[email protected]":
version "2.0.0"
resolved "https://registry.yarnpkg.com/@vercel/kv/-/kv-2.0.0.tgz#a0baa12563946cb35cee23d638b68f0fbbf76172"
integrity sha512-zdVrhbzZBYo5d1Hfn4bKtqCeKf0FuzW8rSHauzQVMUgv1+1JOwof2mWcBuI+YMJy8s0G0oqAUfQ7HgUDzb8EbA==
dependencies:
"@upstash/redis" "^1.31.3"

"@xobotyi/scrollbar-width@^1.9.5":
version "1.9.5"
resolved "https://registry.yarnpkg.com/@xobotyi/scrollbar-width/-/scrollbar-width-1.9.5.tgz#80224a6919272f405b87913ca13b92929bdf3c4d"
Expand Down Expand Up @@ -6524,6 +6552,11 @@ cross-spawn@^7.0.0, cross-spawn@^7.0.2, cross-spawn@^7.0.3:
shebang-command "^2.0.0"
which "^2.0.1"

crypto-js@^4.2.0:
version "4.2.0"
resolved "https://registry.yarnpkg.com/crypto-js/-/crypto-js-4.2.0.tgz#4d931639ecdfd12ff80e8186dba6af2c2e856631"
integrity sha512-KALDyEYgpY+Rlob/iriUtjV6d5Eq+Y191A5g4UqLAi8CyGP9N1+FdVbkc1SxKc2r4YAYqG8JzO2KGL+AizD70Q==

css-in-js-utils@^3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/css-in-js-utils/-/css-in-js-utils-3.1.0.tgz#640ae6a33646d401fc720c54fc61c42cd76ae2bb"
Expand Down

0 comments on commit 4b604e5

Please sign in to comment.