Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add baseUrl option to env #1

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/dist
node_modules
.env
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ Created by [@ammaar](https://x.com/ammaar)

- `GOOGLE_API_KEY`: Your Google API key with access to Gemini API
- `NODE_ENV`: Set to "development" by default, use "production" for production builds
- `BASE_URL`: Set this to your own proxied API base URL (e.g., Cloudflare AI gateway endpoint). Defaults to 'https://generativelanguage.googleapis.com'.

## Development

Expand Down
1 change: 1 addition & 0 deletions server/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export function setupEnvironment() {

return {
GOOGLE_API_KEY: process.env.GOOGLE_API_KEY,
BASE_URL: process.env.BASE_URL || "https://generativelanguage.googleapis.com",
NODE_ENV: process.env.NODE_ENV || "development",
};
}
9 changes: 5 additions & 4 deletions server/routes.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import type { Express } from "express";
import { createServer, type Server } from "http";
import {
GoogleGenerativeAI,
type ChatSession,
type GenerateContentResult,
type ChatSession
} from "@google/generative-ai";
import type { Express } from "express";
import { createServer, type Server } from "http";
import { marked } from "marked";
import { setupEnvironment } from "./env";

Expand All @@ -18,6 +17,8 @@ const model = genAI.getGenerativeModel({
topK: 1,
maxOutputTokens: 2048,
},
}, {
baseUrl: env.BASE_URL,
});

// Store chat sessions in memory
Expand Down
5 changes: 5 additions & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,9 @@ export default defineConfig({
outDir: path.resolve(__dirname, "dist/public"),
emptyOutDir: true,
},
server: {
proxy: {
"/api": "http://localhost:3000",
},
}
});