Spaces:
Sleeping
Sleeping
File size: 685 Bytes
22cf642 564bd7c 22cf642 5f6d4f4 22cf642 5525b46 22cf642 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
from transformers import AutoTokenizer, AutoModelForCausalLM
model_name = "NousResearch/Hermes-2-Pro-Llama-3-8B"
model = AutoModelForCausalLM.from_pretrained(model_name)
tokenizer = AutoTokenizer.from_pretrained(model_name)
# Example messages input
# messages = [
# {"role": "system", "content": "You are Hermes 2."},
# {"role": "user", "content": "Hello, who are you?"}
#]
def generate(messages):
gen_input = tokenizer.apply_chat_template(messages, return_tensors="pt")
output_ids = model.generate(**gen_input, num_beams=3, no_repeat_ngram_size=2, max_new_tokens=100, eos_token_id=tokenizer.eos_token_id)
return tokenizer.decode(output_ids[0], skip_special_tokens=True) |