1- import { Configuration , OpenAIApi } from 'openai' ;
21import Natural from 'natural' ;
2+ import { Configuration , OpenAIApi } from 'openai' ;
33
44const configuration = new Configuration ( {
55 apiKey : process . env . OPENAI_API_KEY ,
@@ -15,13 +15,13 @@ const BANNED_PATTERNS = /[`\[\]{}\(\)]|http/g;
1515const getRandomInt = ( len : number ) => Math . floor ( Math . random ( ) * len ) ;
1616
1717interface KocopolyGenerator {
18- ( username : string , question : string , kocopolyJson : string [ ] , kocopolyName : string ) : Promise <
19- string [ ]
20- > ;
18+ ( username : string , question : string , kocopolyJson : readonly string [ ] , kocopolyName : string ) :
19+ | readonly string [ ]
20+ | Promise < readonly string [ ] > ;
2121}
2222
2323// random
24- export const getRandomKocopolyAnswers : KocopolyGenerator = async (
24+ export const getRandomKocopolyAnswers : KocopolyGenerator = (
2525 _username ,
2626 question ,
2727 kocopolyJson ,
@@ -43,6 +43,7 @@ export const getRandomKocopolyAnswers: KocopolyGenerator = async (
4343 const lines = [ ] ;
4444 let idx = initialIndex === - 1 ? getRandomInt ( g . length ) : initialIndex ;
4545
46+ // eslint-disable-next-line functional/no-loop-statement
4647 for ( let i = 0 ; i < numberOfLines ; ++ i ) {
4748 lines . push ( g [ idx ] ) ;
4849
@@ -63,7 +64,7 @@ export const getKocopolyAnswerFromOpenAI: KocopolyGenerator = async (
6364 kocopolyJson ,
6465 kocopolyName ,
6566) => {
66- const prompt = await generateKocopolyPrompt ( username , question , kocopolyJson , kocopolyName ) ;
67+ const prompt = generateKocopolyPrompt ( username , question , kocopolyJson , kocopolyName ) ;
6768
6869 const engine = 'text-davinci-001' ;
6970 // const engine = 'text-babbage-001';
@@ -94,14 +95,15 @@ export const getKocopolyAnswerFromOpenAI: KocopolyGenerator = async (
9495
9596const getRandomIndices = ( num : number , max : number ) => {
9697 const set = new Set < number > ( ) ;
98+ // eslint-disable-next-line functional/no-loop-statement
9799 while ( set . size < num ) set . add ( getRandomInt ( max ) ) ;
98100 return [ ...set ] ;
99101} ;
100102
101- const generateKocopolyPrompt = async (
103+ const generateKocopolyPrompt = (
102104 username : string ,
103105 question : string ,
104- kocopolyJson : string [ ] ,
106+ kocopolyJson : readonly string [ ] ,
105107 kocopolyName : string ,
106108) => {
107109 const indices = getRandomIndices ( 100 , kocopolyJson . length ) ;
0 commit comments