Mueble commited on
Commit
a6285c2
路
verified 路
1 Parent(s): cf4955c

Update backend.py

Browse files
Files changed (1) hide show
  1. backend.py +5 -5
backend.py CHANGED
@@ -59,10 +59,10 @@ for url in urls:
59
  collection.add(documents=[chunk], ids=[f"{url}_chunk_{i}"], embeddings=[emb])
60
 
61
  # 4. Cargar un modelo local (sin token)
62
- # Puedes cambiar por otro modelo peque帽o si quieres
63
- model_name = "bigscience/bloom-560m" # es gratuito y funciona sin token
64
  tokenizer = AutoTokenizer.from_pretrained(model_name)
65
- model = AutoModelForCausalLM.from_pretrained(model_name) # sin device_map
66
  generator = pipeline("text-generation", model=model, tokenizer=tokenizer)
67
 
68
  # 5. Funci贸n para responder
@@ -72,7 +72,7 @@ def responder_pregunta(pregunta: str, k=3, max_chars=1500) -> str:
72
  contextos = resultados["documents"][0]
73
  contexto = "\n\n".join(contextos)[:max_chars]
74
 
75
- prompt = f"""Responde en espa帽ol a la siguiente pregunta sobre historia peruana.
76
  Contexto hist贸rico:
77
  {contexto}
78
  Pregunta: {pregunta}
@@ -81,7 +81,7 @@ Respuesta:"""
81
  output = generator(
82
  prompt,
83
  max_new_tokens=256,
84
- temperature=0.7,
85
  top_p=0.9,
86
  do_sample=True
87
  )
 
59
  collection.add(documents=[chunk], ids=[f"{url}_chunk_{i}"], embeddings=[emb])
60
 
61
  # 4. Cargar un modelo local (sin token)
62
+
63
+ model_name = "TinyLlama/TinyLlama-1.1B-Chat-v1.0"
64
  tokenizer = AutoTokenizer.from_pretrained(model_name)
65
+ model = AutoModelForCausalLM.from_pretrained(model_name)
66
  generator = pipeline("text-generation", model=model, tokenizer=tokenizer)
67
 
68
  # 5. Funci贸n para responder
 
72
  contextos = resultados["documents"][0]
73
  contexto = "\n\n".join(contextos)[:max_chars]
74
 
75
+ prompt = f"""Responde en espa帽ol a la siguiente pregunta sobre la Batalla de Ayacucho.
76
  Contexto hist贸rico:
77
  {contexto}
78
  Pregunta: {pregunta}
 
81
  output = generator(
82
  prompt,
83
  max_new_tokens=256,
84
+ temperature=0.3,
85
  top_p=0.9,
86
  do_sample=True
87
  )