7
7
import tempfile
8
8
9
9
from openai_wrapper import get_openai_response
10
- from personalities import PERSONALITIES , get_personality
10
+ from personalities import PERSONALITIES , get_personality , get_openai_personality
11
11
12
12
import tiktoken
13
13
from typing import List
14
14
15
+ PERSONALITY = None
16
+
15
17
MODELS = [
16
18
"gpt-3.5-turbo" ,
17
19
"gpt-4"
@@ -38,7 +40,9 @@ def read_input(files: List[str] = None) -> str:
38
40
content = "\n " .join (contents )
39
41
else :
40
42
logging .info ("Reading input from stdin" )
41
- print ("Reading from stdin (press CTRL+D for linux/mac or Enter+CTRL+Z+Enter for windows to stop)..." )
43
+ if os .isatty (sys .stdin .fileno ()):
44
+ print ("Current personality:" , get_personality (PERSONALITY ))
45
+ print ("Reading from stdin (press CTRL+D for linux/mac or Enter+CTRL+Z+Enter for windows to stop)..." )
42
46
content = sys .stdin .read ()
43
47
return content
44
48
@@ -80,7 +84,8 @@ def process_text(model_name: str, input_files: List[str] = None) -> str:
80
84
81
85
logging .info ("Input has %d tokens" , len (enc .encode (input_content )))
82
86
83
- response = get_openai_response (model_name , [{"role" : "user" , "content" : input_content }])
87
+ print (get_openai_personality (PERSONALITY ))
88
+ response = get_openai_response (model_name , [get_openai_personality (PERSONALITY ), {"role" : "user" , "content" : input_content }])
84
89
resp_str = write_output (response )
85
90
logging .info ("FileGPT finished, response has %d tokens" , len (enc .encode (resp_str )))
86
91
@@ -102,8 +107,9 @@ def main():
102
107
# list available personalities
103
108
print (f"Available personalities: { ', ' .join (PERSONALITIES )} " )
104
109
return
105
-
106
110
111
+ global PERSONALITY
112
+ PERSONALITY = get_personality (args .personality )
107
113
process_text (args .model , args .file )
108
114
109
115
0 commit comments