Skip to content

Commit c998b49

Browse files
Copilotna-trium-144
andcommitted
Migrate from deprecated packages to current ones
Co-authored-by: na-trium-144 <[email protected]>
1 parent 6c9d079 commit c998b49

File tree

5 files changed

+209
-22
lines changed

5 files changed

+209
-22
lines changed

app/actions/chatActions.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,10 @@ ${userQuestion}
4747
4848
`;
4949
const result = await generateContent(prompt);
50-
const response = result.response;
51-
const text = response.text();
50+
const text = result.text;
51+
if (!text) {
52+
throw new Error("AIからの応答が空でした");
53+
}
5254
return { response: text, error: null };
5355
} catch (error: unknown) {
5456
console.error("Error calling Generative AI:", error);

app/actions/gemini.ts

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,28 @@
11
"use server";
22

3-
import { GoogleGenerativeAI, ModelParams } from "@google/generative-ai";
3+
import { GoogleGenAI } from "@google/genai";
44

55
export async function generateContent(prompt: string) {
6-
const params: ModelParams = {
7-
model: "gemini-1.5-flash",
8-
};
9-
10-
const genAI = new GoogleGenerativeAI(process.env.API_KEY!);
6+
const ai = new GoogleGenAI({ apiKey: process.env.API_KEY! });
7+
118
try {
12-
const model = genAI.getGenerativeModel(params);
13-
return await model.generateContent(prompt);
9+
return await ai.models.generateContent({
10+
model: "gemini-2.5-flash",
11+
contents: prompt,
12+
});
1413
} catch (e: unknown) {
1514
if (String(e).includes("User location is not supported")) {
16-
const model = genAI.getGenerativeModel(params, {
17-
baseUrl: "https://gemini-proxy.utcode.net",
15+
// For the new API, we can use httpOptions to set a custom baseUrl
16+
const aiWithProxy = new GoogleGenAI({
17+
apiKey: process.env.API_KEY!,
18+
httpOptions: {
19+
baseUrl: "https://gemini-proxy.utcode.net",
20+
},
21+
});
22+
return await aiWithProxy.models.generateContent({
23+
model: "gemini-2.5-flash",
24+
contents: prompt,
1825
});
19-
return await model.generateContent(prompt);
2026
} else {
2127
throw e;
2228
}

app/actions/questionExample.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ export async function getQuestionExample(
3434
${documentContent}
3535
`;
3636
const result = await generateContent(prompt);
37-
const response = result.response;
38-
const text = response.text();
37+
const text = result.text;
38+
if (!text) {
39+
throw new Error("AIからの応答が空でした");
40+
}
3941
return text.trim().split("\n");
4042
}

package-lock.json

Lines changed: 183 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"dependencies": {
1717
"@fontsource-variable/inconsolata": "^5.2.6",
1818
"@fontsource-variable/noto-sans-jp": "^5.2.6",
19-
"@google/generative-ai": "^0.24.1",
19+
"@google/genai": "^1.21.0",
2020
"@opennextjs/cloudflare": "^1.7.1",
2121
"@xterm/addon-fit": "^0.11.0-beta.115",
2222
"@xterm/xterm": "^5.6.0-beta.115",

0 commit comments

Comments
 (0)