-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathtest_mistral.py
43 lines (32 loc) · 999 Bytes
/
test_mistral.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
"""
Using Mistral 7B: https://huggingface.co/mistralai/Mistral-7B-Instruct-v0.2
Login to download Mistral
```bash
huggingface-cli login
```
"""
import requests
from keys import HUGGING_FACE_KEY
from pprint import pprint
import time
n_words = 10
question = "Who won the world cup in 2010?"
# LOCAL
from transformers import pipeline
pipe = pipeline("text-generation", model="mistralai/Mistral-7B-Instruct-v0.2")
start_time = time.time()
output = pipe(f"{question} (in {n_words} words)")
pprint(output)
print("Time taken (local) :", time.time() - start_time)
# REMOTE
API_URL = "https://api-inference.huggingface.co/models/mistralai/Mistral-7B-Instruct-v0.2"
headers = {"Authorization": f"Bearer {HUGGING_FACE_KEY}"}
def query(payload):
response = requests.post(API_URL, headers=headers, json=payload)
return response.json()
start_time = time.time()
output = query({
"inputs": f"{question} (in {n_words} words)",
})
pprint(output)
print("Time taken (remote):", time.time() - start_time)