From 7f97987a83697f25b2f98338bcc67bfd58ea4676 Mon Sep 17 00:00:00 2001 From: ruru <142723369+ruru-m07@users.noreply.github.com> Date: Wed, 8 May 2024 16:56:35 +0530 Subject: [PATCH 1/4] feat(ci): add new workflow chacks.yml Co-Authored-By: ruru --- .github/workflows/chacks.yml | 122 +++++++++++++++++++++++++++++++++++ package.json | 4 +- pnpm-lock.yaml | 9 +++ utils/index.ts | 6 +- 4 files changed, 137 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/chacks.yml diff --git a/.github/workflows/chacks.yml b/.github/workflows/chacks.yml new file mode 100644 index 0000000..fd6ea56 --- /dev/null +++ b/.github/workflows/chacks.yml @@ -0,0 +1,122 @@ +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 + + format: + runs-on: ubuntu-latest + name: pnpm format:check + 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 format:check + + 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/package.json b/package.json index 142d950..ae3f50f 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,8 @@ "dev": "next dev", "build": "next build", "start": "next start", - "lint": "next lint" + "lint": "next lint", + "format:check": "prettier --check \"**/*.{ts,tsx,mdx}\" --cache" }, "dependencies": { "@google/generative-ai": "^0.10.0", @@ -24,6 +25,7 @@ "lucide-react": "^0.378.0", "next": "14.2.3", "next-themes": "^0.3.0", + "prettier": "^3.2.5", "react": "^18", "react-dom": "^18", "react-markdown": "^9.0.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 2b56efb..839a86a 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -50,6 +50,9 @@ dependencies: next-themes: specifier: ^0.3.0 version: 0.3.0(react-dom@18.3.1)(react@18.3.1) + prettier: + specifier: ^3.2.5 + version: 3.2.5 react: specifier: ^18 version: 18.3.1 @@ -3744,6 +3747,12 @@ packages: engines: {node: '>= 0.8.0'} dev: true + /prettier@3.2.5: + resolution: {integrity: sha512-3/GWa9aOC0YeD7LUfvOG2NiDyhOWRvt1k+rcKhOuYnMY24iiCphgneUfJDyFXd6rZCAnuLBv6UeAULtrhT/F4A==} + engines: {node: '>=14'} + hasBin: true + dev: false + /prismjs@1.27.0: resolution: {integrity: sha512-t13BGPUlFDR7wRB5kQDG4jjl7XeuH6jbJGt11JHPL96qwsEHNX2+68tFXqc1/k+/jALsbSWJKUOT/hcYAZ5LkA==} engines: {node: '>=6'} diff --git a/utils/index.ts b/utils/index.ts index 11532a2..cf41a43 100644 --- a/utils/index.ts +++ b/utils/index.ts @@ -1,12 +1,12 @@ 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" }); From 393d7469e18064c17f04dfe410e7abf2e36d7f4e Mon Sep 17 00:00:00 2001 From: ruru <142723369+ruru-m07@users.noreply.github.com> Date: Wed, 8 May 2024 17:26:00 +0530 Subject: [PATCH 2/4] fix(ci): format check Co-Authored-By: ruru --- .github/workflows/chacks.yml | 38 ------------------------------------ package.json | 1 - pnpm-lock.yaml | 9 --------- 3 files changed, 48 deletions(-) diff --git a/.github/workflows/chacks.yml b/.github/workflows/chacks.yml index fd6ea56..d3dba69 100644 --- a/.github/workflows/chacks.yml +++ b/.github/workflows/chacks.yml @@ -45,44 +45,6 @@ jobs: - run: pnpm run lint - format: - runs-on: ubuntu-latest - name: pnpm format:check - 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 format:check - build: runs-on: ubuntu-latest name: pnpm build diff --git a/package.json b/package.json index ae3f50f..1510358 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,6 @@ "lucide-react": "^0.378.0", "next": "14.2.3", "next-themes": "^0.3.0", - "prettier": "^3.2.5", "react": "^18", "react-dom": "^18", "react-markdown": "^9.0.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 839a86a..2b56efb 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -50,9 +50,6 @@ dependencies: next-themes: specifier: ^0.3.0 version: 0.3.0(react-dom@18.3.1)(react@18.3.1) - prettier: - specifier: ^3.2.5 - version: 3.2.5 react: specifier: ^18 version: 18.3.1 @@ -3747,12 +3744,6 @@ packages: engines: {node: '>= 0.8.0'} dev: true - /prettier@3.2.5: - resolution: {integrity: sha512-3/GWa9aOC0YeD7LUfvOG2NiDyhOWRvt1k+rcKhOuYnMY24iiCphgneUfJDyFXd6rZCAnuLBv6UeAULtrhT/F4A==} - engines: {node: '>=14'} - hasBin: true - dev: false - /prismjs@1.27.0: resolution: {integrity: sha512-t13BGPUlFDR7wRB5kQDG4jjl7XeuH6jbJGt11JHPL96qwsEHNX2+68tFXqc1/k+/jALsbSWJKUOT/hcYAZ5LkA==} engines: {node: '>=6'} From 7e65080e6780010642e58268ee04ec2a5fdaf5e5 Mon Sep 17 00:00:00 2001 From: ruru <142723369+ruru-m07@users.noreply.github.com> Date: Wed, 8 May 2024 17:46:27 +0530 Subject: [PATCH 3/4] fix: systemText fetching issue Co-Authored-By: ruru --- .env.example | 2 ++ .gitignore | 3 +++ utils/index.ts | 12 +++++++++++- 3 files changed, 16 insertions(+), 1 deletion(-) 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/.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 cf41a43..eecec33 100644 --- a/utils/index.ts +++ b/utils/index.ts @@ -11,10 +11,20 @@ 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", From 68387dc53bebf35358e46ac83038e405fe832283 Mon Sep 17 00:00:00 2001 From: ruru <142723369+ruru-m07@users.noreply.github.com> Date: Wed, 8 May 2024 17:51:54 +0530 Subject: [PATCH 4/4] fix(scripts): remove unused script "format:check" Co-Authored-By: ruru --- package.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/package.json b/package.json index 1510358..142d950 100644 --- a/package.json +++ b/package.json @@ -6,8 +6,7 @@ "dev": "next dev", "build": "next build", "start": "next start", - "lint": "next lint", - "format:check": "prettier --check \"**/*.{ts,tsx,mdx}\" --cache" + "lint": "next lint" }, "dependencies": { "@google/generative-ai": "^0.10.0",