-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHuggingRefine.py
35 lines (29 loc) · 1023 Bytes
/
HuggingRefine.py
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
32
33
34
35
import json
import urllib2
url = 'https://api-inference.huggingface.co/models/{model_lab}/{model_name}/v1/chat/completions'
api_key = 'hf_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
prompt = u'''Generate a basic JSON containing only the following information on the person mentioned: dateofbirth, placeofbirth, dateofdeath, placeofdeath. Do not provide further information.'''
headers = {
'Authorization': 'Bearer ' + api_key,
'Content-Type': 'application/json',
}
data = {
'messages': [
{
'role': 'user',
'content': prompt + value
}
],
'max_tokens': 2048,
'stream': False,
'temperature': 0,
}
data_string = json.dumps(data)
data_bytes = data_string.encode('utf-8')
req = urllib2.Request(url, data=data_bytes, headers=headers)
response = urllib2.urlopen(req)
response_bytes = response.read()
response_json = json.loads(response_bytes.decode('utf-8'))
content = response_json["choices"][0]["message"]["content"]
content = content.replace("<|end_of_turn|>", "")
return content