diff --git a/.env.example b/.env.example index fd6aa47..c4d4268 100644 --- a/.env.example +++ b/.env.example @@ -1,2 +1,4 @@ # you can get your gemini api key from https://aistudio.google.com/app/apikey API_KEY=your_gemini_api_key_here + +VERCEL_URL="localhost:3000" diff --git a/.github/workflows/chacks.yml b/.github/workflows/chacks.yml new file mode 100644 index 0000000..d3dba69 --- /dev/null +++ b/.github/workflows/chacks.yml @@ -0,0 +1,84 @@ +name: ✨ Next.js checks + +on: + push: + branches: + - "*" + pull_request: + branches: ["*"] + +jobs: + lint: + runs-on: ubuntu-latest + name: pnpm lint + + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Install Node.js + uses: actions/setup-node@v3 + with: + node-version: 18 + + - uses: pnpm/action-setup@v2.2.4 + name: Install pnpm + id: pnpm-install + with: + version: 8.6.1 + run_install: false + + - name: Get pnpm store directory + id: pnpm-cache + run: | + echo "pnpm_cache_dir=$(pnpm store path)" >> $GITHUB_OUTPUT + - uses: actions/cache@v3 + name: Setup pnpm cache + with: + path: ${{ steps.pnpm-cache.outputs.pnpm_cache_dir }} + key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} + restore-keys: | + ${{ runner.os }}-pnpm-store- + - name: Install dependencies + run: pnpm install + + - run: pnpm run lint + + build: + runs-on: ubuntu-latest + name: pnpm build + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Install Node.js + uses: actions/setup-node@v3 + with: + node-version: 18 + + - uses: pnpm/action-setup@v2.2.4 + name: Install pnpm + id: pnpm-install + with: + version: 8.6.1 + run_install: false + + - name: Get pnpm store directory + id: pnpm-cache + run: | + echo "pnpm_cache_dir=$(pnpm store path)" >> $GITHUB_OUTPUT + + - uses: actions/cache@v3 + name: Setup pnpm cache + with: + path: ${{ steps.pnpm-cache.outputs.pnpm_cache_dir }} + key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} + restore-keys: | + ${{ runner.os }}-pnpm-store- + + - name: Install dependencies + run: pnpm install + + - run: pnpm run build diff --git a/.gitignore b/.gitignore index fd3dbb5..1d62dce 100644 --- a/.gitignore +++ b/.gitignore @@ -34,3 +34,6 @@ yarn-error.log* # typescript *.tsbuildinfo next-env.d.ts + +.vercel +.env*.local diff --git a/utils/index.ts b/utils/index.ts index 11532a2..eecec33 100644 --- a/utils/index.ts +++ b/utils/index.ts @@ -1,20 +1,30 @@ import { GoogleGenerativeAI } from "@google/generative-ai"; -import { promises as fs } from "fs"; // Get your API key from https://makersuite.google.com/app/apikey if (!process.env.API_KEY) { - throw new Error("API_KEY environment variable is required"); + console.log("API_KEY environment variable is required", process.env.NODE_ENV); + console.log("node env:- ", process.env.NODE_ENV); } -const genAI = new GoogleGenerativeAI(process.env.API_KEY); +const genAI = new GoogleGenerativeAI(process.env.API_KEY!); export const model = genAI.getGenerativeModel({ model: "gemini-pro" }); export const systemHistory = async () => { + const protocol = process.env.NODE_ENV === "production" ? "https" : "http"; - const systemdata = await fetch("http://localhost:3000/system.txt"); + console.log("protocol", protocol); + console.log("VERCEL_URL", process.env.VERCEL_URL) + + const systemdata = await fetch( + `${protocol}://${process.env.VERCEL_URL}/system.txt` + ); const systemText = await systemdata.text(); + if (systemText) { + console.log("is systemText", true); + } + return [ { role: "user",