Spaces:
Runtime error
Runtime error
Update zefir7b_api.py
Browse files- zefir7b_api.py +40 -40
zefir7b_api.py
CHANGED
@@ -1,40 +1,40 @@
|
|
1 |
-
import aiohttp
|
2 |
-
import json
|
3 |
-
import traceback
|
4 |
-
|
5 |
-
HUGGINGFACE_TOKEN = '
|
6 |
-
MODEL = "HuggingFaceH4/zephyr-7b-beta"
|
7 |
-
|
8 |
-
async def call_huggingface_api(messages, temperature=0.95, top_k=50, top_p=0.9, num_return_sequences=1000):
|
9 |
-
url = f"https://api-inference.huggingface.co/models/{MODEL}"
|
10 |
-
headers = {"Authorization": f"Bearer {HUGGINGFACE_TOKEN}"}
|
11 |
-
data = {
|
12 |
-
"inputs": "\n".join([f"{msg['role']}: {msg['content']}" for msg in messages]),
|
13 |
-
"options": {
|
14 |
-
"temperature": temperature,
|
15 |
-
"top_k": top_k,
|
16 |
-
"top_p": top_p,
|
17 |
-
"max_length": 1000,
|
18 |
-
"no_repeat_ngram_size": 3,
|
19 |
-
"do_sample": True,
|
20 |
-
"num_return_sequences": num_return_sequences,
|
21 |
-
"no_repeat_ngram_size": 3,
|
22 |
-
"repetition_penalty": 1.2,
|
23 |
-
"length_penalty": 1.0,
|
24 |
-
"early_stopping": True,
|
25 |
-
}
|
26 |
-
}
|
27 |
-
|
28 |
-
try:
|
29 |
-
async with aiohttp.ClientSession() as session:
|
30 |
-
async with session.post(url, headers=headers, json=data) as resp:
|
31 |
-
if resp.status == 200:
|
32 |
-
response = await resp.json()
|
33 |
-
return response
|
34 |
-
else:
|
35 |
-
print(f"Error calling Hugging Face API: {resp.status}, {await resp.text()}")
|
36 |
-
return None
|
37 |
-
except Exception as e:
|
38 |
-
print(f"Error calling Hugging Face API: {e}")
|
39 |
-
print(traceback.format_exc())
|
40 |
-
return None
|
|
|
1 |
+
import aiohttp
|
2 |
+
import json
|
3 |
+
import traceback
|
4 |
+
|
5 |
+
HUGGINGFACE_TOKEN = ' ััััััััััััััััััััััััััััััััััััััััััััั'
|
6 |
+
MODEL = "HuggingFaceH4/zephyr-7b-beta"
|
7 |
+
|
8 |
+
async def call_huggingface_api(messages, temperature=0.95, top_k=50, top_p=0.9, num_return_sequences=1000):
|
9 |
+
url = f"https://api-inference.huggingface.co/models/{MODEL}"
|
10 |
+
headers = {"Authorization": f"Bearer {HUGGINGFACE_TOKEN}"}
|
11 |
+
data = {
|
12 |
+
"inputs": "\n".join([f"{msg['role']}: {msg['content']}" for msg in messages]),
|
13 |
+
"options": {
|
14 |
+
"temperature": temperature,
|
15 |
+
"top_k": top_k,
|
16 |
+
"top_p": top_p,
|
17 |
+
"max_length": 1000,
|
18 |
+
"no_repeat_ngram_size": 3,
|
19 |
+
"do_sample": True,
|
20 |
+
"num_return_sequences": num_return_sequences,
|
21 |
+
"no_repeat_ngram_size": 3,
|
22 |
+
"repetition_penalty": 1.2,
|
23 |
+
"length_penalty": 1.0,
|
24 |
+
"early_stopping": True,
|
25 |
+
}
|
26 |
+
}
|
27 |
+
|
28 |
+
try:
|
29 |
+
async with aiohttp.ClientSession() as session:
|
30 |
+
async with session.post(url, headers=headers, json=data) as resp:
|
31 |
+
if resp.status == 200:
|
32 |
+
response = await resp.json()
|
33 |
+
return response
|
34 |
+
else:
|
35 |
+
print(f"Error calling Hugging Face API: {resp.status}, {await resp.text()}")
|
36 |
+
return None
|
37 |
+
except Exception as e:
|
38 |
+
print(f"Error calling Hugging Face API: {e}")
|
39 |
+
print(traceback.format_exc())
|
40 |
+
return None
|