-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathmain.py
More file actions
37 lines (30 loc) · 1.24 KB
/
Copy pathmain.py
File metadata and controls
37 lines (30 loc) · 1.24 KB
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
import argparse
import google.generativeai as palm
def get_fix(path, apikey):
# required prompt
prompt = '''
You are an expert at analyzing logs.
You have to summarize the content of the log content given to you and
suggest ways to fix errors if possible. Ignore any warnings
that you see. If the file is not a typical log file or if the file is
a program file in any programming language then inform the user
that the file provided was not a log file.
'''
palm.configure(api_key=apikey)
models = [m for m in palm.list_models() if 'generateText' in m.supported_generation_methods]
model = models[0].name
try:
with open(path, 'r') as file:
prompt += "\nAnalyze the following content:\n" + file.read()
file.close()
ans = palm.generate_text(model=model, prompt=prompt,
temperature=0, max_output_tokens=800)
print(ans.candidates[0]['output'])
except FileNotFoundError:
print("Unable to find specified file. Use pwd for referrence.")
parser = argparse.ArgumentParser(description="Get file name")
parser.add_argument('filename')
parser.add_argument('apikey')
# Arguments
args = parser.parse_args()
get_fix(args.filename, args.apikey)