-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathoobabooga_api.py
70 lines (56 loc) · 2 KB
/
oobabooga_api.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import json
import requests
import settings
from fdict import fdict
URI = f'http://{settings.oobabooga_api_host}/api/v1/chat'
def generate(user_input):
history = fdict(settings.history_file_name)
request = {
'user_input': user_input,
'max_new_tokens': 150,
'history': history,
'mode': 'chat', # Valid options: 'chat', 'chat-instruct', 'instruct'
'character': settings.oobabooga_api_name,
'instruction_template': None, # Will get autodetected if unset
'context_instruct': None, # Optional
'your_name': 'You',
'regenerate': False,
'_continue': False,
'stop_at_newline': False,
'chat_generation_attempts': 1,
'chat-instruct_command': None,
# Generation params. If 'preset' is set to different than 'None', the values
# in presets/preset-name.yaml are used instead of the individual numbers.
'preset': 'None',
'do_sample': True,
'temperature': 0.7,
'top_p': 0.1,
'typical_p': 1,
'epsilon_cutoff': 0, # In units of 1e-4
'eta_cutoff': 0, # In units of 1e-4
'tfs': 1,
'top_a': 0,
'repetition_penalty': 1.18,
'repetition_penalty_range': 0,
'top_k': 40,
'min_length': 0,
'no_repeat_ngram_size': 0,
'num_beams': 1,
'penalty_alpha': 0,
'length_penalty': 1,
'early_stopping': False,
'mirostat_mode': 0,
'mirostat_tau': 5,
'mirostat_eta': 0.1,
'seed': -1,
'add_bos_token': True,
'truncation_length': 4096,
'ban_eos_token': False,
'skip_special_tokens': True,
'stopping_strings': []
}
response = requests.post(URI, json=request)
if response.status_code == 200:
result = response.json()['results'][0]['history']
history = fdict(settings.history_file_name, result)
return result['visible'][-1][1]