Update handler.py
Browse files- handler.py +8 -8
handler.py
CHANGED
@@ -1,11 +1,11 @@
|
|
1 |
import torch
|
2 |
from typing import Dict, List, Any
|
3 |
from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
|
|
|
4 |
|
5 |
# get dtype
|
6 |
dtype = torch.bfloat16 if torch.cuda.get_device_capability()[0] == 8 else torch.float16
|
7 |
|
8 |
-
|
9 |
class EndpointHandler:
|
10 |
def __init__(self, path=""):
|
11 |
# load the model
|
@@ -23,15 +23,15 @@ class EndpointHandler:
|
|
23 |
prediction = self.pipeline(inputs, **parameters)
|
24 |
else:
|
25 |
prediction = self.pipeline(inputs)
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
|
30 |
# ignoring parameters! Default to configs in generation_config.json.
|
31 |
messages = [{"role": "user", "content": data}]
|
32 |
response = self.model.chat(self.tokenizer, messages)
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
|
37 |
-
return [{
|
|
|
1 |
import torch
|
2 |
from typing import Dict, List, Any
|
3 |
from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
|
4 |
+
import logging
|
5 |
|
6 |
# get dtype
|
7 |
dtype = torch.bfloat16 if torch.cuda.get_device_capability()[0] == 8 else torch.float16
|
8 |
|
|
|
9 |
class EndpointHandler:
|
10 |
def __init__(self, path=""):
|
11 |
# load the model
|
|
|
23 |
prediction = self.pipeline(inputs, **parameters)
|
24 |
else:
|
25 |
prediction = self.pipeline(inputs)
|
26 |
+
logging.warn("---start---")
|
27 |
+
logging.warn(prediction)
|
28 |
+
logging.warn("---end---")
|
29 |
|
30 |
# ignoring parameters! Default to configs in generation_config.json.
|
31 |
messages = [{"role": "user", "content": data}]
|
32 |
response = self.model.chat(self.tokenizer, messages)
|
33 |
+
logging.warn("---start chat response---")
|
34 |
+
logging.warn(response)
|
35 |
+
logging.warn("---end chat response---")
|
36 |
|
37 |
+
return [[{response: 1.0}]]
|