forked from NVIDIA/Megatron-LM
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ef59b68
commit 3c76018
Showing
3 changed files
with
21 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,23 @@ | ||
# Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved. | ||
import json | ||
import sys | ||
import urllib2 | ||
class PutRequest(urllib2.Request): | ||
'''class to handling putting with urllib2''' | ||
import json | ||
import requests | ||
|
||
def get_method(self, *args, **kwargs): | ||
return 'PUT' | ||
|
||
if __name__ == "__main__": | ||
url = sys.argv[1] | ||
url = 'http://' + url + '/api' | ||
headers = {'Content-Type': 'application/json'} | ||
|
||
while True: | ||
sentence = raw_input("Enter prompt: ") | ||
tokens_to_generate = int(input("Enter number of tokens to generate: ")) | ||
data = json.dumps({"prompts": [sentence], "tokens_to_generate":tokens_to_generate}) | ||
req = PutRequest(url, data, {'Content-Type': 'application/json'}) | ||
response = urllib2.urlopen(req) | ||
resp_sentences = json.load(response) | ||
print("Megatron Response: ") | ||
print(resp_sentences["text"][0]) | ||
sentence = input("Enter prompt: ") | ||
tokens_to_generate = int(eval(input("Enter number of tokens to generate: "))) | ||
|
||
data = {"prompts": [sentence], "tokens_to_generate": tokens_to_generate} | ||
response = requests.put(url, data=json.dumps(data), headers=headers) | ||
|
||
if response.status_code != 200: | ||
print(f"Error {response.status_code}: {response.json()['message']}") | ||
else: | ||
print("Megatron Response: ") | ||
print(response.json()['text'][0]) |