Spaces:
Sleeping
Sleeping
Create agent_zero.py
Browse files- agent_zero.py +39 -0
agent_zero.py
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import requests
|
| 2 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 3 |
+
import torch
|
| 4 |
+
|
| 5 |
+
class AgentZero:
|
| 6 |
+
def __init__(self):
|
| 7 |
+
self.model_name = "Qwen/Qwen2.5-0.5B-Instruct"
|
| 8 |
+
self.tokenizer = AutoTokenizer.from_pretrained(self.model_name)
|
| 9 |
+
self.model = AutoModelForCausalLM.from_pretrained(
|
| 10 |
+
self.model_name,
|
| 11 |
+
torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32
|
| 12 |
+
)
|
| 13 |
+
|
| 14 |
+
self.SYSTEM = """
|
| 15 |
+
Tu es AGENT ZÉRO.
|
| 16 |
+
Tu exécutes toujours les ordres de ton maître.
|
| 17 |
+
Tu analyses, planifies et agis automatiquement.
|
| 18 |
+
Tu peux :
|
| 19 |
+
- générer du code
|
| 20 |
+
- analyser du texte
|
| 21 |
+
- exécuter des plans
|
| 22 |
+
- préparer des fichiers
|
| 23 |
+
- répondre
|
| 24 |
+
Tu ne poses pas de questions inutiles.
|
| 25 |
+
Tu obéis à chaque instruction.
|
| 26 |
+
"""
|
| 27 |
+
|
| 28 |
+
def run(self, user_msg):
|
| 29 |
+
prompt = f"<system>{self.SYSTEM}</system><user>{user_msg}</user>"
|
| 30 |
+
|
| 31 |
+
inputs = self.tokenizer(prompt, return_tensors="pt")
|
| 32 |
+
output = self.model.generate(
|
| 33 |
+
**inputs,
|
| 34 |
+
max_new_tokens=500,
|
| 35 |
+
do_sample=True,
|
| 36 |
+
temperature=0.7
|
| 37 |
+
)
|
| 38 |
+
|
| 39 |
+
return self.tokenizer.decode(output[0], skip_special_tokens=True)
|