From bde4d5bafcb284c726552e8ffb5408fdf296239a Mon Sep 17 00:00:00 2001 From: Jason Ross Date: Fri, 29 Nov 2024 12:07:34 -0600 Subject: [PATCH] * Updated tsconfig options to nodenext module resolution to resolve module not found error * Created .npmrc and .nvmrc files. Set .nvmrc file to Node 22, currently the latest LTS ver * Created envConfig util for importing API key from local env file. --- .npmrc | 0 .nvmrc | 1 + node_modules/.modules.yaml | 10 +-------- node_modules/.pnpm/lock.yaml | 41 +++--------------------------------- package.json | 10 ++++++--- pnpm-lock.yaml | 41 +++--------------------------------- src/envConfig.ts | 7 ++++++ src/index.ts | 7 ++++-- tsconfig.json | 13 ++++++------ 9 files changed, 34 insertions(+), 96 deletions(-) create mode 100644 .npmrc create mode 100644 .nvmrc create mode 100644 src/envConfig.ts diff --git a/.npmrc b/.npmrc new file mode 100644 index 0000000..e69de29 diff --git a/.nvmrc b/.nvmrc new file mode 100644 index 0000000..5ef1a0c --- /dev/null +++ b/.nvmrc @@ -0,0 +1 @@ +22.* \ No newline at end of file diff --git a/node_modules/.modules.yaml b/node_modules/.modules.yaml index 989fa2f..c7cc9af 100644 --- a/node_modules/.modules.yaml +++ b/node_modules/.modules.yaml @@ -19,8 +19,6 @@ hoistedDependencies: '@inquirer/number': private '@inquirer/password@4.0.2(@types/node@22.10.1)': '@inquirer/password': private - '@inquirer/prompts@7.1.0(@types/node@22.10.1)': - '@inquirer/prompts': private '@inquirer/rawlist@4.0.2(@types/node@22.10.1)': '@inquirer/rawlist': private '@inquirer/search@3.0.2(@types/node@22.10.1)': @@ -55,10 +53,6 @@ hoistedDependencies: mute-stream: private os-tmpdir@1.0.2: os-tmpdir: private - run-async@3.0.0: - run-async: private - rxjs@7.8.1: - rxjs: private safer-buffer@2.1.2: safer-buffer: private signal-exit@4.1.0: @@ -69,8 +63,6 @@ hoistedDependencies: strip-ansi: private tmp@0.0.33: tmp: private - tslib@2.8.1: - tslib: private type-fest@0.21.3: type-fest: private undici-types@6.20.0: @@ -88,7 +80,7 @@ layoutVersion: 5 nodeLinker: isolated packageManager: pnpm@9.2.0 pendingBuilds: [] -prunedAt: Thu, 28 Nov 2024 17:36:55 GMT +prunedAt: Fri, 29 Nov 2024 17:52:13 GMT publicHoistPattern: - '*eslint*' - '*prettier*' diff --git a/node_modules/.pnpm/lock.yaml b/node_modules/.pnpm/lock.yaml index 5402674..75c722b 100644 --- a/node_modules/.pnpm/lock.yaml +++ b/node_modules/.pnpm/lock.yaml @@ -11,12 +11,12 @@ importers: '@google/generative-ai': specifier: ^0.21.0 version: 0.21.0 + '@inquirer/prompts': + specifier: ^7.1.0 + version: 7.1.0(@types/node@22.10.1) dotenv: specifier: ^16.4.5 version: 16.4.5 - inquirer: - specifier: ^12.1.0 - version: 12.1.0(@types/node@22.10.1) devDependencies: '@types/node': specifier: ^22.10.1 @@ -162,12 +162,6 @@ packages: resolution: {integrity: sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==} engines: {node: '>=0.10.0'} - inquirer@12.1.0: - resolution: {integrity: sha512-3/iexk64jn3EF0tjWYfOJi/DNWtcSSwg4ER67cnopO2xlCTUQjFCTMH9NBNQAMO/+dC3sEvKJtGJsqXnCkSsFg==} - engines: {node: '>=18'} - peerDependencies: - '@types/node': '>=18' - is-fullwidth-code-point@3.0.0: resolution: {integrity: sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==} engines: {node: '>=8'} @@ -180,13 +174,6 @@ packages: resolution: {integrity: sha512-D2FR03Vir7FIu45XBY20mTb+/ZSWB00sjU9jdQXt83gDrI4Ztz5Fs7/yy74g2N5SVQY4xY1qDr4rNddwYRVX0g==} engines: {node: '>=0.10.0'} - run-async@3.0.0: - resolution: {integrity: sha512-540WwVDOMxA6dN6We19EcT9sc3hkXPw5mzRNGM3FkdN/vtE9NFvj5lFAPNwUDmJjXidm3v7TC1cTE7t17Ulm1Q==} - engines: {node: '>=0.12.0'} - - rxjs@7.8.1: - resolution: {integrity: sha512-AA3TVj+0A2iuIoQkWEK/tqFjBq2j+6PO6Y0zJcvzLAFhEFIO3HL0vls9hWLncZbAAbK0mar7oZ4V079I/qPMxg==} - safer-buffer@2.1.2: resolution: {integrity: sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==} @@ -206,9 +193,6 @@ packages: resolution: {integrity: sha512-jRCJlojKnZ3addtTOjdIqoRuPEKBvNXcGYqzO6zWZX8KfKEpnGY5jfggJQ3EjKuu8D4bJRr0y+cYJFmYbImXGw==} engines: {node: '>=0.6.0'} - tslib@2.8.1: - resolution: {integrity: sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==} - type-fest@0.21.3: resolution: {integrity: sha512-t0rzBq87m3fVcduHDUFhKmyyX+9eo6WQjZvf51Ea/M0Q7+T374Jp1aUiyUl0GKxp8M/OETVHSDvmkyPgvX+X2w==} engines: {node: '>=10'} @@ -379,29 +363,12 @@ snapshots: dependencies: safer-buffer: 2.1.2 - inquirer@12.1.0(@types/node@22.10.1): - dependencies: - '@inquirer/core': 10.1.0(@types/node@22.10.1) - '@inquirer/prompts': 7.1.0(@types/node@22.10.1) - '@inquirer/type': 3.0.1(@types/node@22.10.1) - '@types/node': 22.10.1 - ansi-escapes: 4.3.2 - mute-stream: 2.0.0 - run-async: 3.0.0 - rxjs: 7.8.1 - is-fullwidth-code-point@3.0.0: {} mute-stream@2.0.0: {} os-tmpdir@1.0.2: {} - run-async@3.0.0: {} - - rxjs@7.8.1: - dependencies: - tslib: 2.8.1 - safer-buffer@2.1.2: {} signal-exit@4.1.0: {} @@ -420,8 +387,6 @@ snapshots: dependencies: os-tmpdir: 1.0.2 - tslib@2.8.1: {} - type-fest@0.21.3: {} typescript@5.7.2: {} diff --git a/package.json b/package.json index f812207..1da44ec 100644 --- a/package.json +++ b/package.json @@ -7,12 +7,16 @@ "packageManager": "pnpm@9.2.0+sha1.886364ebd6dae009284bebc56ed4296bb6dd557a", "dependencies": { "@google/generative-ai": "^0.21.0", - "dotenv": "^16.4.5", - "inquirer": "^12.1.0" + "@inquirer/prompts": "^7.1.0", + "dotenv": "^16.4.5" }, "type": "module", "scripts": { - "start": "tsc", + "transpile": "tsc", "build": "tsc --build && node dist/index.js" + }, + "engines": { + "pnpm": "^9.2.0", + "node": "22" } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 5402674..75c722b 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -11,12 +11,12 @@ importers: '@google/generative-ai': specifier: ^0.21.0 version: 0.21.0 + '@inquirer/prompts': + specifier: ^7.1.0 + version: 7.1.0(@types/node@22.10.1) dotenv: specifier: ^16.4.5 version: 16.4.5 - inquirer: - specifier: ^12.1.0 - version: 12.1.0(@types/node@22.10.1) devDependencies: '@types/node': specifier: ^22.10.1 @@ -162,12 +162,6 @@ packages: resolution: {integrity: sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==} engines: {node: '>=0.10.0'} - inquirer@12.1.0: - resolution: {integrity: sha512-3/iexk64jn3EF0tjWYfOJi/DNWtcSSwg4ER67cnopO2xlCTUQjFCTMH9NBNQAMO/+dC3sEvKJtGJsqXnCkSsFg==} - engines: {node: '>=18'} - peerDependencies: - '@types/node': '>=18' - is-fullwidth-code-point@3.0.0: resolution: {integrity: sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==} engines: {node: '>=8'} @@ -180,13 +174,6 @@ packages: resolution: {integrity: sha512-D2FR03Vir7FIu45XBY20mTb+/ZSWB00sjU9jdQXt83gDrI4Ztz5Fs7/yy74g2N5SVQY4xY1qDr4rNddwYRVX0g==} engines: {node: '>=0.10.0'} - run-async@3.0.0: - resolution: {integrity: sha512-540WwVDOMxA6dN6We19EcT9sc3hkXPw5mzRNGM3FkdN/vtE9NFvj5lFAPNwUDmJjXidm3v7TC1cTE7t17Ulm1Q==} - engines: {node: '>=0.12.0'} - - rxjs@7.8.1: - resolution: {integrity: sha512-AA3TVj+0A2iuIoQkWEK/tqFjBq2j+6PO6Y0zJcvzLAFhEFIO3HL0vls9hWLncZbAAbK0mar7oZ4V079I/qPMxg==} - safer-buffer@2.1.2: resolution: {integrity: sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==} @@ -206,9 +193,6 @@ packages: resolution: {integrity: sha512-jRCJlojKnZ3addtTOjdIqoRuPEKBvNXcGYqzO6zWZX8KfKEpnGY5jfggJQ3EjKuu8D4bJRr0y+cYJFmYbImXGw==} engines: {node: '>=0.6.0'} - tslib@2.8.1: - resolution: {integrity: sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==} - type-fest@0.21.3: resolution: {integrity: sha512-t0rzBq87m3fVcduHDUFhKmyyX+9eo6WQjZvf51Ea/M0Q7+T374Jp1aUiyUl0GKxp8M/OETVHSDvmkyPgvX+X2w==} engines: {node: '>=10'} @@ -379,29 +363,12 @@ snapshots: dependencies: safer-buffer: 2.1.2 - inquirer@12.1.0(@types/node@22.10.1): - dependencies: - '@inquirer/core': 10.1.0(@types/node@22.10.1) - '@inquirer/prompts': 7.1.0(@types/node@22.10.1) - '@inquirer/type': 3.0.1(@types/node@22.10.1) - '@types/node': 22.10.1 - ansi-escapes: 4.3.2 - mute-stream: 2.0.0 - run-async: 3.0.0 - rxjs: 7.8.1 - is-fullwidth-code-point@3.0.0: {} mute-stream@2.0.0: {} os-tmpdir@1.0.2: {} - run-async@3.0.0: {} - - rxjs@7.8.1: - dependencies: - tslib: 2.8.1 - safer-buffer@2.1.2: {} signal-exit@4.1.0: {} @@ -420,8 +387,6 @@ snapshots: dependencies: os-tmpdir: 1.0.2 - tslib@2.8.1: {} - type-fest@0.21.3: {} typescript@5.7.2: {} diff --git a/src/envConfig.ts b/src/envConfig.ts new file mode 100644 index 0000000..b3d93db --- /dev/null +++ b/src/envConfig.ts @@ -0,0 +1,7 @@ +import { config } from 'dotenv'; + +export function envConfig() { + // Load environment variables from multiple .env files + config({ path: '.env.local' }); + config({ path: '.env' }); +} \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index 5c5e192..cd2a7d4 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,18 +1,21 @@ import { GoogleGenerativeAI } from "@google/generative-ai"; -import 'dotenv/config'; +import { input } from '@inquirer/prompts'; +import { envConfig } from './envConfig.js'; export async function geminiClient() { + envConfig(); const genAI = new GoogleGenerativeAI(process.env.API_KEY as string); const model = genAI.getGenerativeModel({ model: "gemini-1.5-pro" }); - const prompt = ``; + const prompt = await input({ message: "Enter your prompt", required: true }); const result = await model.generateContent(prompt); const modelResponse = result.response.text(); return modelResponse; } + const query = await geminiClient() console.log(query); \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index d5254b2..ccb465e 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -8,9 +8,9 @@ "lib": [ "es2022" ], - "module": "ES2022", + "module": "NodeNext", "preserveConstEnums": true, - "moduleResolution": "bundler", + "moduleResolution": "nodenext", "strict": true, "sourceMap": true, "target": "es2022", @@ -21,8 +21,9 @@ }, "exclude": [ "node_modules" - ], - "files": [ - "src/index.ts" - ], + ], + "include": [ + "src" + ] + } \ No newline at end of file