forked from daveshap/TutorChatbot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
finetune.py
52 lines (34 loc) · 1.71 KB
/
finetune.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import requests
import openai
from pprint import pprint
with open('openaiapikey.txt', 'r') as infile:
open_ai_api_key = infile.read()
openai.api_key = open_ai_api_key
def file_upload(filename, purpose='fine-tune'):
resp = openai.File.create(purpose=purpose, file=open(filename))
pprint(resp)
return resp
def file_list():
resp = openai.File.list()
pprint(resp)
def finetune_model(fileid, suffix, model='davinci'):
header = {'Content-Type': 'application/json', 'Authorization': 'Bearer %s' % open_ai_api_key}
payload = {'training_file': fileid, 'model': model, 'suffix': suffix}
resp = requests.request(method='POST', url='https://api.openai.com/v1/fine-tunes', json=payload, headers=header, timeout=45)
pprint(resp.json())
def finetune_list():
header = {'Content-Type': 'application/json', 'Authorization': 'Bearer %s' % open_ai_api_key}
resp = requests.request(method='GET', url='https://api.openai.com/v1/fine-tunes', headers=header, timeout=45)
pprint(resp.json())
def finetune_events(ftid):
header = {'Content-Type': 'application/json', 'Authorization': 'Bearer %s' % open_ai_api_key}
resp = requests.request(method='GET', url='https://api.openai.com/v1/fine-tunes/%s/events' % ftid, headers=header, timeout=45)
pprint(resp.json())
def finetune_get(ftid):
header = {'Content-Type': 'application/json', 'Authorization': 'Bearer %s' % open_ai_api_key}
resp = requests.request(method='GET', url='https://api.openai.com/v1/fine-tunes/%s' % ftid, headers=header, timeout=45)
pprint(resp.json())
#resp = file_upload('tim.jsonl')
#finetune_model(resp['id'], 'Tutor', 'davinci')
finetune_list()
#openai.FineTune.cancel("ft-2ZxHjUVe5DpqK2EsYyA0YtKz")