File tree Expand file tree Collapse file tree 1 file changed +25
-12
lines changed
Expand file tree Collapse file tree 1 file changed +25
-12
lines changed Original file line number Diff line number Diff line change @@ -46,10 +46,31 @@ for (const lang of langEntries) {
4646 }
4747 console . log ( prompt ) ;
4848
49- const result = await generateContent ( prompt . join ( "\n" ) ) ;
50- const text = result . text ;
51- if ( ! text ) {
52- throw new Error ( "AIからの応答が空でした" ) ;
49+ let text : string | undefined ;
50+ while ( true ) {
51+ if ( requestCount >= geminiMaxRequest ) {
52+ console . log (
53+ `Geminiへのリクエスト数が${ geminiMaxRequest } に達したため、処理を終了します。`
54+ ) ;
55+ process . exit ( 1 ) ;
56+ }
57+ requestCount ++ ;
58+
59+ try {
60+ const result = await generateContent ( prompt . join ( "\n" ) ) ;
61+ text = result . text ;
62+ if ( text ) {
63+ break ;
64+ } else {
65+ console . error ( "AIからの応答が空でした" ) ;
66+ await new Promise ( ( resolve ) => setTimeout ( resolve , 30000 ) ) ;
67+ continue ;
68+ }
69+ } catch ( e ) {
70+ console . error ( `Geminiへのリクエスト中にエラーが発生しました: ${ e } ` ) ;
71+ await new Promise ( ( resolve ) => setTimeout ( resolve , 30000 ) ) ;
72+ continue ;
73+ }
5374 }
5475 console . log ( text ) ;
5576
@@ -119,14 +140,6 @@ for (const lang of langEntries) {
119140 "utf-8"
120141 ) ;
121142 }
122-
123- requestCount ++ ;
124- if ( requestCount >= geminiMaxRequest ) {
125- console . log (
126- `Geminiへのリクエスト数が${ geminiMaxRequest } に達したため、処理を終了します。`
127- ) ;
128- process . exit ( 1 ) ;
129- }
130143 }
131144 }
132145}
You can’t perform that action at this time.
0 commit comments