-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtest_1.py
More file actions
31 lines (23 loc) · 935 Bytes
/
Copy pathtest_1.py
File metadata and controls
31 lines (23 loc) · 935 Bytes
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
import os
import subprocess
from openai import OpenAI
# Inicializar cliente
client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
# Listar archivos del repo
files = subprocess.check_output(["git", "ls-files"]).decode().splitlines()
for fpath in files:
if fpath.endswith(".py"): # Podés cambiar la extensión
with open(fpath, "r", encoding="utf-8") as f:
code = f.read()
print(f"\nAnalizando {fpath}...")
# <-- Definimos 'messages' antes de usarlo
messages = [
{"role": "system", "content": "Sos un experto en Python y CUDA."},
{"role": "user", "content": f"Explicá brevemente qué hace este código:\n\n{code}"}
]
# Llamada a la API usando la nueva clase OpenAI
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=messages
)
print(response.choices[0].message.content)