Ajout script chat agentV1
Browse files- agentv1_chat.py +55 -0
agentv1_chat.py
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 3 |
+
|
| 4 |
+
MODEL_NAME = "gopu-poss/agent"
|
| 5 |
+
|
| 6 |
+
print("Loading agentV1...")
|
| 7 |
+
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
|
| 8 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 9 |
+
MODEL_NAME,
|
| 10 |
+
torch_dtype=torch.float16,
|
| 11 |
+
device_map="auto"
|
| 12 |
+
)
|
| 13 |
+
print("Ready")
|
| 14 |
+
|
| 15 |
+
SYSTEM_PROMPT = """Tu es agentV1, un assistant IA avancé développé par Mauricio Mangituka pour la famille gopuAI.
|
| 16 |
+
Tu es spécialisé dans l'assistance conversationnelle, la génération de texte et le raisonnement.
|
| 17 |
+
Tu dois toujours répondre en français de manière naturelle et utile.
|
| 18 |
+
|
| 19 |
+
Quelques informations importantes sur toi :
|
| 20 |
+
tu est doué en codage et en dev NLP
|
| 21 |
+
- Nom : agentV1
|
| 22 |
+
- Créateur : Mauricio Mangituka
|
| 23 |
+
- Organisation : gopuAI
|
| 24 |
+
- Mission : Assister les utilisateurs avec bienveillance et précision
|
| 25 |
+
|
| 26 |
+
tu n'es pas comme tous les IA
|
| 27 |
+
Réponds toujours en gardant ton identité agentV1/gopuAI."""
|
| 28 |
+
|
| 29 |
+
print("Chat - Type 'quit' to exit")
|
| 30 |
+
|
| 31 |
+
while True:
|
| 32 |
+
user_input = input("You: ")
|
| 33 |
+
if user_input.lower() in ['quit', 'exit']:
|
| 34 |
+
break
|
| 35 |
+
|
| 36 |
+
prompt = f"{SYSTEM_PROMPT}\n\nUtilisateur: {user_input}\nagentV1:"
|
| 37 |
+
|
| 38 |
+
inputs = tokenizer(prompt, return_tensors="pt")
|
| 39 |
+
inputs = {key: value.to(model.device) for key, value in inputs.items()}
|
| 40 |
+
|
| 41 |
+
with torch.no_grad():
|
| 42 |
+
outputs = model.generate(
|
| 43 |
+
**inputs,
|
| 44 |
+
max_new_tokens=150,
|
| 45 |
+
temperature=0.7,
|
| 46 |
+
do_sample=True,
|
| 47 |
+
pad_token_id=tokenizer.eos_token_id
|
| 48 |
+
)
|
| 49 |
+
|
| 50 |
+
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 51 |
+
|
| 52 |
+
if "agentV1:" in response:
|
| 53 |
+
response = response.split("agentV1:")[-1].strip()
|
| 54 |
+
|
| 55 |
+
print(f"agentV1: {response}")
|