<commit_before>import sys
import requests
from requests.packages.urllib3.exceptions import InsecureRequestWarning
import json

INSTANCE_ID = sys.argv[1]
JOB_NAME = sys.argv[2]
JOB_PARAMETERS = sys.argv[3]
API_VERSION = "/api/2.1"

print("----------RUNNING JOB " + JOB_NAME )

# Run Get request with api_command param
# /jobs/list/ with api 2.0 returns all jobs, 2.1 does not
def getRequest(api_command, params={}):
    if api_command == "/jobs/list":
        url = "https://{}{}{}".format(INSTANCE_ID, "/api/2.0", api_command)
    else:
        url = "https://{}{}{}".format(INSTANCE_ID, API_VERSION, api_command)
    response = requests.get(
      url = url,
      json = params,
    )
    return response

# Start a job run
def postRequest(api_command, params):
    url = "https://{}{}{}".format(INSTANCE_ID, API_VERSION, api_command)
    response = requests.post(
      url = url,
      json = params,
    )
    return response

# Get all job names and jobID"s and map to dict
def getJobIds(res):
    tempDict = {}
    for job in res.json()["jobs"]:
      tempDict[job["settings"]["name"]] = job["job_id"]
    return tempDict

jobs = getJobIds(getRequest("/jobs/list"))

if( JOB_NAME in jobs ):
    print("JOB ID: " + str(jobs[JOB_NAME]))

    # Set notebook params for job
    notebook_params = JOB_PARAMETERS.split("\n")
    notebook_object = {}
    for p in notebook_params:
        key = p.split(":")[0]
        paramValue = p.split(":")[1]
        notebook_object[key] = paramValue

    # Run Job
    job_params = { "job_id": jobs[JOB_NAME], "notebook_params": notebook_object }
    startJob = postRequest("/jobs/run-now", job_params)

    # Get run details
    run_id = startJob.json()["run_id"]
    run_params = { "run_id" : run_id }
    job_status = getRequest("/jobs/runs/get", run_params).json()["state"]["life_cycle_state"]
<commit_msg>update run to python params<commit_after>import sys
import requests
from requests.packages.urllib3.exceptions import InsecureRequestWarning
import json

INSTANCE_ID = sys.argv[1]
JOB_NAME = sys.argv[2]
JOB_PARAMETERS = sys.argv[3]
API_VERSION = "/api/2.1"

print("----------RUNNING JOB " + JOB_NAME )

# Run Get request with api_command param
# /jobs/list/ with api 2.0 returns all jobs, 2.1 does not
def getRequest(api_command, params={}):
    if api_command == "/jobs/list":
        url = "https://{}{}{}".format(INSTANCE_ID, "/api/2.0", api_command)
    else:
        url = "https://{}{}{}".format(INSTANCE_ID, API_VERSION, api_command)
    response = requests.get(
      url = url,
      json = params,
    )
    return response

# Start a job run
def postRequest(api_command, params):
    url = "https://{}{}{}".format(INSTANCE_ID, API_VERSION, api_command)
    response = requests.post(
      url = url,
      json = params,
    )
    return response

# Get all job names and jobID"s and map to dict
def getJobIds(res):
    tempDict = {}
    for job in res.json()["jobs"]:
      tempDict[job["settings"]["name"]] = job["job_id"]
    return tempDict

jobs = getJobIds(getRequest("/jobs/list"))

if( JOB_NAME in jobs ):
    print("JOB ID: " + str(jobs[JOB_NAME]))

    # Set python params for job
    python_params = JOB_PARAMETERS.split("\n")

    # Used for notebook params
    # notebook_object = {}
    # for p in notebook_params:
    #     key = p.split(":")[0]
    #     paramValue = p.split(":")[1]
    #     notebook_object[key] = paramValue

    # Run Job
    job_params = { "job_id": jobs[JOB_NAME], "python_params": python_params }
    startJob = postRequest("/jobs/run-now", job_params)

    # Get run details
    run_id = startJob.json()["run_id"]
    run_params = { "run_id" : run_id }
    job_status = getRequest("/jobs/runs/get", run_params).json()["state"]["life_cycle_state"]

{'fraction_non_alphanumeric': 0.1520811099252935, 'fraction_numerical': 0.007470651013874066, 'mean_word_length': 3.279680365296804, 'pattern_counts': {'":': 10, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6592129', 'n_tokens_mistral': 1290, 'n_tokens_neox': 1290, 'n_words': 304}