-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgemini.ts
More file actions
29 lines (25 loc) · 768 Bytes
/
gemini.ts
File metadata and controls
29 lines (25 loc) · 768 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
"use server";
import { GoogleGenAI } from "@google/genai";
export async function generateContent(prompt: string) {
const params = {
model: "gemini-2.5-flash",
contents: prompt,
};
const ai = new GoogleGenAI({ apiKey: process.env.API_KEY! });
try {
return await ai.models.generateContent(params);
} catch (e: unknown) {
if (String(e).includes("User location is not supported")) {
// For the new API, we can use httpOptions to set a custom baseUrl
const aiWithProxy = new GoogleGenAI({
apiKey: process.env.API_KEY!,
httpOptions: {
baseUrl: "https://gemini-proxy.utcode.net",
},
});
return await aiWithProxy.models.generateContent(params);
} else {
throw e;
}
}
}