Skip to content

Instantly share code, notes, and snippets.

@hpssjellis
Forked from svpino/llama2-monsterapis.py
Created July 31, 2023 18:03
Show Gist options
  • Select an option

  • Save hpssjellis/5dfbb2fea3c257f3d5d8998164f52ff4 to your computer and use it in GitHub Desktop.

Select an option

Save hpssjellis/5dfbb2fea3c257f3d5d8998164f52ff4 to your computer and use it in GitHub Desktop.

Revisions

  1. @svpino svpino revised this gist Jul 31, 2023. 1 changed file with 4 additions and 2 deletions.
    6 changes: 4 additions & 2 deletions llama2-monsterapis.py
    Original file line number Diff line number Diff line change
    @@ -27,12 +27,14 @@
    }

    response = requests.post(url, headers=headers, data=json.dumps(data))
    process_id = response.json()["process_id"]

    status = None

    while True:
    response = requests.post(
    fetch_url,
    headers=headers,
    fetch_url,
    headers=headers,
    data=json.dumps({
    "process_id": process_id,
    })).json()
  2. @svpino svpino revised this gist Jul 26, 2023. 1 changed file with 30 additions and 1 deletion.
    31 changes: 30 additions & 1 deletion llama2-monsterapis.py
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,34 @@
    status = None
    import requests
    import json
    from time import sleep

    API_KEY = "INSERT YOUR API KEY HERE"
    AUTHORIZATION = "INSERT YOUR AUTHORIZATION TOKEN HERE"

    url = "https://api.monsterapi.ai/apis/add-task"
    fetch_url = "https://api.monsterapi.ai/apis/task-status"

    headers = {
    "x-api-key": API_KEY,
    "Authorization": f"Bearer {AUTHORIZATION}",
    "Content-Type": "application/json",
    }

    data = {
    "model": "llama2-7b-chat",
    "data": {
    "prompt": "How many states in the United States of America?",
    "top_k": 10,
    "top_p": 0.9,
    "temp": 0.1,
    "max_length": 1000,
    "beam_size": 1
    }
    }

    response = requests.post(url, headers=headers, data=json.dumps(data))

    status = None
    while True:
    response = requests.post(
    fetch_url,
  3. @svpino svpino created this gist Jul 26, 2023.
    20 changes: 20 additions & 0 deletions llama2-monsterapis.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    status = None

    while True:
    response = requests.post(
    fetch_url,
    headers=headers,
    data=json.dumps({
    "process_id": process_id,
    })).json()

    status = response["response_data"]["status"]
    if status not in ("COMPLETED", "FAILED"):
    sleep(2)
    else:
    break

    if status == "COMPLETED":
    print(response["response_data"]["result"]["text"])
    else:
    print("Error:", response["response_data"]["result"]["errorMessage"])