Skip to content

Commit 7a0d5c5

Browse files
authored
Add initial script, config, readme
1 parent e2fe308 commit 7a0d5c5

File tree

3 files changed

+39
-2
lines changed

3 files changed

+39
-2
lines changed

README.md

-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +0,0 @@
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.

chat.py

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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)

creds.ini

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[OPENAI]
2+
API_KEY = YOUR_API_KEY_HERE

0 commit comments

Comments
 (0)