File tree Expand file tree Collapse file tree 4 files changed +870
-1
lines changed Expand file tree Collapse file tree 4 files changed +870
-1
lines changed Original file line number Diff line number Diff line change 1+ import { Configuration , OpenAIApi } from 'openai' ;
2+ import dotenv from 'dotenv' ;
3+
4+ dotenv . config ( ) ;
5+
6+ const openaiApiKey = process . env . OPENAI_API_KEY ;
7+
8+ if ( ! openaiApiKey ) {
9+ console . error ( 'OPENAI_API_KEY is not defined in the environment variables' ) ;
10+ throw new Error ( 'OPENAI_API_KEY is not defined in the environment variables' ) ;
11+ // This will stop the execution of the script
12+ process . exit ( 1 ) ;
13+
14+ }
15+
16+ const configuration = new Configuration ( {
17+ apiKey : openaiApiKey ,
18+ } ) ;
19+ // below is the open ai api instance
20+ // The OpenAIApi class is used to interact with the OpenAI API
21+ const openai = new OpenAIApi ( configuration ) ;
22+ // Function to generate SQL query using OpenAI API
Original file line number Diff line number Diff line change 1+ import express from 'express' ;
2+ import cors from 'cors' ;
3+
4+ const app = express ( ) ;
5+
6+ app . use ( cors ( ) ) ;
7+
8+ const port = process . env . PORT || 3005 ;
9+
10+ // endpoint to test the server
11+ app . get ( "/" , ( req , res ) => {
12+ res . send ( "Server is running.Hello World from our API" ) ;
13+ } ) ;
14+
15+ // app.listen is a method that starts the server and listens for incoming requests on the specified port
16+ // The port is either taken from the environment variables or defaults to 3005
17+ // The callback function is executed when the server starts successfully
18+ app . listen ( port , ( ) => {
19+ console . log ( `Server is running on port ${ port } ` ) ;
20+ } )
You can’t perform that action at this time.
0 commit comments