Skip to content

Commit a5adb46

Browse files
committed
bug fixes, global personality works
1 parent 81b4291 commit a5adb46

File tree

2 files changed

+28
-11
lines changed

2 files changed

+28
-11
lines changed

filegpt/FileGPT.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@
77
import tempfile
88

99
from openai_wrapper import get_openai_response
10-
from personalities import PERSONALITIES, get_personality
10+
from personalities import PERSONALITIES, get_personality, get_openai_personality
1111

1212
import tiktoken
1313
from typing import List
1414

15+
PERSONALITY = None
16+
1517
MODELS = [
1618
"gpt-3.5-turbo",
1719
"gpt-4"
@@ -38,7 +40,9 @@ def read_input(files: List[str] = None) -> str:
3840
content = "\n".join(contents)
3941
else:
4042
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)...")
4246
content = sys.stdin.read()
4347
return content
4448

@@ -80,7 +84,8 @@ def process_text(model_name: str, input_files: List[str] = None) -> str:
8084

8185
logging.info("Input has %d tokens", len(enc.encode(input_content)))
8286

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}])
8489
resp_str = write_output(response)
8590
logging.info("FileGPT finished, response has %d tokens", len(enc.encode(resp_str)))
8691

@@ -102,8 +107,9 @@ def main():
102107
# list available personalities
103108
print(f"Available personalities: {', '.join(PERSONALITIES)}")
104109
return
105-
106110

111+
global PERSONALITY
112+
PERSONALITY = get_personality(args.personality)
107113
process_text(args.model, args.file)
108114

109115

filegpt/personalities.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,34 @@
11
PERSONALITIES = [
2-
"python_coder",
2+
"coder",
33
]
44

55
MAP_PERSONALITY_TO_OPENAI = {
6-
"python_coder": """
6+
"coder": {"role": "system", "content": """
77
You only give your responses with python code.
88
When you need to tell the user something, use code comments.
99
1010
Example:
1111
User: What is your name?
1212
Bot: # My name is GPT-3
13-
User: Write some code to print your name
14-
Bot: print("GPT-3")
15-
"""
13+
User: Write some code that performs the fibonacci sequence
14+
Bot:
15+
# Sure! Here you go:
16+
def fibonacci(n):
17+
...
18+
19+
Do not use markdown or html in your responses.
20+
Do not wrap your response in backticks (```python)
21+
"""}
1622
}
1723

1824
def get_personality(personality: str) -> str:
1925
if personality in PERSONALITIES:
2026
return personality
2127
else:
22-
print(f"Personality {personality} not found. Available personalities: {', '.join(PERSONALITIES)}")
23-
return None
28+
return None
29+
30+
def get_openai_personality(personality: str) -> str:
31+
if personality in MAP_PERSONALITY_TO_OPENAI:
32+
return MAP_PERSONALITY_TO_OPENAI[personality]
33+
else:
34+
return None

0 commit comments

Comments
 (0)