Views
No views yet
1from transformers import AutoTokenizer, AutoModelForCausalLM
2
3model_id = "fungamer2/Ami-360M"
4tokenizer = AutoTokenizer.from_pretrained(model_id)
5model = AutoModelForCausalLM.from_pretrained(model_id)
6
7def generate_response(prompt):
8 if isinstance(prompt, str):
9 prompt = [
10 {"role": "user", "content": prompt},
11 ]
12 inputs = tokenizer.apply_chat_template(
13 prompt,
14 add_generation_prompt=True,
15 tokenize=True,
16 return_dict=True,
17 return_tensors="pt",
18 ).to(model.device)
19
20 outputs = model.generate(**inputs, max_new_tokens=1024, do_sample=True, temperature=0.3)
21 return tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:], skip_special_tokens=True)
22
23prompt = "What is the meaning of life?"
24print(generate_response(prompt))
25'''
26Oh, the *meaning of life* - that's such a big question! 😊 It's like asking, *"What's the most important thing in your life?"* What if I told you that even the simplest things can have the most profound impact?
27
28Here's a fun way to think about it:
29- The universe is *full* of mysteries. What if the "why" of life is just one of those mysteries waiting to be solved?
30- Happiness is a choice. You can choose to focus on the good or the bad - and that's okay.
31- Life is a journey. No one's "done" life yet - we're all just starting.
32
33But here's the thing: the *meaning* of life isn't something you *find* - it's something *you* *create*. Think of it like a puzzle: the pieces don't just fit - they *shape* your life.
34
35What's one thing that makes you feel *alive*? Maybe it's a hobby, a memory, or even just the quiet moments with loved ones. That's the kind of thing that can make life feel meaningful.
36
37What's something that makes you feel *alive* right now?
38'''
39
40prompt = "I'm having trouble sleeping at night, and I think it's because I'm stressed about work."
41print(generate_response(prompt))
42'''
43Oh no, I *feel* you - stress can really mess with sleep, and it's so important to take care of yourself. 💙 If you're feeling overwhelmed, I'd love to hear more about what's on your mind - what's been on your mind lately? (Or if you'd rather, we can just chat about how it's making you feel.)
44'''