File tree 3 files changed +39
-2
lines changed
3 files changed +39
-2
lines changed Original file line number Diff line number Diff line change 1
- # minimalgpt
2
- A minimal Python based GPT CLI query app to run on light hardware. Uses GPT-3.5-turbo model, written mostly by the GPT-4 model.
Original file line number Diff line number Diff line change
1
+ #!/usr/bin/env python3
2
+
3
+ import openai
4
+ import configparser
5
+ import sys
6
+ import os
7
+ import time
8
+
9
+ # Load configuration
10
+ config = configparser .ConfigParser ()
11
+ config .read ('creds.ini' )
12
+ api_key = config ['OPENAI' ]['API_KEY' ]
13
+
14
+ # Initialize OpenAI API
15
+ openai .api_key = api_key
16
+
17
+ def query_openai (query ):
18
+ try :
19
+ response = openai .ChatCompletion .create (
20
+ model = "gpt-3.5-turbo" ,
21
+ messages = [
22
+ {"role" : "system" , "content" : "You are a helpful assistant." },
23
+ {"role" : "user" , "content" : query }
24
+ ]
25
+ )
26
+ return response ['choices' ][0 ]['message' ]['content' ].strip ()
27
+ except Exception as e :
28
+ return f"Error: { e } "
29
+
30
+ if __name__ == "__main__" :
31
+ if len (sys .argv ) != 2 :
32
+ print ("Usage: chat <query>" )
33
+ sys .exit (1 )
34
+
35
+ user_query = sys .argv [1 ]
36
+ response = query_openai (user_query )
37
+ print (response )
Original file line number Diff line number Diff line change
1
+ [OPENAI]
2
+ API_KEY = YOUR_API_KEY_HERE
You can’t perform that action at this time.
0 commit comments