Added getting number of tokens
Browse files- gigiachat_requests.py +21 -0
gigiachat_requests.py
CHANGED
@@ -30,6 +30,27 @@ def get_access_token():
|
|
30 |
print('Got access token')
|
31 |
return access_token
|
32 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
def get_completion_from_gigachat(prompt, max_tokens, access_token):
|
34 |
url_completion = os.getenv('GIGA_COMPLETION_URL')
|
35 |
|
|
|
30 |
print('Got access token')
|
31 |
return access_token
|
32 |
|
33 |
+
def get_number_of_tokens(prompt, access_token):
|
34 |
+
url_completion = os.getenv('GIGA_TOKENS_URL')
|
35 |
+
|
36 |
+
data_copm = json.dumps({
|
37 |
+
"model": os.getenv('GIGA_MODEL'),
|
38 |
+
"input": [
|
39 |
+
prompt
|
40 |
+
],
|
41 |
+
})
|
42 |
+
|
43 |
+
headers_comp = {
|
44 |
+
'Content-Type': 'application/json',
|
45 |
+
'Accept': 'application/json',
|
46 |
+
'Authorization': 'Bearer ' + access_token
|
47 |
+
}
|
48 |
+
|
49 |
+
response = requests.post(url_completion, headers=headers_comp, data=data_copm, verify=False)
|
50 |
+
response_data = response.json()
|
51 |
+
|
52 |
+
return response_data[0]['tokens']
|
53 |
+
|
54 |
def get_completion_from_gigachat(prompt, max_tokens, access_token):
|
55 |
url_completion = os.getenv('GIGA_COMPLETION_URL')
|
56 |
|