1
1
import { OpenAI } from "openai" ;
2
2
import readline from "readline" ;
3
3
4
+ // User input
4
5
const rl = readline . createInterface ( {
5
6
input : process . stdin ,
6
7
output : process . stdout
@@ -14,48 +15,38 @@ const question = (query) => {
14
15
} ) ;
15
16
} ;
16
17
17
- const height = await question ( "Enter the current height above the ground in meters:" ) ;
18
+ async function main ( ) {
19
+ const userPrompt = await question ( "Enter your prompt: " ) ;
18
20
19
- const speed = await question ( "Enter the speed at which you're moving forward in meters per second:" ) ;
21
+ const messages = [
22
+ {
23
+ role : "user" ,
24
+ content : userPrompt
25
+ }
26
+ ] ;
20
27
21
- const gravity = await question ( "Enter the gravity in meters per second squared:" ) ;
22
-
23
- const wind = await question ( "Enter the wind speed upwards in meters per second:" ) ;
24
-
25
- // Distance to the hill
26
- const distance = 100 ;
27
-
28
- // Create prompt including inputs should include chain of thought
29
-
30
- const prompt = "TODO" ;
31
-
32
- // Call the language model with the prompt
33
-
34
- const messages = [
35
- {
36
- "role" : "user" ,
37
- "content" : prompt
38
- } ] ;
39
-
40
- // 2. Create client
41
- // -----------------------------------
42
-
43
- const openai = new OpenAI ( {
44
- baseURL : "https://models.inference.ai.azure.com" ,
45
- apiKey : process . env . GITHUB_TOKEN ,
46
- } ) ;
47
-
48
- // 3. Send the request
49
- // -----------------------------------
28
+ // OpenAI API setup
29
+ const openai = new OpenAI ( {
30
+ baseURL : "https://models.inference.ai.azure.com" ,
31
+ apiKey : process . env . GITHUB_TOKEN ,
32
+ } ) ;
50
33
51
- const completion = await openai . chat . completions . create ( {
34
+ const completion = await openai . chat . completions . create ( {
52
35
model : 'gpt-4o-mini' ,
53
36
messages : messages ,
54
- } ) ;
37
+ } ) ;
38
+
39
+ const answer = completion . choices [ 0 ] ?. message ?. content ;
40
+
41
+ console . log ( `\nAI Response:\n` ) ;
42
+ console . log ( answer ) ;
55
43
56
- console . log ( `Answer for "${ prompt } ":` ) ;
44
+ // Easter Egg Check
45
+ if ( userPrompt . toLowerCase ( ) . includes ( "time-traveling javascript developer" ) && answer ) {
46
+ console . log ( "\n Easter Egg Unlocked! You discovered the hidden poem! " ) ;
47
+ }
57
48
58
- // 4. Print the answer
59
- // -----------------------------------
49
+ rl . close ( ) ;
50
+ }
60
51
61
- console . log ( completion . choices [ 0 ] ?. message ?. content ) ;
52
+ main ( ) ;
0 commit comments