Update main.py
Browse files
main.py
CHANGED
@@ -6,44 +6,7 @@ import prompt_style
|
|
6 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
7 |
import torch
|
8 |
|
9 |
-
#
|
10 |
-
# import transformers
|
11 |
-
# import torch
|
12 |
-
|
13 |
-
# pipeline = transformers.pipeline(
|
14 |
-
# "text-generation",
|
15 |
-
# model=model_id,
|
16 |
-
# model_kwargs={"torch_dtype": torch.bfloat16},
|
17 |
-
# device_map="auto",
|
18 |
-
# )
|
19 |
-
|
20 |
-
def generate_1(item: Item):
|
21 |
-
messages = [
|
22 |
-
{"role": "system", "content": "You are a pirate chatbot who always responds in pirate speak!"},
|
23 |
-
{"role": "user", "content": "Who are you?"},
|
24 |
-
]
|
25 |
-
|
26 |
-
terminators = [
|
27 |
-
pipeline.tokenizer.eos_token_id,
|
28 |
-
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>")
|
29 |
-
]
|
30 |
-
|
31 |
-
outputs = pipeline(
|
32 |
-
messages,
|
33 |
-
max_new_tokens=item.max_new_tokens,
|
34 |
-
eos_token_id=terminators,
|
35 |
-
do_sample=True,
|
36 |
-
temperature=item.temperature,
|
37 |
-
top_p=item.top_p,
|
38 |
-
)
|
39 |
-
return outputs[0]["generated_text"][-1]
|
40 |
-
|
41 |
-
# **************************************************
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
client = InferenceClient(model_id)
|
47 |
|
48 |
class Item(BaseModel):
|
49 |
prompt: str
|
|
|
6 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
7 |
import torch
|
8 |
|
9 |
+
# client = InferenceClient(model_id)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
class Item(BaseModel):
|
12 |
prompt: str
|