-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsingleshot.py
38 lines (30 loc) · 988 Bytes
/
singleshot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import openai
import os
import math
import sys
from src.openaiinteractions import OpenAIInteraction
class SingleShot(OpenAIInteraction):
def __init__(self):
super().__init__()
def run(self):
sp = ""
spf = self.config.get_system_prompt_file()
print("spf: " + str(spf))
if spf:
sp = open(spf, 'r').read()
else:
sp = input("Enter a system prompt: ")
if not sys.stdin.isatty():
up = sys.stdin.read()
else:
up = input("Enter a user prompt: ")
max_tokens = self.config.get_max_tokens()
if not max_tokens:
tokens = self.num_tokens_from_string(up)
max_tokens = int(input("How many response tokens? The provided file has " + str(tokens) + " tokens."))
print("Response:")
self.generate_response(sp, up, max_tokens=max_tokens, stream=True)
def main():
SingleShot().run()
if __name__ == "__main__":
main()