File size: 1,098 Bytes
77f290b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
eac755c
77f290b
 
 
 
 
eac755c
77f290b
 
 
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
from .utils import log, model_predict
import re

def evaluate(verbose, llm, zip, readme):
  log(verbose, "LOG", "\nEvaluating repository licensing...")
  overall = "No"
  license_files = [license for license in zip.namelist() if ((("LICENSE" in license) | ("license" in license)) & (len(license.split("/")) == 2))]
  if (len(license_files) > 0):
      license = zip.open(license_files[0]).read().decode("utf-8")
      ans = [row for row in license.split("\n") if row != ""]

      if (llm):
          license = license[:50]
          prompt = f"Q: {license}. This was an excerpt from a license \
          file. Do you know the name of this license?"
          ans = model_predict(prompt)
          log(verbose, "LOG", f"Found license: {ans}")
      else:
          log(verbose, "LOG", f"Found license file: {license_files[0]}")

      overall = "Yes"
      return overall

  if (readme):
      if ("License" in readme):
          log(verbose, "LOG", "License found in README.")
          overall = "Yes"
          return overall

  log(verbose, "ERROR", "LICENSE file not found.")
  return overall