Skip to content
Merged
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
6 changes: 4 additions & 2 deletions app/actions/chatActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,10 @@ ${userQuestion}

`;
const result = await generateContent(prompt);
const response = result.response;
const text = response.text();
const text = result.text;
if (!text) {
throw new Error("AIからの応答が空でした");
}
return { response: text, error: null };
} catch (error: unknown) {
console.error("Error calling Generative AI:", error);
Expand Down
23 changes: 14 additions & 9 deletions app/actions/gemini.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
"use server";

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

export async function generateContent(prompt: string) {
const params: ModelParams = {
model: "gemini-1.5-flash",
const params = {
model: "gemini-2.5-flash",
contents: prompt,
};

const genAI = new GoogleGenerativeAI(process.env.API_KEY!);
const ai = new GoogleGenAI({ apiKey: process.env.API_KEY! });

try {
const model = genAI.getGenerativeModel(params);
return await model.generateContent(prompt);
return await ai.models.generateContent(params);
} catch (e: unknown) {
if (String(e).includes("User location is not supported")) {
const model = genAI.getGenerativeModel(params, {
baseUrl: "https://gemini-proxy.utcode.net",
// 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 model.generateContent(prompt);
return await aiWithProxy.models.generateContent(params);
} else {
throw e;
}
Expand Down
6 changes: 4 additions & 2 deletions app/actions/questionExample.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ export async function getQuestionExample(
${documentContent}
`;
const result = await generateContent(prompt);
const response = result.response;
const text = response.text();
const text = result.text;
if (!text) {
throw new Error("AIからの応答が空でした");
}
return text.trim().split("\n");
}
189 changes: 183 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"dependencies": {
"@fontsource-variable/inconsolata": "^5.2.6",
"@fontsource-variable/noto-sans-jp": "^5.2.6",
"@google/generative-ai": "^0.24.1",
"@google/genai": "^1.21.0",
"@opennextjs/cloudflare": "^1.7.1",
"@xterm/addon-fit": "^0.11.0-beta.115",
"@xterm/xterm": "^5.6.0-beta.115",
Expand Down