|
17 | 17 |
|
18 | 18 |
|
19 | 19 | console = Console()
|
20 |
| -version = "0.4.0" |
21 |
| -_session_file_=".messages.json" |
| 20 | +version = "0.4.1" |
| 21 | +_session_file_ = ".messages.json" |
22 | 22 |
|
23 | 23 | def get_lindata():
|
24 | 24 | lindata = "Users Kernel:" + platform.platform() + "\n" \
|
@@ -50,6 +50,54 @@ def put_session(messages):
|
50 | 50 | separators=(',', ': '), ensure_ascii=False)
|
51 | 51 | outfile.write(to_unicode(str_))
|
52 | 52 |
|
| 53 | +def read_text(url): |
| 54 | + messages = "" |
| 55 | + with open(url) as sf: |
| 56 | + for line in sf: |
| 57 | + line = line.rstrip() |
| 58 | + messages += line + ' ' |
| 59 | + return messages |
| 60 | + |
| 61 | +def stripp_it(rawt): |
| 62 | + rawt.replace('\n', ' ').replace('\r', '') |
| 63 | + rawt.replace('\t', ' ') |
| 64 | + return rawt |
| 65 | + |
| 66 | +def read_csv(url): |
| 67 | + messages = "" |
| 68 | + with open(url) as sf: |
| 69 | + for line in sf: |
| 70 | + line = line.rstrip() |
| 71 | + messages += line + '\n' |
| 72 | + return messages |
| 73 | + |
| 74 | + |
| 75 | +def read_pdf(prompt): |
| 76 | + console.log("PDF not supported yet") |
| 77 | + exit() |
| 78 | + |
| 79 | +def extract_jsonstr(prompt): |
| 80 | + file, ext = prompt.split('.') |
| 81 | + if ext == 'txt': |
| 82 | + rawt = read_text(prompt) |
| 83 | + pro = stripp_it(rawt) |
| 84 | + |
| 85 | + elif ext in ['py', 'html', 'css', 'c', 'h', 'cpp', 'hpp']: |
| 86 | + rawt = read_text(prompt) |
| 87 | + pro = stripp_it(rawt) |
| 88 | + |
| 89 | + elif ext == 'csv': |
| 90 | + rawt = read_csv(prompt) |
| 91 | + pro = stripp_it(rawt) |
| 92 | + |
| 93 | + elif ext == 'pdf': |
| 94 | + rawt = read_pdf(prompt) |
| 95 | + |
| 96 | + else: |
| 97 | + console.status("File format not supported: "+ext) |
| 98 | + exit() |
| 99 | + return pro |
| 100 | + |
53 | 101 | def main():
|
54 | 102 | desc = "This tool sends a query to OpenAIs Chat API from the command line.\n\n"\
|
55 | 103 | "A new chat session is started with -n <pre-info> and gives the opportunity to\n"\
|
@@ -82,6 +130,8 @@ def main():
|
82 | 130 | os.remove(_session_file_)
|
83 | 131 | if args.prompt:
|
84 | 132 | prompt = args.prompt
|
| 133 | + if os.path.exists(prompt): |
| 134 | + prompt = extract_jsonstr(prompt) |
85 | 135 | else:
|
86 | 136 | prompt = ""
|
87 | 137 | pprompt = f"{prompt}\n\n" \
|
|
0 commit comments