def generator_handler():
bearer_token = "**"
endpoint_id = "**"
prompt = """
List me all of the US presidents?
"""
# Define the URL
url = f"https://api.runpod.ai/v2/{endpoint_id}/run"
# Define the headers
headers = {
'Content-Type': 'application/json',
'Authorization': f'Bearer {bearer_token}'
}
system_message = """You are a helpful, respectful and honest assistant and chatbot."""
prompt_template = f'''[INST] <<SYS>>
{system_message}
<</SYS>>'''
# Add the initial user message
prompt_template += f'\n{prompt} [/INST]'
print("here")
request = {
'prompt': prompt_template,
'max_new_tokens': 4000,
'temperature': 0.7,
'top_k': 50,
'top_p': 0.7,
'repetition_penalty': 1.2,
'batch_size': 8,
}
response = requests.post(url, json=dict(input=request), headers = {
"Authorization": f"Bearer {bearer_token}"
})
print(response.text)
response_json = json.loads(response.text)
job = response_json['id']
while True:
status_url = f"https://api.runpod.ai/v2/{endpoint_id}/status/{response_json['id']}"
get_status = requests.get(status_url, headers=headers)
print("here",get_status.text)
status_id = json.loads(get_status.text)['id']
status = json.loads(get_status.text)['status']
if status in ["IN_QUEUE", "IN_PROGRESS"]:
time.sleep(20)
else:
if status == "COMPLETED":
print("COMPLETED")
return {
"error": "error 1",
"output": json.loads(get_status.text)
}
else:
return {
"error": "error 2",
"output": json.loads(get_status.text)
}
if __name__ == '__main__':
runpod.serverless.start({
"handler": generator_handler, # Required
})
def generator_handler():
bearer_token = "**"
endpoint_id = "**"
prompt = """
List me all of the US presidents?
"""
# Define the URL
url = f"https://api.runpod.ai/v2/{endpoint_id}/run"
# Define the headers
headers = {
'Content-Type': 'application/json',
'Authorization': f'Bearer {bearer_token}'
}
system_message = """You are a helpful, respectful and honest assistant and chatbot."""
prompt_template = f'''[INST] <<SYS>>
{system_message}
<</SYS>>'''
# Add the initial user message
prompt_template += f'\n{prompt} [/INST]'
print("here")
request = {
'prompt': prompt_template,
'max_new_tokens': 4000,
'temperature': 0.7,
'top_k': 50,
'top_p': 0.7,
'repetition_penalty': 1.2,
'batch_size': 8,
}
response = requests.post(url, json=dict(input=request), headers = {
"Authorization": f"Bearer {bearer_token}"
})
print(response.text)
response_json = json.loads(response.text)
job = response_json['id']
while True:
status_url = f"https://api.runpod.ai/v2/{endpoint_id}/status/{response_json['id']}"
get_status = requests.get(status_url, headers=headers)
print("here",get_status.text)
status_id = json.loads(get_status.text)['id']
status = json.loads(get_status.text)['status']
if status in ["IN_QUEUE", "IN_PROGRESS"]:
time.sleep(20)
else:
if status == "COMPLETED":
print("COMPLETED")
return {
"error": "error 1",
"output": json.loads(get_status.text)
}
else:
return {
"error": "error 2",
"output": json.loads(get_status.text)
}
if __name__ == '__main__':
runpod.serverless.start({
"handler": generator_handler, # Required
})