-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgeminiConnect.py
More file actions
43 lines (31 loc) · 1.43 KB
/
geminiConnect.py
File metadata and controls
43 lines (31 loc) · 1.43 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
38
39
40
41
42
43
# TODO(developer) Vertex AI SDK - uncomment below & run
# pip3 install --upgrade --user google-cloud-aiplatform
# gcloud auth application-default login
import vertexai
from vertexai.generative_models import GenerativeModel, Part
import datetime
import glob
import os
print(datetime.datetime.now().strftime("%H:%M"))
print('1')
# Initialize Vertex AI
vertexai.init(project="lithe-optics-422207-j7", location="us-central1")
# Load the model
# multimodal_model = GenerativeModel(model_name=gemini-1.0-pro-vision-001)
multimodal_model = GenerativeModel(model_name="gemini-pro")
prompt = "Please review the following code and identify and list any errors. If errors are present, please present a corrected version of the code as well."
for i in range(5):
files = glob.glob('.\\Python Files\\*.py')
for index, filePath in enumerate(files):
if filePath.endswith('Node.py'):
continue
print(datetime.datetime.now().strftime("%H:%M"))
print(f"Processing file {index+1}/{len(files)}: {filePath}")
with open(filePath, 'r') as file:
code = file.read()
response = multimodal_model.generate_content([prompt, code])
correctionPath = './llmCorrection/python/gemini/' + os.path.basename(filePath).replace('.py', '.txt')
os.makedirs(os.path.dirname(correctionPath), exist_ok=True)
with open(correctionPath, 'a') as geminiFile:
geminiFile.write(response.text + "\n----- another analysis -----\n")
print("finished")