Views
No views yet
1from transformers import AutoModelForCausalLM, AutoTokenizer
2import torch
3
4model_name = "NidhalFerjani/Llama-3.2-3b-Coffria-Dialogue"
5
6tokenizer = AutoTokenizer.from_pretrained(model_name)
7model = AutoModelForCausalLM.from_pretrained(
8 model_name,
9 torch_dtype=torch.bfloat16,
10 device_map="auto"
11)
12
13# Exemple pour un assistant de recherche documentaire
14prompt = "Bonjour, je cherche des documents sur l'IA."
15inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
16outputs = model.generate(**inputs, max_length=200)
17response = tokenizer.decode(outputs[0], skip_special_tokens=True)
18print(response)
19
20# Les balises d'intention peuvent être extraites avec une regex
21import re
22intention_match = re.search(r"<\|INTENTION_START\|>(.*?)<\|INTENTION_END\|>", response)
23intention = intention_match.group(1) if intention_match else "Non spécifiée"
24print(f"Intention: ")