File tree Expand file tree Collapse file tree 5 files changed +206
-20
lines changed
Expand file tree Collapse file tree 5 files changed +206
-20
lines changed Original file line number Diff line number Diff 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 ) ;
Original file line number Diff line number Diff line change 11"use server" ;
22
3- import { GoogleGenerativeAI , ModelParams } from "@google/generative-ai " ;
3+ import { GoogleGenAI } from "@google/genai " ;
44
55export async function generateContent ( prompt : string ) {
6- const params : ModelParams = {
7- model : "gemini-1.5-flash" ,
6+ const params = {
7+ model : "gemini-2.5-flash" ,
8+ contents : prompt ,
89 } ;
910
10- const genAI = new GoogleGenerativeAI ( process . env . API_KEY ! ) ;
11+ const ai = new GoogleGenAI ( { apiKey : process . env . API_KEY ! } ) ;
12+
1113 try {
12- const model = genAI . getGenerativeModel ( params ) ;
13- return await model . generateContent ( prompt ) ;
14+ return await ai . models . generateContent ( params ) ;
1415 } catch ( e : unknown ) {
1516 if ( String ( e ) . includes ( "User location is not supported" ) ) {
16- const model = genAI . getGenerativeModel ( params , {
17- baseUrl : "https://gemini-proxy.utcode.net" ,
17+ // For the new API, we can use httpOptions to set a custom baseUrl
18+ const aiWithProxy = new GoogleGenAI ( {
19+ apiKey : process . env . API_KEY ! ,
20+ httpOptions : {
21+ baseUrl : "https://gemini-proxy.utcode.net" ,
22+ } ,
1823 } ) ;
19- return await model . generateContent ( prompt ) ;
24+ return await aiWithProxy . models . generateContent ( params ) ;
2025 } else {
2126 throw e ;
2227 }
Original file line number Diff line number Diff 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}
Original file line number Diff line number Diff line change 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" ,
You can’t perform that action at this time.
0 commit comments